5454import org .elasticsearch .common .time .TimeProviderUtils ;
5555import org .elasticsearch .common .unit .ByteSizeValue ;
5656import org .elasticsearch .common .util .Maps ;
57+ import org .elasticsearch .common .util .set .Sets ;
5758import org .elasticsearch .core .Strings ;
5859import org .elasticsearch .core .TimeValue ;
5960import org .elasticsearch .core .Tuple ;
@@ -566,7 +567,21 @@ public void testNoDataNodes() {
566567 }
567568
568569 public void testAppliesMoveCommands () {
569- var desiredBalanceComputer = createDesiredBalanceComputer ();
570+ var desiredBalanceComputer = createDesiredBalanceComputer (new ShardsAllocator () {
571+ @ Override
572+ public void allocate (RoutingAllocation allocation ) {
573+ assertThat (
574+ "unexpected relocating shards: " + allocation .routingNodes (),
575+ allocation .routingNodes ().getRelocatingShardCount (),
576+ equalTo (0 )
577+ );
578+ }
579+
580+ @ Override
581+ public ShardAllocationDecision decideShardAllocation (ShardRouting shard , RoutingAllocation allocation ) {
582+ throw new AssertionError ("only used for allocation explain" );
583+ }
584+ });
570585 var clusterState = createInitialClusterState (3 );
571586 var index = clusterState .metadata ().getProject ().index (TEST_INDEX ).getIndex ();
572587
@@ -578,25 +593,29 @@ public void testAppliesMoveCommands() {
578593 }
579594 clusterState = rebuildRoutingTable (clusterState , routingNodes );
580595
581- var desiredBalance = desiredBalanceComputer .compute (
582- DesiredBalance .BECOME_MASTER_INITIAL ,
583- createInput (clusterState ),
584- queue (
585- new MoveAllocationCommand (index .getName (), 0 , "node-1" , "node-2" ),
586- new MoveAllocationCommand (index .getName (), 1 , "node-1" , "node-2" )
587- ),
588- input -> true
589- );
596+ final var dataNodeIds = clusterState .nodes ().getDataNodes ().keySet ();
597+ for (var nodeId : List .of ("node-0" , "node-1" )) {
598+ var desiredBalance = desiredBalanceComputer .compute (
599+ DesiredBalance .BECOME_MASTER_INITIAL ,
600+ createInput (clusterState ),
601+ queue (
602+ new MoveAllocationCommand (index .getName (), 0 , nodeId , "node-2" ),
603+ new MoveAllocationCommand (index .getName (), 1 , nodeId , "node-2" )
604+ ),
605+ input -> true
606+ );
590607
591- assertDesiredAssignments (
592- desiredBalance ,
593- Map .of (
594- new ShardId (index , 0 ),
595- new ShardAssignment (Set .of ("node-0" , "node-2" ), 2 , 0 , 0 ),
596- new ShardId (index , 1 ),
597- new ShardAssignment (Set .of ("node-0" , "node-2" ), 2 , 0 , 0 )
598- )
599- );
608+ final Set <String > expectedNodeIds = Sets .difference (dataNodeIds , Set .of (nodeId ));
609+ assertDesiredAssignments (
610+ desiredBalance ,
611+ Map .of (
612+ new ShardId (index , 0 ),
613+ new ShardAssignment (expectedNodeIds , 2 , 0 , 0 ),
614+ new ShardId (index , 1 ),
615+ new ShardAssignment (expectedNodeIds , 2 , 0 , 0 )
616+ )
617+ );
618+ }
600619 }
601620
602621 public void testDesiredBalanceShouldConvergeInABigCluster () {
0 commit comments