2525import org .elasticsearch .action .admin .indices .create .CreateIndexClusterStateUpdateRequest ;
2626import org .elasticsearch .action .admin .indices .stats .CommonStats ;
2727import 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 ;
2930import org .elasticsearch .action .admin .indices .stats .IndicesStatsResponse ;
3031import org .elasticsearch .action .support .ActionFilters ;
3132import org .elasticsearch .action .support .ActiveShardCount ;
3233import org .elasticsearch .action .support .PlainActionFuture ;
33- import org .elasticsearch .client .AdminClient ;
3434import org .elasticsearch .client .Client ;
35- import org .elasticsearch .client .IndicesAdminClient ;
3635import org .elasticsearch .cluster .ClusterName ;
3736import org .elasticsearch .cluster .ClusterState ;
3837import org .elasticsearch .cluster .metadata .AliasAction ;
4342import org .elasticsearch .cluster .metadata .MetaData ;
4443import org .elasticsearch .cluster .metadata .MetaDataCreateIndexService ;
4544import org .elasticsearch .cluster .metadata .MetaDataIndexAliasesService ;
45+ import org .elasticsearch .cluster .node .DiscoveryNode ;
4646import org .elasticsearch .cluster .service .ClusterService ;
4747import org .elasticsearch .common .UUIDs ;
4848import org .elasticsearch .common .settings .Settings ;
5353import org .elasticsearch .index .Index ;
5454import org .elasticsearch .index .shard .DocsStats ;
5555import org .elasticsearch .rest .action .cat .RestIndicesActionTests ;
56+ import org .elasticsearch .tasks .Task ;
5657import org .elasticsearch .test .ESTestCase ;
5758import org .elasticsearch .threadpool .ThreadPool ;
5859import org .elasticsearch .transport .TransportService ;
@@ -345,9 +346,12 @@ public void testRejectDuplicateAlias() {
345346 assertThat (ex .getMessage (), containsString ("index template [test-template]" ));
346347 }
347348
348- public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPrimariesFromWriteIndex () {
349+ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPrimariesFromWriteIndex () throws Exception {
349350 final TransportService mockTransportService = mock (TransportService .class );
350351 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 );
351355 final ThreadPool mockThreadPool = mock (ThreadPool .class );
352356 final MetaDataCreateIndexService mockCreateIndexService = mock (MetaDataCreateIndexService .class );
353357 final IndexNameExpressionResolver mockIndexNameExpressionResolver = mock (IndexNameExpressionResolver .class );
@@ -356,31 +360,25 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
356360 final MetaDataIndexAliasesService mdIndexAliasesService = mock (MetaDataIndexAliasesService .class );
357361
358362 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 );
363363
364- final IndicesStatsRequestBuilder mockIndicesStatsBuilder = mock (IndicesStatsRequestBuilder .class );
365- when (mockIndicesAdminClient .prepareStats (any ())).thenReturn (mockIndicesStatsBuilder );
366364 final Map <String , IndexStats > indexStats = new HashMap <>();
367365 int total = randomIntBetween (500 , 1000 );
368366 indexStats .put ("logs-index-000001" , createIndexStats (200L , total ));
369367 indexStats .put ("logs-index-000002" , createIndexStats (300L , total ));
370368 final IndicesStatsResponse statsResponse = createAliasToMultipleIndicesStatsResponse (indexStats );
371- when (mockIndicesStatsBuilder .clear ()).thenReturn (mockIndicesStatsBuilder );
372- when (mockIndicesStatsBuilder .setDocs (true )).thenReturn (mockIndicesStatsBuilder );
373369
374- assert statsResponse .getPrimaries ().getDocs ().getCount () == 500L ;
375- assert statsResponse .getTotal ().getDocs ().getCount () == (total + total );
376370
377371 doAnswer (invocation -> {
378372 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 ];
381376 listener .onResponse (statsResponse );
382377 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 );
384382
385383 final IndexMetaData .Builder indexMetaData = IndexMetaData .builder ("logs-index-000001" )
386384 .putAlias (AliasMetaData .builder ("logs-alias" ).writeIndex (false ).build ()).settings (settings (Version .CURRENT ))
@@ -401,7 +399,7 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
401399 RolloverRequest rolloverRequest = new RolloverRequest ("logs-alias" , "logs-index-000003" );
402400 rolloverRequest .addMaxIndexDocsCondition (500L );
403401 rolloverRequest .dryRun (true );
404- transportRolloverAction .masterOperation (rolloverRequest , stateBefore , future );
402+ transportRolloverAction .masterOperation (mock ( Task . class ), rolloverRequest , stateBefore , future );
405403
406404 RolloverResponse response = future .actionGet ();
407405 assertThat (response .getOldIndex (), equalTo ("logs-index-000002" ));
@@ -417,7 +415,7 @@ public void testConditionEvaluationWhenAliasToWriteAndReadIndicesConsidersOnlyPr
417415 rolloverRequest = new RolloverRequest ("logs-alias" , "logs-index-000003" );
418416 rolloverRequest .addMaxIndexDocsCondition (300L );
419417 rolloverRequest .dryRun (true );
420- transportRolloverAction .masterOperation (rolloverRequest , stateBefore , future );
418+ transportRolloverAction .masterOperation (mock ( Task . class ), rolloverRequest , stateBefore , future );
421419
422420 response = future .actionGet ();
423421 assertThat (response .getOldIndex (), equalTo ("logs-index-000002" ));
0 commit comments