diff options
Diffstat (limited to 'core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java')
-rw-r--r-- | core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java index 5707a229da..77e83fd665 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/ElectReplicaAsPrimaryDuringRelocationTests.java @@ -22,6 +22,7 @@ package org.elasticsearch.cluster.routing.allocation; import org.apache.logging.log4j.Logger; import org.elasticsearch.Version; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.ESAllocationTestCase; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.MetaData; import org.elasticsearch.cluster.node.DiscoveryNodes; @@ -30,11 +31,11 @@ import org.elasticsearch.cluster.routing.RoutingNodes; import org.elasticsearch.cluster.routing.RoutingTable; import org.elasticsearch.common.logging.Loggers; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.cluster.ESAllocationTestCase; import static org.elasticsearch.cluster.routing.ShardRoutingState.INITIALIZING; import static org.elasticsearch.cluster.routing.ShardRoutingState.STARTED; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.not; /** * @@ -59,29 +60,26 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build(); - RoutingAllocation.Result routingResult = strategy.reroute(clusterState, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build(); + clusterState = strategy.reroute(clusterState, "reroute"); logger.info("Start the primary shards"); RoutingNodes routingNodes = clusterState.getRoutingNodes(); - routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); - clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build(); + clusterState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); logger.info("Start the replica shards"); routingNodes = clusterState.getRoutingNodes(); - routingResult = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); - clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build(); - routingNodes = clusterState.getRoutingNodes(); + ClusterState resultingState = strategy.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); + assertThat(resultingState, not(equalTo(clusterState))); + clusterState = resultingState; - assertTrue(routingResult.changed()); + routingNodes = clusterState.getRoutingNodes(); assertThat(clusterState.routingTable().index("test").shards().size(), equalTo(2)); assertThat(routingNodes.node("node1").numberOfShardsWithState(STARTED), equalTo(2)); assertThat(routingNodes.node("node2").numberOfShardsWithState(STARTED), equalTo(2)); logger.info("Start another node and perform rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3"))).build(); - routingResult = strategy.reroute(clusterState, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build(); + clusterState = strategy.reroute(clusterState, "reroute"); logger.info("find the replica shard that gets relocated"); IndexShardRoutingTable indexShardRoutingTable = null; @@ -95,8 +93,7 @@ public class ElectReplicaAsPrimaryDuringRelocationTests extends ESAllocationTest if (indexShardRoutingTable != null) { logger.info("kill the node [{}] of the primary shard for the relocating replica", indexShardRoutingTable.primaryShard().currentNodeId()); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).remove(indexShardRoutingTable.primaryShard().currentNodeId())).build(); - routingResult = strategy.deassociateDeadNodes(clusterState, true, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(routingResult).build(); + clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute"); logger.info("make sure all the primary shards are active"); assertThat(clusterState.routingTable().index("test").shard(0).primaryShard().active(), equalTo(true)); |