List<Integer> nodesChecked = Lists.newArrayList();
for(RebalanceTaskInfo plan: plans) {
nodesChecked.add(plan.getStealerId());
assertEquals(servers[plan.getStealerId()].getMetadataStore().getRebalancerState(),
new RebalancerState(Lists.newArrayList(plan)));
assertEquals(servers[plan.getStealerId()].getMetadataStore().getCluster(),
finalCluster);
}
List<Integer> allNodes = Lists.newArrayList(Utils.nodeListToNodeIdList(Lists.newArrayList(currentCluster.getNodes())));
allNodes.removeAll(nodesChecked);
// Check all other nodes
for(int nodeId: allNodes) {
assertEquals(servers[nodeId].getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
assertEquals(servers[nodeId].getMetadataStore().getCluster(), finalCluster);
}
// Clean-up everything
cleanUpAllState();
// Test 2) Add a plan before hand on one of them which should
// trigger a rollback
servers[3].getMetadataStore()
.getRebalancerState()
.update(new RebalanceTaskInfo(3,
0,
new HashMap<String, List<Integer>>(),
currentCluster));
try {
adminClient.rebalanceOps.rebalanceStateChange(currentCluster,
finalCluster,
servers[2].getMetadataStore()
.getStoreDefList(),
servers[2].getMetadataStore()
.getStoreDefList(),
plans,
false,
true,
true,
true,
true);
fail("Should have thrown an exception since we added state before hand");
} catch(VoldemortRebalancingException e) {}
// All nodes should have nothing in their rebalancing state
// except node 3 + all of them should have old cluster metadata
for(VoldemortServer server: servers) {
if(server.getMetadataStore().getNodeId() != 3) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
}
assertEquals(server.getMetadataStore().getCluster(), currentCluster);
}
// Clean-up everything
cleanUpAllState();
// Test 3) Shut one node down
ServerTestUtils.stopVoldemortServer(servers[3]);
servers[3] = null;
try {
adminClient.rebalanceOps.rebalanceStateChange(currentCluster,
finalCluster,
servers[2].getMetadataStore()
.getStoreDefList(),
servers[2].getMetadataStore()
.getStoreDefList(),
plans,
false,
true,
true,
true,
true);
fail("Should have thrown an exception since we added state before hand");
} catch(VoldemortRebalancingException e) {}
// All nodes should have nothing in their rebalancing state
// exception node 3
for(VoldemortServer server: servers) {
if(server != null) {
assertEquals(server.getMetadataStore().getRebalancerState(),
new RebalancerState(new ArrayList<RebalanceTaskInfo>()));
assertEquals(server.getMetadataStore().getCluster(), currentCluster);
}
}
} finally {
shutDown();