|
| 1 | +using System; |
| 2 | +using Elasticsearch.Net; |
| 3 | +using Nest; |
| 4 | +using Tests.Framework; |
| 5 | +using Tests.Framework.Integration; |
| 6 | +using Tests.Framework.ManagedElasticsearch.Clusters; |
| 7 | +using static Nest.Infer; |
| 8 | + |
| 9 | +namespace Tests.Document.Multiple.ReindexOnServer |
| 10 | +{ |
| 11 | + public class ReindexOnServerSourceApiTests : ApiIntegrationTestBase<IntrusiveOperationCluster, IReindexOnServerResponse, IReindexOnServerRequest, ReindexOnServerDescriptor, ReindexOnServerRequest> |
| 12 | + { |
| 13 | + public class Test |
| 14 | + { |
| 15 | + public long Id { get; set; } |
| 16 | + public string Flag { get; set; } |
| 17 | + } |
| 18 | + |
| 19 | + public ReindexOnServerSourceApiTests(IntrusiveOperationCluster cluster, EndpointUsage usage) : base(cluster, usage) { } |
| 20 | + |
| 21 | + protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values) |
| 22 | + { |
| 23 | + foreach (var index in values.Values) |
| 24 | + { |
| 25 | + this.Client.Bulk(b => b |
| 26 | + .Index(index) |
| 27 | + .IndexMany(new [] |
| 28 | + { |
| 29 | + new Test { Id = 1, Flag = "bar" }, |
| 30 | + new Test { Id = 2, Flag = "bar" } |
| 31 | + }) |
| 32 | + .Refresh(Refresh.WaitFor) |
| 33 | + ); |
| 34 | + } |
| 35 | + } |
| 36 | + protected override LazyResponses ClientUsage() => Calls( |
| 37 | + fluent: (client, f) => client.ReindexOnServer(f), |
| 38 | + fluentAsync: (client, f) => client.ReindexOnServerAsync(f), |
| 39 | + request: (client, r) => client.ReindexOnServer(r), |
| 40 | + requestAsync: (client, r) => client.ReindexOnServerAsync(r) |
| 41 | + ); |
| 42 | + |
| 43 | + protected override bool ExpectIsValid => true; |
| 44 | + protected override int ExpectStatusCode => 200; |
| 45 | + protected override HttpMethod HttpMethod => HttpMethod.POST; |
| 46 | + |
| 47 | + protected override string UrlPath => $"/_reindex?refresh=true"; |
| 48 | + |
| 49 | + protected override bool SupportsDeserialization => false; |
| 50 | + |
| 51 | + protected override Func<ReindexOnServerDescriptor, IReindexOnServerRequest> Fluent => d => d |
| 52 | + .Source(s => s |
| 53 | + .Index(CallIsolatedValue) |
| 54 | + .Type("test") |
| 55 | + .Source<Test>(f => f |
| 56 | + .Field(ff => ff.Id) |
| 57 | + .Field(ff => ff.Flag) |
| 58 | + ) |
| 59 | + ) |
| 60 | + .Destination(s => s |
| 61 | + .Index(CallIsolatedValue + "-clone") |
| 62 | + .Type("test") |
| 63 | + ) |
| 64 | + .Conflicts(Conflicts.Proceed) |
| 65 | + .Refresh(); |
| 66 | + |
| 67 | + protected override ReindexOnServerRequest Initializer => new ReindexOnServerRequest |
| 68 | + { |
| 69 | + Source = new ReindexSource |
| 70 | + { |
| 71 | + Index = CallIsolatedValue, |
| 72 | + Type = "test", |
| 73 | + Source = Infer.Fields<Test>( |
| 74 | + ff => ff.Id, |
| 75 | + ff => ff.Flag |
| 76 | + ) |
| 77 | + }, |
| 78 | + Destination = new ReindexDestination |
| 79 | + { |
| 80 | + Index = CallIsolatedValue + "-clone", |
| 81 | + Type = Type<Test>(), |
| 82 | + }, |
| 83 | + Conflicts = Conflicts.Proceed, |
| 84 | + Refresh = true, |
| 85 | + }; |
| 86 | + |
| 87 | + protected override void ExpectResponse(IReindexOnServerResponse response) |
| 88 | + { |
| 89 | + response.ShouldBeValid(); |
| 90 | + } |
| 91 | + |
| 92 | + protected override object ExpectJson => |
| 93 | + new |
| 94 | + { |
| 95 | + dest = new |
| 96 | + { |
| 97 | + index = $"{CallIsolatedValue}-clone", |
| 98 | + type = "test", |
| 99 | + }, |
| 100 | + source = new |
| 101 | + { |
| 102 | + index = CallIsolatedValue, |
| 103 | + _source = new [] { "id", "flag" }, |
| 104 | + type = new[] { "test" }, |
| 105 | + }, |
| 106 | + conflicts = "proceed" |
| 107 | + }; |
| 108 | + } |
| 109 | +} |
0 commit comments