You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@helix.apache.org by ka...@apache.org on 2014/03/07 20:15:30 UTC

git commit: [HELIX-399] Make TestConsecutiveZkSessionExpiry less flaky

Repository: helix
Updated Branches:
  refs/heads/helix-0.6.2-release 24eacbc92 -> bee3dde0c


[HELIX-399] Make TestConsecutiveZkSessionExpiry less flaky


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

Branch: refs/heads/helix-0.6.2-release
Commit: bee3dde0c20213a11122f0dc18bb58fb5f96b341
Parents: 24eacbc
Author: Kanak Biscuitwala <ka...@apache.org>
Authored: Fri Mar 7 10:04:18 2014 -0800
Committer: Kanak Biscuitwala <ka...@apache.org>
Committed: Fri Mar 7 11:12:18 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/helix/ZkUnitTestBase.java   | 31 +++++++++++++++++---
 .../manager/TestConsecutiveZkSessionExpiry.java | 19 ++++++++----
 2 files changed, 41 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/bee3dde0/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java b/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
index 0752481..6f467e5 100644
--- a/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
@@ -37,19 +37,19 @@ import org.apache.helix.manager.zk.ZKHelixDataAccessor;
 import org.apache.helix.manager.zk.ZNRecordSerializer;
 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
 import org.apache.helix.manager.zk.ZkClient;
+import org.apache.helix.model.CurrentState;
+import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.HelixConfigScope.ConfigScopeProperty;
 import org.apache.helix.model.IdealState;
 import org.apache.helix.model.IdealState.RebalanceMode;
-import org.apache.helix.model.CurrentState;
-import org.apache.helix.model.ExternalView;
 import org.apache.helix.model.InstanceConfig;
 import org.apache.helix.model.LiveInstance;
 import org.apache.helix.model.Message;
-import org.apache.helix.model.StateModelDefinition;
 import org.apache.helix.model.Message.Attributes;
 import org.apache.helix.model.Message.MessageType;
-import org.apache.helix.tools.StateModelConfigGenerator;
+import org.apache.helix.model.StateModelDefinition;
 import org.apache.helix.tools.ClusterStateVerifier.ZkVerifier;
+import org.apache.helix.tools.StateModelConfigGenerator;
 import org.apache.helix.util.HelixUtil;
 import org.apache.helix.util.ZKClientPool;
 import org.apache.log4j.Logger;
@@ -358,6 +358,29 @@ public class ZkUnitTestBase {
   }
 
   /**
+   * Poll for the existence (or lack thereof) of a specific Helix property
+   * @param clazz the HelixProeprty subclass
+   * @param accessor connected HelixDataAccessor
+   * @param key the property key to look up
+   * @param shouldExist true if the property should exist, false otherwise
+   * @return the property if found, or null if it does not exist
+   */
+  protected <T extends HelixProperty> T pollForProperty(Class<T> clazz, HelixDataAccessor accessor,
+      PropertyKey key, boolean shouldExist) throws InterruptedException {
+    final int POLL_TIMEOUT = 5000;
+    final int POLL_INTERVAL = 50;
+    T property = accessor.getProperty(key);
+    int timeWaited = 0;
+    while (((shouldExist && property == null) || (!shouldExist && property != null))
+        && timeWaited < POLL_TIMEOUT) {
+      Thread.sleep(POLL_INTERVAL);
+      timeWaited += POLL_INTERVAL;
+      property = accessor.getProperty(key);
+    }
+    return property;
+  }
+
+  /**
    * Ensures that external view and current state are empty
    */
   protected static class EmptyZkVerifier implements ZkVerifier {

http://git-wip-us.apache.org/repos/asf/helix/blob/bee3dde0/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
----------------------------------------------------------------------
diff --git a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
index 8625c0c..8bff2fb 100644
--- a/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
+++ b/helix-core/src/test/java/org/apache/helix/integration/manager/TestConsecutiveZkSessionExpiry.java
@@ -23,6 +23,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
 
+import org.apache.helix.HelixDataAccessor;
 import org.apache.helix.PreConnectCallback;
 import org.apache.helix.PropertyKey;
 import org.apache.helix.TestHelper;
@@ -226,11 +227,13 @@ public class TestConsecutiveZkSessionExpiry extends ZkUnitTestBase {
     Assert.assertTrue(result);
 
     // verify leader changes to localhost_12919
-    ZKHelixDataAccessor accessor =
+    HelixDataAccessor accessor =
         new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor<ZNRecord>(_gZkClient));
     PropertyKey.Builder keyBuilder = accessor.keyBuilder();
-    Assert.assertNotNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12918")));
-    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
+    Assert.assertNotNull(pollForProperty(LiveInstance.class, accessor,
+        keyBuilder.liveInstance("localhost_12918"), true));
+    LiveInstance leader =
+        pollForProperty(LiveInstance.class, accessor, keyBuilder.controllerLeader(), true);
     Assert.assertNotNull(leader);
     Assert.assertEquals(leader.getId(), "localhost_12919");
 
@@ -245,10 +248,16 @@ public class TestConsecutiveZkSessionExpiry extends ZkUnitTestBase {
                 + handlers.size());
 
     // clean up
+    distributedControllers[0].disconnect();
     distributedControllers[1].disconnect();
-    Assert.assertNull(accessor.getProperty(keyBuilder.liveInstance("localhost_12919")));
-    Assert.assertNull(accessor.getProperty(keyBuilder.controllerLeader()));
+    Assert.assertNull(pollForProperty(LiveInstance.class, accessor,
+        keyBuilder.liveInstance("localhost_12918"), false));
+    Assert.assertNull(pollForProperty(LiveInstance.class, accessor,
+        keyBuilder.liveInstance("localhost_12919"), false));
+    Assert.assertNull(pollForProperty(LiveInstance.class, accessor, keyBuilder.controllerLeader(),
+        false));
 
     System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
   }
+
 }