diff options
Diffstat (limited to 'core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java')
-rw-r--r-- | core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java | 30 |
1 files changed, 10 insertions, 20 deletions
diff --git a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java index ccdc4deb02..ca9d61997b 100644 --- a/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.java +++ b/core/src/test/java/org/elasticsearch/cluster/routing/allocation/PrimaryElectionRoutingTests.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; @@ -29,7 +30,6 @@ 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; @@ -59,28 +59,23 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase { logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1"))).build(); - RoutingAllocation.Result result = strategy.reroute(clusterState, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(result).build(); + clusterState = strategy.reroute(clusterState, "reroute"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node2"))).build(); - result = strategy.reroute(clusterState, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(result).build(); + clusterState = strategy.reroute(clusterState, "reroute"); logger.info("Start the primary shard (on node1)"); RoutingNodes routingNodes = clusterState.getRoutingNodes(); - result = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING)); - clusterState = ClusterState.builder(clusterState).routingResult(result).build(); + clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node1").shardsWithState(INITIALIZING)); logger.info("Start the backup shard (on node2)"); routingNodes = clusterState.getRoutingNodes(); - result = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING)); - clusterState = ClusterState.builder(clusterState).routingResult(result).build(); + clusterState = strategy.applyStartedShards(clusterState, routingNodes.node("node2").shardsWithState(INITIALIZING)); logger.info("Adding third node and reroute and kill first node"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder(clusterState.nodes()).add(newNode("node3")).remove("node1")).build(); RoutingTable prevRoutingTable = clusterState.routingTable(); - result = strategy.deassociateDeadNodes(clusterState, true, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(result).build(); + clusterState = strategy.deassociateDeadNodes(clusterState, true, "reroute"); routingNodes = clusterState.getRoutingNodes(); routingTable = clusterState.routingTable(); @@ -112,13 +107,11 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase { logger.info("Adding two nodes and performing rerouting"); clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode("node1")).add(newNode("node2"))).build(); - RoutingAllocation.Result rerouteResult = allocation.reroute(clusterState, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build(); + clusterState = allocation.reroute(clusterState, "reroute"); logger.info("Start the primary shards"); RoutingNodes routingNodes = clusterState.getRoutingNodes(); - rerouteResult = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); - clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build(); + clusterState = allocation.applyStartedShards(clusterState, routingNodes.shardsWithState(INITIALIZING)); routingNodes = clusterState.getRoutingNodes(); assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(2)); @@ -130,11 +123,8 @@ public class PrimaryElectionRoutingTests extends ESAllocationTestCase { logger.info("--> fail node with primary"); String nodeIdToFail = clusterState.routingTable().index("test").shard(0).primaryShard().currentNodeId(); String nodeIdRemaining = nodeIdToFail.equals("node1") ? "node2" : "node1"; - clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder() - .add(newNode(nodeIdRemaining)) - ).build(); - rerouteResult = allocation.deassociateDeadNodes(clusterState, true, "reroute"); - clusterState = ClusterState.builder(clusterState).routingResult(rerouteResult).build(); + clusterState = ClusterState.builder(clusterState).nodes(DiscoveryNodes.builder().add(newNode(nodeIdRemaining))).build(); + clusterState = allocation.deassociateDeadNodes(clusterState, true, "reroute"); routingNodes = clusterState.getRoutingNodes(); assertThat(routingNodes.shardsWithState(STARTED).size(), equalTo(1)); |