Improved acknowledgement test for cluster reroute with dry_run flag

Usually acknowledged true means that all nodes have digested the change and are in sync. When no changes are made, there is no need to push a new cluster state, no need to wait for ack either, but can't guarantee that all nodes are in sync.

When using cluster reroute with dryRun flag no changes are made, this test was based on the wrong assumption that acknowledged meant all nodes were in sync, which is not the case here.

Changed the test to only read the cluster state from the master, to check that nothing changed there after processing the cluster state update.
This commit is contained in:
Luca Cavanna 2013-11-01 15:45:31 +01:00
parent 6df60b7271
commit a021c1d4f2
1 changed files with 20 additions and 19 deletions

View File

@ -186,30 +186,30 @@ public class AckTests extends AbstractIntegrationTest {
ClusterRerouteResponse clusterRerouteResponse = client().admin().cluster().prepareReroute().setDryRun(true).add(moveAllocationCommand).get();
assertThat(clusterRerouteResponse.isAcknowledged(), equalTo(true));
for (Client client : clients()) {
ClusterStateResponse clusterStateResponse = client.admin().cluster().prepareState().setLocal(true).get();
RoutingNode routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.fromNode());
for (MutableShardRouting mutableShardRouting : routingNode) {
//the shard that we wanted to move is still on the same node, as we had dryRun flag
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
assertThat(mutableShardRouting.started(), equalTo(true));
}
//testing only on master with the latest cluster state as we didn't make any change thus we cannot guarantee that
//all nodes hold the same cluster state version. We only know there was no need to change anything, thus no need for ack on this update.
ClusterStateResponse clusterStateResponse = client().admin().cluster().prepareState().get();
RoutingNode routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.fromNode());
boolean found = false;
for (MutableShardRouting mutableShardRouting : routingNode) {
//the shard that we wanted to move is still on the same node, as we had dryRun flag
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
assertThat(mutableShardRouting.started(), equalTo(true));
found = true;
break;
}
}
assertThat(found, equalTo(true));
routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.toNode());
boolean found = false;
for (MutableShardRouting mutableShardRouting : routingNode) {
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
found = true;
break;
}
routingNode = clusterStateResponse.getState().routingNodes().nodesToShards().get(moveAllocationCommand.toNode());
for (MutableShardRouting mutableShardRouting : routingNode) {
if (mutableShardRouting.shardId().equals(moveAllocationCommand.shardId())) {
fail("shard [" + mutableShardRouting + "] shouldn't be on node [" + moveAllocationCommand.toString() + "]");
}
assertThat(found, equalTo(false));
}
}
private static MoveAllocationCommand getAllocationCommand() {
private MoveAllocationCommand getAllocationCommand() {
String fromNodeId = null;
String toNodeId = null;
MutableShardRouting shardToBeMoved = null;
@ -218,7 +218,7 @@ public class AckTests extends AbstractIntegrationTest {
if (routingNode.node().isDataNode()) {
if (fromNodeId == null && routingNode.numberOfOwningShards() > 0) {
fromNodeId = routingNode.nodeId();
shardToBeMoved = routingNode.shards().get(0);
shardToBeMoved = routingNode.shards().get(randomInt(routingNode.shards().size()-1));
} else {
toNodeId = routingNode.nodeId();
}
@ -233,6 +233,7 @@ public class AckTests extends AbstractIntegrationTest {
assert toNodeId != null;
assert shardToBeMoved != null;
logger.info("==> going to move shard [{}] from [{}] to [{}]", shardToBeMoved, fromNodeId, toNodeId);
return new MoveAllocationCommand(shardToBeMoved.shardId(), fromNodeId, toNodeId);
}