helix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ka...@apache.org
Subject git commit: [HELIX-399] Make TestConsecutiveZkSessionExpiry less flaky
Date Fri, 07 Mar 2014 19:17:30 GMT
Repository: helix
Updated Branches:
  refs/heads/master bfda7c3dc -> 6bd9fd571


[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/6bd9fd57
Tree: http://git-wip-us.apache.org/repos/asf/helix/tree/6bd9fd57
Diff: http://git-wip-us.apache.org/repos/asf/helix/diff/6bd9fd57

Branch: refs/heads/master
Commit: 6bd9fd571f5bc8768b4273d3bec7de3c50786de2
Parents: bfda7c3
Author: Kanak Biscuitwala <kanak@apache.org>
Authored: Fri Mar 7 10:04:18 2014 -0800
Committer: Kanak Biscuitwala <kanak@apache.org>
Committed: Fri Mar 7 11:17:19 2014 -0800

----------------------------------------------------------------------
 .../java/org/apache/helix/ZkUnitTestBase.java   | 29 ++++++++++++++++++--
 .../manager/TestConsecutiveZkSessionExpiry.java | 19 +++++++++----
 2 files changed, 40 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/helix/blob/6bd9fd57/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 75f23e3..5051db5 100644
--- a/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
+++ b/helix-core/src/test/java/org/apache/helix/ZkUnitTestBase.java
@@ -41,19 +41,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.Message.Attributes;
 import org.apache.helix.model.Message.MessageType;
 import org.apache.helix.model.StateModelDefinition;
-import org.apache.helix.tools.StateModelConfigGenerator;
 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;
@@ -362,6 +362,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/6bd9fd57/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()));
   }
+
 }


Mime
View raw message