Skip to content

Commit 7663b37

Browse files
committed
reindex rethrottle integration tests
1 parent 62770f0 commit 7663b37

File tree

6 files changed

+102
-15
lines changed

6 files changed

+102
-15
lines changed

src/Nest/Document/Multiple/ReindexRethrottle/ReindexNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class ReindexStatus
8787
public long ThrottledInMilliseconds { get; internal set; }
8888

8989
[JsonProperty("requests_per_second")]
90-
public long RequestsPerSecond { get; internal set; }
90+
public Union<string,long> RequestsPerSecond { get; internal set; }
9191

9292
[JsonProperty("throttled_until_millis")]
9393
public long ThrottledUntilInMilliseconds { get; internal set; }

src/Nest/Document/Multiple/ReindexRethrottle/ReindexRethrottleResponse.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ namespace Nest
77
public interface IReindexRethrottleResponse : IResponse
88
{
99
[JsonProperty("nodes")]
10-
IEnumerable<ReindexNode> Nodes { get; set; }
10+
[JsonConverter(typeof(VerbatimDictionaryKeysJsonConverter))]
11+
Dictionary<string, ReindexNode> Nodes { get; set; }
1112
}
1213

1314
public class ReindexRethrottleResponse : ResponseBase, IReindexRethrottleResponse
1415
{
15-
public IEnumerable<ReindexNode> Nodes { get; set; }
16+
public Dictionary<string, ReindexNode> Nodes { get; set; }
1617
}
1718
}

src/Nest/Nest.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,9 @@
533533
<Compile Include="Document\Multiple\ReindexOnServer\ReindexRouting.cs" />
534534
<Compile Include="Document\Multiple\ReindexOnServer\ReindexRoutingJsonConverter.cs" />
535535
<Compile Include="Document\Multiple\ReindexOnServer\ReindexSource.cs" />
536+
<Compile Include="Document\Multiple\ReindexRethrottle\ElasticClient-ReindexRethrottle.cs" />
537+
<Compile Include="Document\Multiple\ReindexRethrottle\ReindexNode.cs" />
538+
<Compile Include="Document\Multiple\ReindexRethrottle\ReindexRethrottleResponse.cs" />
536539
<Compile Include="Document\Multiple\UpdateByQuery\UpdateByQueryRequest.cs" />
537540
<Compile Include="Document\Multiple\UpdateByQuery\UpdateByQueryResponse.cs" />
538541
<Compile Include="Document\Multiple\UpdateByQuery\ElasticClient-UpdateByQuery.cs" />

src/Tests/Document/Multiple/ReindexRethrottle/ReindexRethrottleApiTests.cs

Lines changed: 92 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using FluentAssertions;
66
using Nest;
77
using Tests.Document.Multiple.Reindex;
8+
using Tests.Document.Multiple.ReindexOnServer;
89
using Tests.Framework;
910
using Tests.Framework.Integration;
1011
using Tests.Framework.MockData;
@@ -14,20 +15,68 @@
1415
namespace Tests.Document.Multiple.ReindexRethrottle
1516
{
1617
[Collection(IntegrationContext.Reindex)]
17-
public class ReindexRethrottleApiTests
18-
: ApiIntegrationTestBase<IReindexRethrottleResponse, IReindexRethrottleRequest, ReindexRethrottleDescriptor, ReindexRethrottleRequest>
18+
public class ReindexRethrottleReindexApiTests : ReindexRethrottleApiTests
1919
{
20-
private readonly TaskId _taskId = "rhtoNesNR4aXVIY2bRR4GQ:13056";
20+
public ReindexRethrottleReindexApiTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage)
21+
{
22+
}
2123

22-
public ReindexRethrottleApiTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
24+
protected override void OnBeforeCall(IElasticClient client)
25+
{
26+
var reindex = client.ReindexOnServer(r => r
27+
.Source(s => s
28+
.Index(Index<Project>())
29+
)
30+
.Destination(s => s
31+
.Index(CallIsolatedValue)
32+
.OpType(OpType.Create)
33+
)
34+
.Refresh()
35+
.RequestsPerSecond(1)
36+
.WaitForCompletion(false)
37+
);
2338

24-
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
39+
reindex.IsValid.Should().BeTrue();
40+
this.ExtendedValue(TaskIdKey, reindex.Task);
41+
}
42+
}
43+
44+
[Collection(IntegrationContext.Reindex)]
45+
public class ReindexRethrottleUpdateByQueryTests : ReindexRethrottleApiTests
46+
{
47+
public ReindexRethrottleUpdateByQueryTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage)
2548
{
2649
}
2750

