@@ -221,7 +221,7 @@ public void testExecuteAllocateNotCompleteOnlyOneCopyAllocated() throws Exceptio
221221 new ClusterStateWaitStep .Result (false , new CheckShrinkReadyStep .Info ("node1" , 2 , 1 )));
222222 }
223223
224- public void testExecuteAllocateUnassigned () throws Exception {
224+ public void testExecuteAllocateReplicaUnassigned () {
225225 Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
226226 Map <String , String > requires = AllocateActionTests .randomMap (1 , 5 );
227227 Settings .Builder existingSettings = Settings .builder ()
@@ -239,12 +239,12 @@ public void testExecuteAllocateUnassigned() throws Exception {
239239
240240 IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
241241 .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , true , ShardRoutingState .STARTED ))
242- .addShard (TestShardRouting .newShardRouting (new ShardId (index , 1 ), null , null , true , ShardRoutingState .UNASSIGNED ,
242+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), null , null , false , ShardRoutingState .UNASSIGNED ,
243243 new UnassignedInfo (randomFrom (UnassignedInfo .Reason .values ()), "the shard is intentionally unassigned" )));
244244
245245 CheckShrinkReadyStep step = createRandomInstance ();
246- assertAllocateStatus (index , 2 , 0 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
247- new ClusterStateWaitStep .Result (false , new CheckShrinkReadyStep . Info ( "" , 2 , - 1 ) ));
246+ assertAllocateStatus (index , 1 , 1 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
247+ new ClusterStateWaitStep .Result (true , null ));
248248 }
249249
250250 /**
@@ -267,7 +267,9 @@ public void testExecuteAllocateUnassigned() throws Exception {
267267 public void testExecuteReplicasNotAllocatedOnSingleNode () {
268268 Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
269269 Map <String , String > requires = Collections .singletonMap ("_id" , "node1" );
270- Settings .Builder existingSettings = Settings .builder ().put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
270+ Settings .Builder existingSettings = Settings .builder ()
271+ .put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
272+ .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id" , "node1" )
271273 .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
272274 Settings .Builder expectedSettings = Settings .builder ();
273275 Settings .Builder node1Settings = Settings .builder ();
@@ -278,12 +280,40 @@ public void testExecuteReplicasNotAllocatedOnSingleNode() {
278280
279281 IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
280282 .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , true , ShardRoutingState .STARTED ))
283+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 1 ), "node1" , false , ShardRoutingState .STARTED ))
284+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 1 ), "node2" , true , ShardRoutingState .STARTED ))
281285 .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), null , null , false , ShardRoutingState .UNASSIGNED ,
282286 new UnassignedInfo (UnassignedInfo .Reason .REPLICA_ADDED , "no attempt" )));
283287
284288 CheckShrinkReadyStep step = createRandomInstance ();
285- assertAllocateStatus (index , 1 , 1 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
286- new ClusterStateWaitStep .Result (false , new CheckShrinkReadyStep .Info ("" , 1 , -1 )));
289+ assertAllocateStatus (index , 2 , 1 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
290+ new ClusterStateWaitStep .Result (true , null ));
291+ }
292+
293+ public void testExecuteReplicasButCopiesNotPresent () {
294+ Index index = new Index (randomAlphaOfLengthBetween (1 , 20 ), randomAlphaOfLengthBetween (1 , 20 ));
295+ Map <String , String > requires = Collections .singletonMap ("_id" , "node1" );
296+ Settings .Builder existingSettings = Settings .builder ()
297+ .put (IndexMetaData .SETTING_VERSION_CREATED , Version .CURRENT .id )
298+ .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_PREFIX + "._id" , "node1" )
299+ .put (IndexMetaData .SETTING_INDEX_UUID , index .getUUID ());
300+ Settings .Builder expectedSettings = Settings .builder ();
301+ Settings .Builder node1Settings = Settings .builder ();
302+ Settings .Builder node2Settings = Settings .builder ();
303+ requires .forEach ((k , v ) -> {
304+ expectedSettings .put (IndexMetaData .INDEX_ROUTING_REQUIRE_GROUP_SETTING .getKey () + k , v );
305+ });
306+
307+ IndexRoutingTable .Builder indexRoutingTable = IndexRoutingTable .builder (index )
308+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), "node1" , true , ShardRoutingState .STARTED ))
309+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 1 ), "node2" , false , ShardRoutingState .STARTED ))
310+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 1 ), "node3" , true , ShardRoutingState .STARTED ))
311+ .addShard (TestShardRouting .newShardRouting (new ShardId (index , 0 ), null , null , false , ShardRoutingState .UNASSIGNED ,
312+ new UnassignedInfo (UnassignedInfo .Reason .REPLICA_ADDED , "no attempt" )));
313+
314+ CheckShrinkReadyStep step = createRandomInstance ();
315+ assertAllocateStatus (index , 2 , 1 , step , existingSettings , node1Settings , node2Settings , indexRoutingTable ,
316+ new ClusterStateWaitStep .Result (false , new CheckShrinkReadyStep .Info ("node1" , 2 , 1 )));
287317 }
288318
289319 public void testExecuteIndexMissing () throws Exception {
0 commit comments