You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by hu...@apache.org on 2019/11/19 20:39:04 UTC

[helix] branch master updated: Fix NullPointerException in TestDisableCustomCodeRunner_test. (#617)

This is an automated email from the ASF dual-hosted git repository.

hulee pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git


The following commit(s) were added to refs/heads/master by this push:
     new 8e0ac76  Fix NullPointerException in TestDisableCustomCodeRunner_test. (#617)
8e0ac76 is described below

commit 8e0ac7697fd519e3760bff0678aad4664f7c1853
Author: Huizhi L <ih...@gmail.com>
AuthorDate: Tue Nov 19 12:38:57 2019 -0800

    Fix NullPointerException in TestDisableCustomCodeRunner_test. (#617)
    
    In TestDisableCustomCodeRunner_test, a new fake live instance is created without an instance config, so when the cluster monitor is reporting metrics for this instance, its instance config is not found, thus a NullPointerException is thrown.
    
    Fix it by adding an instance config to the cluster for the fake live instance.
---
 .../helix/integration/TestDisableCustomCodeRunner.java   | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java b/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java
index dd6aba3..ab5a830 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/TestDisableCustomCodeRunner.java
@@ -38,6 +38,7 @@ import org.apache.helix.manager.zk.ZKHelixAdmin;
 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.model.ExternalView;
+import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.LiveInstance;
 import org.apache.helix.participant.CustomCodeCallbackHandler;
 import org.apache.helix.participant.HelixCustomCodeRunner;
@@ -177,10 +178,17 @@ public class TestDisableCustomCodeRunner extends ZkUnitTestBase {
     Assert.assertTrue(result);
 
     // Change live-instance should not invoke any custom-code runner
-    LiveInstance fakeInstance = new LiveInstance("fakeInstance");
+    String fakeInstanceName = "fakeInstance";
+    InstanceConfig instanceConfig = new InstanceConfig(fakeInstanceName);
+    instanceConfig.setHostName("localhost");
+    instanceConfig.setPort("10000");
+    instanceConfig.setInstanceEnabled(true);
+    admin.addInstance(clusterName, instanceConfig);
+
+    LiveInstance fakeInstance = new LiveInstance(fakeInstanceName);
     fakeInstance.setSessionId("fakeSessionId");
     fakeInstance.setHelixVersion("0.6");
-    accessor.setProperty(keyBuilder.liveInstance("fakeInstance"), fakeInstance);
+    accessor.setProperty(keyBuilder.liveInstance(fakeInstanceName), fakeInstance);
     Thread.sleep(1000);
 
     for (Map.Entry<String, DummyCallback> e : callbacks.entrySet()) {
@@ -196,7 +204,7 @@ public class TestDisableCustomCodeRunner extends ZkUnitTestBase {
     }
 
     // Remove fake instance
-    accessor.removeProperty(keyBuilder.liveInstance("fakeInstance"));
+    accessor.removeProperty(keyBuilder.liveInstance(fakeInstanceName));
 
     // Re-enable custom-code runner
     admin.enableResource(clusterName, customCodeRunnerResource, true);
@@ -227,7 +235,7 @@ public class TestDisableCustomCodeRunner extends ZkUnitTestBase {
     }
 
     // Add a fake instance should invoke custom-code runner
-    accessor.setProperty(keyBuilder.liveInstance("fakeInstance"), fakeInstance);
+    accessor.setProperty(keyBuilder.liveInstance(fakeInstanceName), fakeInstance);
     Thread.sleep(1000);
     for (String instance : callbacks.keySet()) {
       DummyCallback callback = callbacks.get(instance);