25
25
import org .elasticsearch .action .admin .indices .create .CreateIndexClusterStateUpdateRequest ;
26
26
import org .elasticsearch .action .admin .indices .stats .CommonStats ;
27
27
import org .elasticsearch .action .admin .indices .stats .IndexStats ;
28
- import org .elasticsearch .action .admin .indices .stats .IndicesStatsRequestBuilder ;
28
+ import org .elasticsearch .action .admin .indices .stats .IndicesStatsAction ;
29
+ import org .elasticsearch .action .admin .indices .stats .IndicesStatsRequest ;
29
30
import org .elasticsearch .action .admin .indices .stats .IndicesStatsResponse ;
30
31
import org .elasticsearch .action .support .ActionFilters ;
31
32
import org .elasticsearch .action .support .ActiveShardCount ;
32
33
import org .elasticsearch .action .support .PlainActionFuture ;
33
- import org .elasticsearch .client .AdminClient ;
34
34
import org .elasticsearch .client .Client ;
35
- import org .elasticsearch .client .IndicesAdminClient ;
36
35
import org .elasticsearch .cluster .ClusterName ;
37
36
import org .elasticsearch .cluster .ClusterState ;
38
37
import org .elasticsearch .cluster .metadata .AliasAction ;
43
42
import org .elasticsearch .cluster .metadata .MetaData ;
44
43
import org .elasticsearch .cluster .metadata .MetaDataCreateIndexService ;
45
44
import org .elasticsearch .cluster .metadata .MetaDataIndexAliasesService ;
45
+ import org .elasticsearch .cluster .node .DiscoveryNode ;
46
46
import org .elasticsearch .cluster .service .ClusterService ;
47
47
import org .elasticsearch .common .UUIDs ;
48
48
import org .elasticsearch .common .settings .Settings ;
53
53
import org .elasticsearch .index .Index ;
54
54
import org .elasticsearch .index .shard .DocsStats ;
55
55
import org .elasticsearch .rest .action .cat .RestIndicesActionTests ;
56
+ import org .elasticsearch .tasks .Task ;
56
57
import org .elasticsearch .test .ESTestCase ;
57
58
import org .elasticsearch .threadpool .ThreadPool ;
58
59
import org .elasticsearch .transport .TransportService ;
@@ -345,9 +346,12 @@ public void testRejectDuplicateAlias() {
345
346
assertThat (ex .getMessage (), containsString ("index template [test-template]" ));
346
347
}
347
348
348
- public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPrimariesFromWriteIndex () {
349
+ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPrimariesFromWriteIndex () throws Exception {
349
350
final TransportService mockTransportService = mock (TransportService .class );
350
351
final ClusterService mockClusterService = mock (ClusterService .class );
352
+ final DiscoveryNode mockNode = mock (DiscoveryNode .class );
353
+ when (mockNode .getId ()).thenReturn ("mocknode" );
354
+ when (mockClusterService .localNode ()).thenReturn (mockNode );
351
355
final ThreadPool mockThreadPool = mock (ThreadPool .class );
352
356
final MetaDataCreateIndexService mockCreateIndexService = mock (MetaDataCreateIndexService .class );
353
357
final IndexNameExpressionResolver mockIndexNameExpressionResolver = mock (IndexNameExpressionResolver .class );
@@ -356,31 +360,25 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
356
360
final MetaDataIndexAliasesService mdIndexAliasesService = mock (MetaDataIndexAliasesService .class );
357
361
358
362
final Client mockClient = mock (Client .class );
359
- final AdminClient mockAdminClient = mock (AdminClient .class );
360
- final IndicesAdminClient mockIndicesAdminClient = mock (IndicesAdminClient .class );
361
- when (mockClient .admin ()).thenReturn (mockAdminClient );
362
- when (mockAdminClient .indices ()).thenReturn (mockIndicesAdminClient );
363
363
364
- final IndicesStatsRequestBuilder mockIndicesStatsBuilder = mock (IndicesStatsRequestBuilder .class );
365
- when (mockIndicesAdminClient .prepareStats (any ())).thenReturn (mockIndicesStatsBuilder );
366
364
final Map <String , IndexStats > indexStats = new HashMap <>();
367
365
int total = randomIntBetween (500 , 1000 );
368
366
indexStats .put ("logs-index-000001" , createIndexStats (200L , total ));
369
367
indexStats .put ("logs-index-000002" , createIndexStats (300L , total ));
370
368
final IndicesStatsResponse statsResponse = createAliasToMultipleIndicesStatsResponse (indexStats );
371
- when (mockIndicesStatsBuilder .clear ()).thenReturn (mockIndicesStatsBuilder );
372
- when (mockIndicesStatsBuilder .setDocs (true )).thenReturn (mockIndicesStatsBuilder );
373
369
374
- assert statsResponse .getPrimaries ().getDocs ().getCount () == 500L ;
375
- assert statsResponse .getTotal ().getDocs ().getCount () == (total + total );
376
370
377
371
doAnswer (invocation -> {
378
372
Object [] args = invocation .getArguments ();
379
- assert args .length == 1 ;
380
- ActionListener <IndicesStatsResponse > listener = (ActionListener <IndicesStatsResponse >) args [0 ];
373
+ assert args .length == 3 ;
374
+ @ SuppressWarnings ("unchecked" )
375
+ ActionListener <IndicesStatsResponse > listener = (ActionListener <IndicesStatsResponse >) args [2 ];
381
376
listener .onResponse (statsResponse );
382
377
return null ;
383
- }).when (mockIndicesStatsBuilder ).execute (any (ActionListener .class ));
378
+ }).when (mockClient ).execute (any (IndicesStatsAction .class ), any (IndicesStatsRequest .class ), any (ActionListener .class ));
379
+
380
+ assert statsResponse .getPrimaries ().getDocs ().getCount () == 500L ;
381
+ assert statsResponse .getTotal ().getDocs ().getCount () == (total + total );
384
382
385
383
final IndexMetaData .Builder indexMetaData = IndexMetaData .builder ("logs-index-000001" )
386
384
.putAlias (AliasMetaData .builder ("logs-alias" ).writeIndex (false ).build ()).settings (settings (Version .CURRENT ))
@@ -401,7 +399,7 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
401
399
RolloverRequest rolloverRequest = new RolloverRequest ("logs-alias" , "logs-index-000003" );
402
400
rolloverRequest .addMaxIndexDocsCondition (500L );
403
401
rolloverRequest .dryRun (true );
404
- transportRolloverAction .masterOperation (rolloverRequest , stateBefore , future );
402
+ transportRolloverAction .masterOperation (mock ( Task . class ), rolloverRequest , stateBefore , future );
405
403
406
404
RolloverResponse response = future .actionGet ();
407
405
assertThat (response .getOldIndex (), equalTo ("logs-index-000002" ));
@@ -417,7 +415,7 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
417
415
rolloverRequest = new RolloverRequest ("logs-alias" , "logs-index-000003" );
418
416
rolloverRequest .addMaxIndexDocsCondition (300L );
419
417
rolloverRequest .dryRun (true );
420
- transportRolloverAction .masterOperation (rolloverRequest , stateBefore , future );
418
+ transportRolloverAction .masterOperation (mock ( Task . class ), rolloverRequest , stateBefore , future );
421
419
422
420
response = future .actionGet ();
423
421
assertThat (response .getOldIndex (), equalTo ("logs-index-000002" ));
0 commit comments