IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
idealState.setRebalanceMode(RebalanceMode.CUSTOMIZED);
accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
// start controller
MockController controller =
new MockController(_zkaddr, clusterName, "controller_0");
controller.syncStart();
// start participants
for (int i = 0; i < n; i++) {
String instanceName = "localhost_" + (12918 + i);
participants[i] = new MockParticipant(_zkaddr, clusterName, instanceName);
participants[i].syncStart();
}
boolean result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// disable [TestDB0_0, TestDB0_5] on localhost_12919
String command =
"--zkSvr " + _zkaddr + " --enablePartition false " + clusterName
+ " localhost_12919 TestDB0 TestDB0_0 TestDB0_5";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// make sure localhost_12918 is in OFFLINE state for [TestDB0_0, TestDB0_5]
Map<String, Map<String, String>> expectStateMap = new HashMap<String, Map<String, String>>();
Map<String, String> expectInstanceStateMap = new HashMap<String, String>();
expectInstanceStateMap.put("localhost_12919", "OFFLINE");
expectStateMap.put("TestDB0_0", expectInstanceStateMap);
expectStateMap.put("TestDB0_5", expectInstanceStateMap);
result = ZkTestHelper.verifyState(_zkclient, clusterName, "TestDB0", expectStateMap, "==");
Assert.assertTrue(result, "localhost_12919"
+ " should be in OFFLINE for [TestDB0_0, TestDB0_5]");
// re-enable localhost_12919 for [TestDB0_0, TestDB0_5]
command =
"--zkSvr " + _zkaddr + " --enablePartition true " + clusterName
+ " localhost_12919 TestDB0 TestDB0_0 TestDB0_5";
ClusterSetup.processCommandLineArgs(command.split("\\s+"));
result =
ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(_zkaddr,
clusterName));
Assert.assertTrue(result);
// make sure localhost_12919 is NOT in OFFLINE state for [TestDB0_0, TestDB0_5]
result = ZkTestHelper.verifyState(_zkclient, clusterName, "TestDB0", expectStateMap, "!=");
Assert.assertTrue(result, "localhost_12919" + " should NOT be in OFFLINE");
// clean up
// wait for all zk callbacks done
controller.syncStop();
for (int i = 0; i < 5; i++) {
participants[i].syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));