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 2017/07/23 02:41:25 UTC

[17/23] curator git commit: testSessionSurvives is a bit flakey. Add a connection state listener to make it less timing dependent

testSessionSurvives is a bit flakey. Add a connection state listener to make it less timing dependent


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

Branch: refs/heads/master
Commit: 9f601cc15fc475eabe96fff2e0a915eadf08f748
Parents: 0f493b9
Author: randgalt <ra...@apache.org>
Authored: Fri Jul 21 22:23:35 2017 -0500
Committer: randgalt <ra...@apache.org>
Committed: Fri Jul 21 22:23:35 2017 -0500

----------------------------------------------------------------------
 .../curator/framework/imps/TestWithCluster.java     | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/9f601cc1/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWithCluster.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWithCluster.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWithCluster.java
index e846020..c8050de 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWithCluster.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestWithCluster.java
@@ -48,6 +48,20 @@ public class TestWithCluster
             client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
             client.start();
 
+            final CountDownLatch reconnectedLatch = new CountDownLatch(1);
+            ConnectionStateListener listener = new ConnectionStateListener()
+            {
+                @Override
+                public void stateChanged(CuratorFramework client, ConnectionState newState)
+                {
+                    if ( newState == ConnectionState.RECONNECTED )
+                    {
+                        reconnectedLatch.countDown();;
+                    }
+                }
+            };
+            client.getConnectionStateListenable().addListener(listener);
+
             client.create().withMode(CreateMode.EPHEMERAL).forPath("/temp", "value".getBytes());
             Assert.assertNotNull(client.checkExists().forPath("/temp"));
 
@@ -59,7 +73,7 @@ public class TestWithCluster
                 timing.sleepABit();
             }
 
-            timing.sleepABit();
+            Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
             Assert.assertNotNull(client.checkExists().forPath("/temp"));
         }
         finally