You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ra...@apache.org on 2013/11/10 03:57:39 UTC
git commit: PersistentEphemeralNode was trying to be too clever about
when createNode() should be called. There's no harm in calling it whenever
there's an interesting event. It also works around connection instability
issues
Updated Branches:
refs/heads/CURATOR-53-2 [created] cb1a80938
PersistentEphemeralNode was trying to be too clever about when createNode() should be called. There's no harm in calling it whenever there's an interesting event. It also works around connection instability issues
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/cb1a8093
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/cb1a8093
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/cb1a8093
Branch: refs/heads/CURATOR-53-2
Commit: cb1a80938cacccbfb87aa2ced35ad2fb07f06207
Parents: f836c7a
Author: randgalt <ra...@apache.org>
Authored: Sat Nov 9 18:56:57 2013 -0800
Committer: randgalt <ra...@apache.org>
Committed: Sat Nov 9 18:56:57 2013 -0800
----------------------------------------------------------------------
.../recipes/nodes/PersistentEphemeralNode.java | 11 +----
.../nodes/TestPersistentEphemeralNode.java | 51 ++++++++++++++++++++
2 files changed, 53 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/cb1a8093/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 053965b..60b43c8 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,7 +19,6 @@
package org.apache.curator.framework.recipes.nodes;
-import com.google.common.base.Objects;
import com.google.common.base.Preconditions;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.api.ACLBackgroundPathAndBytesable;
@@ -68,10 +67,7 @@ public class PersistentEphemeralNode implements Closeable
@Override
public void process(WatchedEvent event)
{
- if ( Objects.equal(nodePath.get(), event.getPath()) )
- {
- createNode();
- }
+ createNode();
}
};
private final ConnectionStateListener listener = new ConnectionStateListener()
@@ -79,10 +75,7 @@ public class PersistentEphemeralNode implements Closeable
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState)
{
- if ( newState == ConnectionState.RECONNECTED )
- {
- createNode();
- }
+ createNode();
}
};
private final BackgroundCallback checkExistsCallback = new BackgroundCallback()
http://git-wip-us.apache.org/repos/asf/curator/blob/cb1a8093/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 767afb0..0b11d8e 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
@@ -30,6 +30,7 @@ import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.KillSession;
import org.apache.curator.test.TestingServer;
import org.apache.curator.test.Timing;
+import org.apache.curator.utils.DebugUtils;
import org.apache.curator.utils.ZKPaths;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
@@ -71,6 +72,56 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
}
@Test
+ public void testListenersReconnectedIsFast() throws Exception
+ {
+ System.setProperty(DebugUtils.PROPERTY_LOG_EVENTS, "true");
+
+ server.close();
+
+ Timing timing = new Timing();
+ CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
+ try
+ {
+ client.start();
+ PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes());
+ node.start();
+
+ final CountDownLatch connectedLatch = new CountDownLatch(1);
+ final CountDownLatch reconnectedLatch = new CountDownLatch(1);
+ ConnectionStateListener listener = new ConnectionStateListener()
+ {
+ @Override
+ public void stateChanged(CuratorFramework client, ConnectionState newState)
+ {
+ if ( newState == ConnectionState.CONNECTED )
+ {
+ connectedLatch.countDown();
+ }
+ if ( newState == ConnectionState.RECONNECTED )
+ {
+ reconnectedLatch.countDown();
+ }
+ }
+ };
+ client.getConnectionStateListenable().addListener(listener);
+ timing.sleepABit();
+ server = new TestingServer(server.getPort());
+ Assert.assertTrue(timing.awaitLatch(connectedLatch));
+ timing.sleepABit();
+ Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS));
+ server.close();
+ timing.sleepABit();
+ server = new TestingServer(server.getPort());
+ timing.sleepABit();
+ Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
+ }
+ finally
+ {
+ Closeables.closeQuietly(client);
+ }
+ }
+
+ @Test
public void testNoServerAtStart() throws Exception
{
server.close();