2851
protected override void OnBeforeCall(IElasticClient client)
2952
{
30-
base.OnBeforeCall(client);
53+
var reindex = client.UpdateByQuery<Project>(Nest.Indices.Index<Project>(), Types.Type<Project>(), u => u
54+
.Conflicts(Conflicts.Proceed)
55+
.Query(q => q.MatchAll())
56+
.Script(s => s.Inline("ctx._source.numberOfCommits+10"))
57+
.Refresh()
58+
.RequestsPerSecond(1)
59+
.WaitForCompletion(false)
60+
);
61+
62+
reindex.IsValid.Should().BeTrue();
63+
this.ExtendedValue(TaskIdKey, reindex.Task);
64+
}
65+
}
66+
67+
public abstract class ReindexRethrottleApiTests
68+
: ApiIntegrationTestBase<IReindexRethrottleResponse, IReindexRethrottleRequest, ReindexRethrottleDescriptor, ReindexRethrottleRequest>
69+
{
70+
protected TaskId TaskId => this.RanIntegrationSetup ? this.ExtendedValue<TaskId>(TaskIdKey) : "foo:1";
71+
72+
protected const string TaskIdKey = "taskId";
73+
74+
protected ReindexRethrottleApiTests(ReindexCluster cluster, EndpointUsage usage) : base(cluster, usage) { }
75+
76+
protected override void IntegrationSetup(IElasticClient client, CallUniqueValues values)
77+
{
78+
client.IndexMany(Project.Projects);
79+
client.Refresh(Index<Project>());
3180
}
3281

3382
protected override LazyResponses ClientUsage() => Calls(
@@ -36,24 +85,56 @@ protected override LazyResponses ClientUsage() => Calls(
3685
request: (client, r) => client.ReindexRethrottle(r),
3786
requestAsync: (client, r) => client.ReindexRethrottleAsync(r)
3887
);
39-
protected override void OnAfterCall(IElasticClient client) => client.Refresh(CallIsolatedValue);
4088

4189
protected override bool ExpectIsValid => true;
4290
protected override int ExpectStatusCode => 200;
4391
protected override HttpMethod HttpMethod => HttpMethod.POST;
4492

45-
46-
protected override string UrlPath => $"/_reindex/rhtoNesNR4aXVIY2bRR4GQ%3A13056/_rethrottle";
93+
protected override string UrlPath => $"/_reindex/{TaskId.NodeId}%3A{TaskId.TaskNumber}/_rethrottle?requests_per_second=0";
4794

4895
protected override bool SupportsDeserialization => false;
4996

5097
protected override Func<ReindexRethrottleDescriptor, IReindexRethrottleRequest> Fluent => d => d
51-
.TaskId(_taskId);
98+
.TaskId(TaskId)
99+
.RequestsPerSecond(0);
52100

53-
protected override ReindexRethrottleRequest Initializer => new ReindexRethrottleRequest(_taskId);
101+
protected override ReindexRethrottleRequest Initializer => new ReindexRethrottleRequest(TaskId)
102+
{
103+
RequestsPerSecond = 0,
104+
};
54105

55106
protected override void ExpectResponse(IReindexRethrottleResponse response)
56107
{
108+
response.IsValid.Should().BeTrue();
109+
110+
response.Nodes.Should().NotBeEmpty().And.HaveCount(1);
111+
var node = response.Nodes.First().Value;
112+
113+
node.Name.Should().NotBeNullOrEmpty();
114+
node.TransportAddress.Should().NotBeNullOrEmpty();
115+
node.Host.Should().NotBeNullOrEmpty();
116+
node.Ip.Should().NotBeNullOrEmpty();
117+
node.Roles.Should().NotBeEmpty();
118+
node.Attributes.Should().NotBeEmpty();
119+
120+
node.Tasks.Should().NotBeEmpty().And.HaveCount(1);
121+
122+
node.Tasks.First().Key.Should().Be(TaskId);
123+
124+
var task = node.Tasks.First().Value;
125+
126+
task.Node.Should().NotBeNullOrEmpty().And.Be(TaskId.NodeId);
127+
task.Id.Should().Be(TaskId.TaskNumber);
128+
task.Type.Should().NotBeNullOrEmpty();
129+
task.Action.Should().NotBeNullOrEmpty();
130+
131+
task.Status.RequestsPerSecond.Match(
132+
s => s.Should().Be("unlimited"),
133+
l => l.Should().Be(0)
134+
);
135+
136+
task.StartTimeInMilliseconds.Should().BeGreaterThan(0);
137+
task.RunningTimeInNanoseconds.Should().BeGreaterThan(0);
57138
}
58139

59140
protected override object ExpectJson => null;

src/Tests/Framework/ApiTestBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public abstract class ApiTestBase<TResponse, TInterface, TDescriptor, TInitializ
2828

2929
protected string CallIsolatedValue => _uniqueValues.Value;
3030
protected T ExtendedValue<T>(string key) where T : class => this._uniqueValues.ExtendedValue<T>(key);
31-
31+
protected void ExtendedValue<T>(string key, T value) where T : class => this._uniqueValues.ExtendedValue(key, value);
3232
protected virtual void IntegrationSetup(IElasticClient client, CallUniqueValues values) { }
3333
protected virtual void OnBeforeCall(IElasticClient client) { }
3434
protected virtual void OnAfterCall(IElasticClient client) { }

src/Tests/Tests.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@
321321
<Compile Include=".\Mapping\Types\Core\Number\NumberMappingTests.cs" />
322322
<Compile Include="Aggregations\AggregationVisitorTests.cs" />
323323
<Compile Include="CodeStandards\Serialization\Converters.doc.cs" />
324+
<Compile Include="Document\Multiple\ReindexRethrottle\ReindexRethrottleApiTests.cs" />
325+
<Compile Include="Document\Multiple\ReindexRethrottle\ReindexRethrottleUrlTests.cs" />
324326
<Compile Include="Framework\MockData\Tag.cs" />
325327
<Compile Include="Framework\MockResponses\SniffingResponse.cs" />
326328
<Compile Include="Indices\IndexManagement\OpenCloseIndex\OpenIndex\OpenIndexApiTests.cs" />

0 commit comments

Comments
 (0)