55using FluentAssertions ;
66using Nest ;
77using Tests . Document . Multiple . Reindex ;
8+ using Tests . Document . Multiple . ReindexOnServer ;
89using Tests . Framework ;
910using Tests . Framework . Integration ;
1011using Tests . Framework . MockData ;
1415namespace 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 ;
0 commit comments