curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject git commit: made testRetry() more resilient
Date Sat, 07 Jun 2014 19:40:30 GMT
Repository: curator
Updated Branches:
  refs/heads/master 8880417db -> d3ce45c63


made testRetry() more resilient


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

Branch: refs/heads/master
Commit: d3ce45c637caf1cef7263489eef5889a684cbca7
Parents: 8880417
Author: randgalt <randgalt@apache.org>
Authored: Sat Jun 7 14:38:09 2014 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Sat Jun 7 14:38:09 2014 -0500

----------------------------------------------------------------------
 .../framework/imps/TestFrameworkEdges.java      | 59 +++++++++++---------
 1 file changed, 34 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d3ce45c6/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
index 52897b6..4cc6330 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java
@@ -44,6 +44,7 @@ import org.apache.zookeeper.Watcher;
 import org.apache.zookeeper.data.Stat;
 import org.testng.Assert;
 import org.testng.annotations.Test;
+import java.io.File;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.Semaphore;
@@ -340,6 +341,7 @@ public class TestFrameworkEdges extends BaseClassForTests
     {
         final int MAX_RETRIES = 3;
         final int serverPort = server.getPort();
+        final File tempDirectory = server.getTempDirectory();
 
         final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryOneTime(10));
         client.start();
@@ -347,36 +349,47 @@ public class TestFrameworkEdges extends BaseClassForTests
         {
             final AtomicInteger retries = new AtomicInteger(0);
             final Semaphore semaphore = new Semaphore(0);
-            client.getZookeeperClient().setRetryPolicy
-                (
-                    new RetryPolicy()
+            RetryPolicy policy = new RetryPolicy()
+            {
+                @Override
+                public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper
sleeper)
+                {
+                    semaphore.release();
+                    if ( retries.incrementAndGet() == MAX_RETRIES )
                     {
-                        @Override
-                        public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper
sleeper)
+                        try
                         {
-                            semaphore.release();
-                            if ( retries.incrementAndGet() == MAX_RETRIES )
-                            {
-                                try
-                                {
-                                    server = new TestingServer(serverPort);
-                                }
-                                catch ( Exception e )
-                                {
-                                    throw new Error(e);
-                                }
-                            }
-                            return true;
+                            server = new TestingServer(serverPort, tempDirectory);
+                        }
+                        catch ( Exception e )
+                        {
+                            throw new Error(e);
                         }
                     }
-                );
+                    try
+                    {
+                        sleeper.sleepFor(100, TimeUnit.MILLISECONDS);
+                    }
+                    catch ( InterruptedException e )
+                    {
+                        Thread.currentThread().interrupt();
+                    }
+                    return true;
+                }
+            };
+            client.getZookeeperClient().setRetryPolicy(policy);
 
             server.stop();
 
             // test foreground retry
             client.checkExists().forPath("/hey");
-            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS));
+            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
 
+            // make sure we're reconnected
+            client.getZookeeperClient().setRetryPolicy(new RetryOneTime(100));
+            client.checkExists().forPath("/hey");
+
+            client.getZookeeperClient().setRetryPolicy(policy);
             semaphore.drainPermits();
             retries.set(0);
 
@@ -384,11 +397,7 @@ public class TestFrameworkEdges extends BaseClassForTests
 
             // test background retry
             client.checkExists().inBackground().forPath("/hey");
-            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS));
-        }
-        catch ( Throwable e )
-        {
-            Assert.fail("Error", e);
+            Assert.assertTrue(semaphore.tryAcquire(MAX_RETRIES, timing.forWaiting().seconds(),
TimeUnit.SECONDS), "Remaining leases: " + semaphore.availablePermits());
         }
         finally
         {


Mime
View raw message