addCluster(clusterName);
addInstancesToCluster(clusterName, "localhost:123", 6, null);
addResource(clusterName, "db_11", 8);
rebalanceResource(clusterName, "db_11");
ClusterControllerManager controller =
new ClusterControllerManager(ZK_ADDR, clusterName, "controller_9900");
controller.syncStart();
// start mock nodes
Map<String, MockParticipantManager> participants =
new HashMap<String, MockParticipantManager>();
for (int i = 0; i < 6; i++) {
String instanceName = "localhost_123" + i;
MockParticipantManager participant =
new MockParticipantManager(ZK_ADDR, clusterName, instanceName);
participant.syncStart();
participants.put(instanceName, participant);
}
HelixDataAccessor accessor;
// drop node should fail as not disabled
String instanceUrl = getInstanceUrl(clusterName, "localhost_1232");
deleteUrl(instanceUrl, true);
// disabled node
String response = assertSuccessPostOperation(instanceUrl, enableInstanceCmd(false), false);
Assert.assertTrue(response.contains("false"));
// Cannot drop / swap
deleteUrl(instanceUrl, true);
String instancesUrl = getClusterUrl(clusterName) + "/instances";
response =
assertSuccessPostOperation(instancesUrl,
swapInstanceCmd("localhost_1232", "localhost_12320"), true);
// disconnect the node
participants.get("localhost_1232").syncStop();
// add new node then swap instance
response = assertSuccessPostOperation(instancesUrl, addInstanceCmd("localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
// swap instance. The instance get swapped out should not exist anymore
response =
assertSuccessPostOperation(instancesUrl,
swapInstanceCmd("localhost_1232", "localhost_12320"), false);
Assert.assertTrue(response.contains("localhost_12320"));
Assert.assertFalse(response.contains("localhost_1232\""));
accessor = participants.get("localhost_1231").getHelixDataAccessor();
String path = accessor.keyBuilder().instanceConfig("localhost_1232").getPath();
Assert.assertFalse(_gZkClient.exists(path));
MockParticipantManager newParticipant =
new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12320");
newParticipant.syncStart();
participants.put("localhost_12320", newParticipant);
boolean verifyResult =
ClusterStateVerifier
.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(verifyResult);
// clean up
controller.syncStop();
for (MockParticipantManager participant : participants.values()) {
participant.syncStop();
}
}