|  | @@ -440,7 +440,7 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          logger.info("Adding two nodes and performing rerouting");
 | 
	
		
			
				|  |  |          clusterState = ClusterState.builder(clusterState)
 | 
	
		
			
				|  |  | -            .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")))
 | 
	
		
			
				|  |  | +            .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).localNodeId("node1").masterNodeId("node1"))
 | 
	
		
			
				|  |  |              .build();
 | 
	
		
			
				|  |  |          clusterState = strategy.reroute(clusterState, "reroute");
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -535,7 +535,15 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          // add 4 nodes
 | 
	
		
			
				|  |  |          clusterState = ClusterState.builder(clusterState)
 | 
	
		
			
				|  |  | -            .nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2")).add(newNode("node3")).add(newNode("node4")))
 | 
	
		
			
				|  |  | +            .nodes(
 | 
	
		
			
				|  |  | +                DiscoveryNodes.builder()
 | 
	
		
			
				|  |  | +                    .add(newNode("node1"))
 | 
	
		
			
				|  |  | +                    .add(newNode("node2"))
 | 
	
		
			
				|  |  | +                    .add(newNode("node3"))
 | 
	
		
			
				|  |  | +                    .add(newNode("node4"))
 | 
	
		
			
				|  |  | +                    .localNodeId("node1")
 | 
	
		
			
				|  |  | +                    .masterNodeId("node1")
 | 
	
		
			
				|  |  | +            )
 | 
	
		
			
				|  |  |              .build();
 | 
	
		
			
				|  |  |          clusterState = ClusterState.builder(clusterState).routingTable(allocation.reroute(clusterState, "reroute").routingTable()).build();
 | 
	
		
			
				|  |  |          assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(1));
 | 
	
	
		
			
				|  | @@ -560,13 +568,19 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
 | 
	
		
			
				|  |  |          ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
 | 
	
		
			
				|  |  |          assertThat(newState, not(equalTo(clusterState)));
 | 
	
		
			
				|  |  |          clusterState = newState;
 | 
	
		
			
				|  |  | -        // the primary gets allocated on another node, replicas are initializing
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // The started replica gets promoted to primary and the initializing replica is reset. The other replica will be assigned.
 | 
	
		
			
				|  |  |          assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
 | 
	
		
			
				|  |  |          assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
 | 
	
		
			
				|  |  |          assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
 | 
	
		
			
				|  |  |          assertThat(newPrimaryShard.allocationId(), equalTo(startedReplica.allocationId()));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // Another reroute changes nothing
 | 
	
		
			
				|  |  | +        clusterState = allocation.reroute(clusterState, "test");
 | 
	
		
			
				|  |  | +        assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
 | 
	
		
			
				|  |  | +        assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testFailAllReplicasInitializingOnPrimaryFailWhileHavingAReplicaToElect() {
 | 
	
	
		
			
				|  | @@ -609,11 +623,18 @@ public class FailedShardsRoutingTests extends ESAllocationTestCase {
 | 
	
		
			
				|  |  |          ClusterState newState = applyFailedShard(allocation, clusterState, primaryShardToFail);
 | 
	
		
			
				|  |  |          assertThat(newState, not(equalTo(clusterState)));
 | 
	
		
			
				|  |  |          clusterState = newState;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // The started replica gets promoted to primary and the initializing replica is reset. The other replica will be assigned.
 | 
	
		
			
				|  |  |          assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
 | 
	
		
			
				|  |  |          assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          ShardRouting newPrimaryShard = clusterState.routingTable().index("test").shard(0).primaryShard();
 | 
	
		
			
				|  |  |          assertThat(newPrimaryShard, not(equalTo(primaryShardToFail)));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // Another reroute changes nothing
 | 
	
		
			
				|  |  | +        clusterState = allocation.reroute(clusterState, "test");
 | 
	
		
			
				|  |  | +        assertThat(shardsWithState(clusterState.getRoutingNodes(), STARTED).size(), equalTo(1));
 | 
	
		
			
				|  |  | +        assertThat(shardsWithState(clusterState.getRoutingNodes(), INITIALIZING).size(), equalTo(2));
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      public void testReplicaOnNewestVersionIsPromoted() {
 |