This is an automated email from the ASF dual-hosted git repository.

randgalt pushed a commit to branch CURATOR-498
in repository https://gitbox.apache.org/repos/asf/curator.git


The following commit(s) were added to refs/heads/CURATOR-498 by this push:
     new 782448e  CURATOR-498
782448e is described below

commit 782448e798ee8fcbb1a05294fcdfd53c0cda2cbf
Author: randgalt <[email protected]>
AuthorDate: Tue Feb 5 10:11:08 2019 -0500

    CURATOR-498
    
    change to how session expiration is injected introduced flakiness into 
testSessionConnectionStateErrorPolicyWithExpirationPercent30. I've tightened up 
the test.
---
 .../state/TestConnectionStateManager.java          | 32 ++++++++++++++--------
 1 file changed, 21 insertions(+), 11 deletions(-)

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
index 1bc9df3..c929b41 100644
--- 
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
@@ -18,7 +18,6 @@
  */
 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;
@@ -28,8 +27,7 @@ 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.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 public class TestConnectionStateManager extends BaseClassForTests {
@@ -46,12 +44,25 @@ public class TestConnectionStateManager extends 
BaseClassForTests {
             .connectionHandlingPolicy(new StandardConnectionHandlingPolicy(30))
             .build();
 
-        try {
-            final BlockingQueue<String> states = 
Queues.newLinkedBlockingQueue();
-            ConnectionStateListener stateListener = new 
ConnectionStateListener() {
+        // we should get LOST around 30% of a session plus a little "slop" for 
processing, etc.
+        final int lostStateExpectedMs = (timing.session() / 3) + 
timing.forSleepingABit().milliseconds();
+        try
+        {
+            CountDownLatch connectedLatch = new CountDownLatch(1);
+            CountDownLatch lostLatch = new CountDownLatch(1);
+            ConnectionStateListener stateListener = new 
ConnectionStateListener()
+            {
                 @Override
-                public void stateChanged(CuratorFramework client, 
ConnectionState newState) {
-                states.add(newState.name());
+                public void stateChanged(CuratorFramework client, 
ConnectionState newState)
+                {
+                    if ( newState == ConnectionState.CONNECTED )
+                    {
+                        connectedLatch.countDown();
+                    }
+                    if ( newState == ConnectionState.LOST )
+                    {
+                        lostLatch.countDown();
+                    }
                 }
             };
 
@@ -59,11 +70,10 @@ public class TestConnectionStateManager extends 
BaseClassForTests {
 
             client.getConnectionStateListenable().addListener(stateListener);
             client.start();
-            
Assert.assertEquals(states.poll(timing.forWaiting().milliseconds(), 
TimeUnit.MILLISECONDS), ConnectionState.CONNECTED.name());
+            Assert.assertTrue(timing.awaitLatch(connectedLatch));
             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());
+            Assert.assertTrue(lostLatch.await(lostStateExpectedMs, 
TimeUnit.MILLISECONDS));
         }
         finally {
             CloseableUtils.closeQuietly(client);

Reply via email to