curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject [2/8] curator git commit: New injectSessionExpiration() operates much faster than previously. It exposes an assumption in the tests. Added a debug hook to work around
Date Mon, 07 Sep 2015 06:51:37 GMT
New injectSessionExpiration() operates much faster than previously. It exposes an assumption
in the tests. Added a debug hook to work around


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

Branch: refs/heads/CURATOR-248
Commit: 145da217ff35df0178823da784f4dd1618851c5e
Parents: d1b4cbf
Author: randgalt <randgalt@apache.org>
Authored: Fri Aug 28 13:39:54 2015 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Fri Aug 28 13:39:54 2015 -0500

----------------------------------------------------------------------
 .../recipes/nodes/PersistentEphemeralNode.java     | 16 ++++++++++++++++
 .../recipes/nodes/TestPersistentEphemeralNode.java | 17 +++++++++--------
 2 files changed, 25 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/145da217/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
index 0b482ef..e889bd8 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/nodes/PersistentEphemeralNode.java
@@ -19,6 +19,7 @@
 
 package org.apache.curator.framework.recipes.nodes;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 
 import org.apache.curator.framework.CuratorFramework;
@@ -111,11 +112,26 @@ public class PersistentEphemeralNode implements Closeable
         {
             if ( newState == ConnectionState.RECONNECTED )
             {
+                if ( debugReconnectLatch != null )
+                {
+                    try
+                    {
+                        debugReconnectLatch.await();
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                        e.printStackTrace();
+                    }
+                }
                 createNode();
             }
         }
     };
 
+    @VisibleForTesting
+    volatile CountDownLatch debugReconnectLatch = null;
+
     private enum State
     {
         LATENT,

http://git-wip-us.apache.org/repos/asf/curator/blob/145da217/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
index c81cc65..3a0d564 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
@@ -297,6 +297,7 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
         CuratorFramework observer = newCurator();
 
         PersistentEphemeralNode node = new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.EPHEMERAL,
PATH, new byte[0]);
+        node.debugReconnectLatch = new CountDownLatch(1);
         node.start();
         try
         {
@@ -307,10 +308,11 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             Trigger deletedTrigger = Trigger.deleted();
             observer.checkExists().usingWatcher(deletedTrigger).forPath(node.getActualPath());
 
-            killSession(curator);
+            KillSession.kill(curator.getZookeeperClient().getZooKeeper());
 
             // Make sure the node got deleted
             assertTrue(deletedTrigger.firedWithin(timing.forWaiting().seconds(), TimeUnit.SECONDS));
+            node.debugReconnectLatch.countDown();
         }
         finally
         {
@@ -325,6 +327,7 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
         CuratorFramework observer = newCurator();
 
         PersistentEphemeralNode node = new PersistentEphemeralNode(curator, PersistentEphemeralNode.Mode.EPHEMERAL,
PATH, new byte[0]);
+        node.debugReconnectLatch = new CountDownLatch(1);
         node.start();
         try
         {
@@ -334,10 +337,11 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             Trigger deletedTrigger = Trigger.deleted();
             observer.checkExists().usingWatcher(deletedTrigger).forPath(node.getActualPath());
 
-            killSession(curator);
+            KillSession.kill(curator.getZookeeperClient().getZooKeeper());
 
             // Make sure the node got deleted...
             assertTrue(deletedTrigger.firedWithin(timing.forWaiting().seconds(), TimeUnit.SECONDS));
+            node.debugReconnectLatch.countDown();
 
             // Check for it to be recreated...
             Trigger createdTrigger = Trigger.created();
@@ -367,14 +371,16 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             // We should be able to disconnect multiple times and each time the node should
be recreated.
             for ( int i = 0; i < 5; i++ )
             {
+                node.debugReconnectLatch = new CountDownLatch(1);
                 Trigger deletionTrigger = Trigger.deleted();
                 observer.checkExists().usingWatcher(deletionTrigger).forPath(path);
 
                 // Kill the session, thus cleaning up the node...
-                killSession(curator);
+                KillSession.kill(curator.getZookeeperClient().getZooKeeper());
 
                 // Make sure the node ended up getting deleted...
                 assertTrue(deletionTrigger.firedWithin(timing.forWaiting().seconds(), TimeUnit.SECONDS));
+                node.debugReconnectLatch.countDown();
 
                 // Now put a watch in the background looking to see if it gets created...
                 Trigger creationTrigger = Trigger.created();
@@ -634,11 +640,6 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
         return client;
     }
 
-    public void killSession(CuratorFramework curator) throws Exception
-    {
-        KillSession.kill(curator.getZookeeperClient().getZooKeeper(), curator.getZookeeperClient().getCurrentConnectionString());
-    }
-
     private static final class Trigger implements Watcher
     {
         private final Event.EventType type;


Mime
View raw message