pkuwm commented on a change in pull request #1053:
URL: https://github.com/apache/helix/pull/1053#discussion_r434294418
##########
File path: helix-core/src/test/java/org/apache/helix/tools/TestClusterSetup.java
##########
@@ -356,51 +360,57 @@ public void testDropInstance() throws Exception {
"MasterSlave", true); // do rebalance
// add fake liveInstance
- ZKHelixDataAccessor accessor =
- new ZKHelixDataAccessor(clusterName, new
ZkBaseDataAccessor<ZNRecord>(ZK_ADDR));
- 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);
+ HelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName,
+ new ZkBaseDataAccessor.Builder<ZNRecord>()
+ .setRealmMode(RealmAwareZkClient.RealmMode.SINGLE_REALM)
+ .setZkClientType(ZkBaseDataAccessor.ZkClientType.DEDICATED)
+ .setZkAddress(ZK_ADDR)
+ .build());
- // 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
+ Builder keyBuilder = new Builder(clusterName);
+ LiveInstance liveInstance = new LiveInstance(instanceName);
+ liveInstance.setSessionId("session_0");
+ liveInstance.setHelixVersion("version_0");
+ accessor.setProperty(keyBuilder.liveInstance(instanceName),
liveInstance);
+
+ // Drop instance without stopping the live instance, should throw
HelixException
+ try {
+ ClusterSetup.processCommandLineArgs(
+ new String[]{"--zkSvr", ZK_ADDR, "--dropNode", clusterName,
instanceAddress});
+ Assert.fail("Should throw exception since localhost_12918 is still in
LIVEINSTANCES/");
+ } catch (HelixException expected) {
+ Assert.assertEquals(expected.getMessage(),
+ "Cannot drop instance " + instanceName + " as it is still live.
Please stop it first");
+ }
+ accessor.removeProperty(keyBuilder.liveInstance(instanceName));
+
+ // drop without disable, should throw exception
+ try {
+ ClusterSetup.processCommandLineArgs(
+ new String[]{"--zkSvr", ZK_ADDR, "--dropNode", clusterName,
instanceAddress});
+ Assert.fail("Should throw exception since " + instanceName + " is
enabled");
+ } catch (HelixException expected) {
+ Assert.assertEquals(expected.getMessage(),
+ "Node " + instanceName + " is enabled, cannot drop");
+ }
+
+ // Disable the instance
+ ClusterSetup.processCommandLineArgs(
+ new String[]{"--zkSvr", ZK_ADDR, "--enableInstance", clusterName,
instanceName, "false"});
+ // Drop the instance
+ ClusterSetup.processCommandLineArgs(
+ new String[]{"--zkSvr", ZK_ADDR, "--dropNode", clusterName,
instanceAddress});
+
+
Assert.assertNull(accessor.getProperty(keyBuilder.instanceConfig(instanceName)),
+ "Instance config should be dropped");
+
Assert.assertFalse(_gZkClient.exists(PropertyPathBuilder.instance(clusterName,
instanceName)),
+ "Instance/host should be dropped");
+ } finally {
+ // Have to close the dedicated zkclient in accessor to avoid zkclient
leakage.
+ accessor.getBaseDataAccessor().close();
+ TestHelper.dropCluster(clusterName, _gZkClient);
Review comment:
Verified and updated.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]