helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-471] Unregister ResourceMonitor on drop, reduce test flakiness
Date Wed, 16 Jul 2014 20:34:53 GMT
Repository: helix
Updated Branches:
  refs/heads/master f952cb760 -> e5e3a7d42


[HELIX-471] Unregister ResourceMonitor on drop, reduce test flakiness


Project: http://git-wip-us.apache.org/repos/asf/helix/repo
Commit: http://git-wip-us.apache.org/repos/asf/helix/commit/e5e3a7d4
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/e5e3a7d4
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/e5e3a7d4

Branch: refs/heads/master
Commit: e5e3a7d42e3f5b5f350bde91b12639a4795ccec5
Parents: f952cb7
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Wed Jul 16 13:34:20 2014 -0700
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Wed Jul 16 13:34:20 2014 -0700

----------------------------------------------------------------------
 .../mbeans/TestDropResourceMetricsReset.java    | 49 +++++++++++++++++---
 1 file changed, 42 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/e5e3a7d4/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
index 7c4a094..17d45de 100644
--- a/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
+++ b/helix-core/src/test/java/org/apache/helix/monitoring/mbeans/TestDropResourceMetricsReset.java
@@ -19,10 +19,14 @@ package org.apache.helix.monitoring.mbeans;
  * under the License.
  */
 
-import java.lang.management.ManagementFactory;
+import java.io.IOException;
 import java.util.Date;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 
+import javax.management.InstanceNotFoundException;
 import javax.management.MBeanServerConnection;
+import javax.management.MBeanServerNotification;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -36,7 +40,8 @@ import org.testng.Assert;
 import org.testng.annotations.Test;
 
 public class TestDropResourceMetricsReset extends ZkUnitTestBase {
-  private static final MBeanServerConnection SERVER = ManagementFactory.getPlatformMBeanServer();
+  private final CountDownLatch _registerLatch = new CountDownLatch(1);
+  private final CountDownLatch _unregisterLatch = new CountDownLatch(1);
 
   @Test
   public void testBasic() throws Exception {
@@ -50,6 +55,9 @@ public class TestDropResourceMetricsReset extends ZkUnitTestBase {
     String clusterName = className + "_" + methodName;
     System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
 
+    ParticipantMonitorListener listener =
+        new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);
+
     // Set up cluster
     TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
         "localhost", // participant name prefix
@@ -74,18 +82,18 @@ public class TestDropResourceMetricsReset extends ZkUnitTestBase {
     controller.syncStart();
 
     // Verify that the bean was created
-    Thread.sleep(2000);
-    ObjectName objectName = getObjectName(RESOURCE_NAME, clusterName);
-    Assert.assertTrue(SERVER.isRegistered(objectName));
+    boolean noTimeout = _registerLatch.await(30000, TimeUnit.MILLISECONDS);
+    Assert.assertTrue(noTimeout);
 
     // Drop the resource
     setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);
 
     // Verify that the bean was removed
-    Thread.sleep(2000);
-    Assert.assertFalse(SERVER.isRegistered(objectName));
+    noTimeout = _unregisterLatch.await(30000, TimeUnit.MILLISECONDS);
+    Assert.assertTrue(noTimeout);
 
     // Clean up
+    listener.disconnect();
     controller.syncStop();
     for (MockParticipantManager participant : participants) {
       participant.syncStop();
@@ -103,4 +111,31 @@ public class TestDropResourceMetricsReset extends ZkUnitTestBase {
     return new ObjectName(String.format("%s: %s", ClusterStatusMonitor.CLUSTER_STATUS_KEY,
         resourceBeanName));
   }
+
+  private class ParticipantMonitorListener extends ClusterMBeanObserver {
+    private final ObjectName _objectName;
+
+    public ParticipantMonitorListener(String domain, String cluster, String resource)
+        throws InstanceNotFoundException, IOException, MalformedObjectNameException,
+        NullPointerException {
+      super(domain);
+      _objectName = getObjectName(resource, cluster);
+    }
+
+    @Override
+    public void onMBeanRegistered(MBeanServerConnection server,
+        MBeanServerNotification mbsNotification) {
+      if (mbsNotification.getMBeanName().equals(_objectName)) {
+        _registerLatch.countDown();
+      }
+    }
+
+    @Override
+    public void onMBeanUnRegistered(MBeanServerConnection server,
+        MBeanServerNotification mbsNotification) {
+      if (mbsNotification.getMBeanName().equals(_objectName)) {
+        _unregisterLatch.countDown();
+      }
+    }
+  }
 }


Mime
View raw message