curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject git commit: Callbacks were not called on retry-able errors - this change adds it in
Date Thu, 05 Sep 2013 05:19:38 GMT
Updated Branches:
  refs/heads/master f5b1fd589 -> aa174242c


Callbacks were not called on retry-able errors - this change adds it in


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

Branch: refs/heads/master
Commit: aa174242c9bdd248d4cc6c6e01dbdc087ec1ac75
Parents: f5b1fd5
Author: randgalt <randgalt@apache.org>
Authored: Wed Sep 4 22:17:50 2013 -0700
Committer: randgalt <randgalt@apache.org>
Committed: Wed Sep 4 22:17:50 2013 -0700

----------------------------------------------------------------------
 .../framework/imps/CuratorFrameworkImpl.java    |  5 ++
 .../framework/imps/TestFrameworkBackground.java | 70 ++++++++++++++++----
 2 files changed, 63 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/aa174242/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
index c3b0992..146103c 100644
--- a/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
+++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java
@@ -485,6 +485,11 @@ public class CuratorFrameworkImpl implements CuratorFramework
                     {
                         operationAndData.getErrorCallback().retriesExhausted(operationAndData);
                     }
+                    
+                    if ( operationAndData.getCallback() != null )
+                    {
+                        sendToBackgroundCallback(operationAndData, event);
+                    }
 
                     KeeperException.Code    code = KeeperException.Code.get(event.getResultCode());
                     Exception               e = null;

http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/aa174242/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkBackground.java
----------------------------------------------------------------------
diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkBackground.java
b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkBackground.java
index 2e0bb3e..8527a14 100644
--- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkBackground.java
+++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkBackground.java
@@ -16,6 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.curator.framework.imps;
 
 import com.google.common.collect.Lists;
@@ -27,31 +28,33 @@ import org.apache.curator.framework.api.CuratorEvent;
 import org.apache.curator.retry.RetryNTimes;
 import org.apache.curator.retry.RetryOneTime;
 import org.apache.curator.test.Timing;
+import org.apache.zookeeper.KeeperException.Code;
 import org.testng.Assert;
 import org.testng.annotations.Test;
 import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 
 public class TestFrameworkBackground extends BaseClassForTests
 {
     @Test
-    public void         testRetries() throws Exception
+    public void testRetries() throws Exception
     {
         final int SLEEP = 1000;
         final int TIMES = 5;
 
-        Timing                  timing = new Timing();
-        CuratorFramework    client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryNTimes(TIMES, SLEEP));
+        Timing timing = new Timing();
+        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryNTimes(TIMES, SLEEP));
         try
         {
             client.start();
             client.getZookeeperClient().blockUntilConnectedOrTimedOut();
 
-            final CountDownLatch    latch = new CountDownLatch(TIMES);
-            final List<Long>        times = Lists.newArrayList();
-            final AtomicLong        start = new AtomicLong(System.currentTimeMillis());
+            final CountDownLatch latch = new CountDownLatch(TIMES);
+            final List<Long> times = Lists.newArrayList();
+            final AtomicLong start = new AtomicLong(System.currentTimeMillis());
             ((CuratorFrameworkImpl)client).debugListener = new CuratorFrameworkImpl.DebugBackgroundListener()
             {
                 @Override
@@ -84,17 +87,17 @@ public class TestFrameworkBackground extends BaseClassForTests
     }
 
     @Test
-    public void         testBasic() throws Exception
+    public void testBasic() throws Exception
     {
-        Timing              timing = new Timing();
-        CuratorFramework    client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryOneTime(1));
+        Timing timing = new Timing();
+        CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryOneTime(1));
         try
         {
             client.start();
 
-            final CountDownLatch    latch = new CountDownLatch(3);
-            final List<String>      paths = Lists.newArrayList();
-            BackgroundCallback      callback = new BackgroundCallback()
+            final CountDownLatch latch = new CountDownLatch(3);
+            final List<String> paths = Lists.newArrayList();
+            BackgroundCallback callback = new BackgroundCallback()
             {
                 @Override
                 public void processResult(CuratorFramework client, CuratorEvent event) throws
Exception
@@ -116,4 +119,47 @@ public class TestFrameworkBackground extends BaseClassForTests
             Closeables.closeQuietly(client);
         }
     }
+
+    /**
+     * Attempt a background operation while Zookeeper server is down.
+     * Return code must be {@link Code#CONNECTIONLOSS}
+     */
+    @Test
+    public void testCuratorCallbackOnError() throws Exception
+    {
+
+        CuratorFramework client = CuratorFrameworkFactory.builder()
+            .connectString(server.getConnectString())
+            .sessionTimeoutMs(60000)
+            .retryPolicy(new RetryNTimes(1, 1000)).build();
+        final CountDownLatch latch = new CountDownLatch(1);
+        try
+        {
+            client.start();
+            BackgroundCallback curatorCallback = new BackgroundCallback()
+            {
+
+                @Override
+                public void processResult(CuratorFramework client, CuratorEvent event)
+                    throws Exception
+                {
+                    if ( event.getResultCode() == Code.CONNECTIONLOSS.intValue() )
+                    {
+                        latch.countDown();
+                    }
+                }
+            };
+            // Stop the Zookeeper server
+            server.stop();
+            // Attempt to retrieve children list
+            client.getChildren().inBackground(curatorCallback).forPath("/");
+            // Check if the callback has been called with a correct return code
+            Assert.assertTrue(latch.await(10, TimeUnit.SECONDS), "Callback has not been called
by curator !");
+        }
+        finally
+        {
+            client.close();
+        }
+
+    }
 }


Mime
View raw message