3, // replicas
"MasterSlave",
true); // do rebalance
// add fake liveInstance
ZKHelixDataAccessor accessor =
new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
Builder keyBuilder = new Builder(clusterName);
LiveInstance liveInstance = new LiveInstance("localhost_12918");
liveInstance.setSessionId("session_0");
liveInstance.setHelixVersion("version_0");
accessor.setProperty(keyBuilder.liveInstance("localhost_12918"), liveInstance);
// drop without stop the process, should throw exception
try
{
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR,
"--dropNode", clusterName, "localhost:12918" });
Assert.fail("Should throw exception since localhost_12918 is still in LIVEINSTANCES/");
}
catch (Exception e)
{
// OK
}
accessor.removeProperty(keyBuilder.liveInstance("localhost_12918"));
// drop without disable, should throw exception
try
{
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR,
"--dropNode", clusterName, "localhost:12918" });
Assert.fail("Should throw exception since localhost_12918 is enabled");
}
catch (Exception e)
{
// e.printStackTrace();
// OK
}
// drop it
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR,
"--enableInstance", clusterName, "localhost_12918", "false" });
ClusterSetup.processCommandLineArgs(new String[] { "--zkSvr", ZK_ADDR, "--dropNode",
clusterName, "localhost:12918" });
Assert.assertNull(accessor.getProperty(keyBuilder.instanceConfig("localhost_12918")),
"Instance config should be dropped");
Assert.assertFalse(_gZkClient.exists(PropertyPathConfig.getPath(PropertyType.INSTANCES,
clusterName,
"localhost_12918")),
"Instance/host should be dropped");