You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ca...@apache.org on 2018/04/12 01:56:02 UTC
[3/6] curator git commit: CURATOR-460 Move test from TestLeaderLatch
to TestConnectionStateManager
CURATOR-460 Move test from TestLeaderLatch to TestConnectionStateManager
Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/0a5b29d5
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/0a5b29d5
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/0a5b29d5
Branch: refs/heads/CURATOR-460
Commit: 0a5b29d588800d7eeabf66f23ea2e3ad0fa0416c
Parents: 6e85467
Author: javando <an...@gmail.com>
Authored: Wed Apr 4 23:10:12 2018 -0300
Committer: javando <an...@gmail.com>
Committed: Wed Apr 4 23:10:12 2018 -0300
----------------------------------------------------------------------
.../state/TestConnectionStateManager.java | 54 ++++++++++++++++++++
.../recipes/leader/TestLeaderLatch.java | 30 -----------
2 files changed, 54 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/curator/blob/0a5b29d5/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java b/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
new file mode 100644
index 0000000..e313c56
--- /dev/null
+++ b/curator-framework/src/test/java/org/apache/curator/framework/state/TestConnectionStateManager.java
@@ -0,0 +1,54 @@
+package org.apache.curator.framework.state;
+
+import com.google.common.collect.Queues;
+import org.apache.curator.connection.StandardConnectionHandlingPolicy;
+import org.apache.curator.framework.CuratorFramework;
+import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.retry.RetryOneTime;
+import org.apache.curator.test.BaseClassForTests;
+import org.apache.curator.test.compatibility.Timing2;
+import org.apache.curator.utils.CloseableUtils;
+import org.testng.Assert;
+import org.testng.annotations.Test;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+public class TestConnectionStateManager extends BaseClassForTests {
+
+ @Test
+ public void testSessionConnectionStateErrorPolicyWithExpirationPercent30() throws Exception {
+ Timing2 timing = new Timing2();
+ CuratorFramework client = CuratorFrameworkFactory.builder()
+ .connectString(server.getConnectString())
+ .connectionTimeoutMs(1000)
+ .sessionTimeoutMs(timing.session())
+ .retryPolicy(new RetryOneTime(1))
+ .connectionStateErrorPolicy(new SessionConnectionStateErrorPolicy())
+ .connectionHandlingPolicy(new StandardConnectionHandlingPolicy(30))
+ .build();
+
+ try {
+ final BlockingQueue<String> states = Queues.newLinkedBlockingQueue();
+ ConnectionStateListener stateListener = new ConnectionStateListener() {
+ @Override
+ public void stateChanged(CuratorFramework client, ConnectionState newState) {
+ states.add(newState.name());
+ }
+ };
+
+ timing.sleepABit();
+
+ client.getConnectionStateListenable().addListener(stateListener);
+ client.start();
+ Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.CONNECTED.name());
+ server.close();
+
+ Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.SUSPENDED.name());
+ Assert.assertEquals(states.poll(timing.session() / 3, TimeUnit.MILLISECONDS), ConnectionState.LOST.name());
+ }
+ finally {
+ CloseableUtils.closeQuietly(client);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/curator/blob/0a5b29d5/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
index af1475d..011e4a0 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/leader/TestLeaderLatch.java
@@ -23,7 +23,6 @@ import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.collect.Queues;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
-import org.apache.curator.connection.StandardConnectionHandlingPolicy;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.imps.TestCleanState;
@@ -223,35 +222,6 @@ public class TestLeaderLatch extends BaseClassForTests
next.add(states.poll(timing.forSessionSleep().milliseconds(), TimeUnit.MILLISECONDS));
next.add(states.poll(timing.forSessionSleep().milliseconds(), TimeUnit.MILLISECONDS));
Assert.assertTrue(next.equals(Arrays.asList(ConnectionState.LOST.name(), "false")) || next.equals(Arrays.asList("false", ConnectionState.LOST.name())), next.toString());
-
- latch.close();
- client.close();
-
- timing.sleepABit();
- states.clear();
- server = new TestingServer();
- client = CuratorFrameworkFactory.builder()
- .connectString(server.getConnectString())
- .connectionTimeoutMs(1000)
- .sessionTimeoutMs(timing.session())
- .retryPolicy(new RetryOneTime(1))
- .connectionStateErrorPolicy(new SessionConnectionStateErrorPolicy())
- .connectionHandlingPolicy(new StandardConnectionHandlingPolicy(30))
- .build();
- client.getConnectionStateListenable().addListener(stateListener);
- client.start();
- latch = new LeaderLatch(client, "/test");
- latch.addListener(listener);
- latch.start();
- Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.CONNECTED.name());
- Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS), "true");
- server.close();
- Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.SUSPENDED.name());
- next = Lists.newArrayList();
-
- next.add(states.poll(timing.session() / 3, TimeUnit.MILLISECONDS));
- next.add(states.poll(timing.forSleepingABit().milliseconds(), TimeUnit.MILLISECONDS));
- Assert.assertTrue(next.equals(Arrays.asList(ConnectionState.LOST.name(), "false")) || next.equals(Arrays.asList("false", ConnectionState.LOST.name())), next.toString());
}
finally
{