You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@helix.apache.org by GitBox <gi...@apache.org> on 2020/06/03 03:29:49 UTC

[GitHub] [helix] narendly commented on a change in pull request #1053: Fix test testDropInstance

narendly commented on a change in pull request #1053:
URL: https://github.com/apache/helix/pull/1053#discussion_r434287996



##########
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:
       Nit: usually a good idea to add a TestHelper.verify() to make sure the cluster has been dropped. This is recommended.




----------------------------------------------------------------
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:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@helix.apache.org
For additional commands, e-mail: reviews-help@helix.apache.org