Return-Path: X-Original-To: apmail-curator-commits-archive@minotaur.apache.org Delivered-To: apmail-curator-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E194E10CD1 for ; Thu, 5 Sep 2013 05:19:46 +0000 (UTC) Received: (qmail 39929 invoked by uid 500); 5 Sep 2013 05:19:46 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 39905 invoked by uid 500); 5 Sep 2013 05:19:45 -0000 Mailing-List: contact commits-help@curator.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.incubator.apache.org Delivered-To: mailing list commits@curator.incubator.apache.org Received: (qmail 39897 invoked by uid 99); 5 Sep 2013 05:19:44 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Sep 2013 05:19:44 +0000 X-ASF-Spam-Status: No, hits=-2002.4 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO mail.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with SMTP; Thu, 05 Sep 2013 05:19:40 +0000 Received: (qmail 39235 invoked by uid 99); 5 Sep 2013 05:19:19 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 05 Sep 2013 05:19:18 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 95CE6900C88; Thu, 5 Sep 2013 05:19:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.incubator.apache.org Message-Id: <4fa36f4311694af1b4bbe3b35113eb6d@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: Callbacks were not called on retry-able errors - this change adds it in Date: Thu, 5 Sep 2013 05:19:18 +0000 (UTC) X-Virus-Checked: Checked by ClamAV on apache.org Updated Branches: refs/heads/CURATOR-52 [created] 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/CURATOR-52 Commit: aa174242c9bdd248d4cc6c6e01dbdc087ec1ac75 Parents: f5b1fd5 Author: randgalt Authored: Wed Sep 4 22:17:50 2013 -0700 Committer: randgalt 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 times = Lists.newArrayList(); - final AtomicLong start = new AtomicLong(System.currentTimeMillis()); + final CountDownLatch latch = new CountDownLatch(TIMES); + final List 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 paths = Lists.newArrayList(); - BackgroundCallback callback = new BackgroundCallback() + final CountDownLatch latch = new CountDownLatch(3); + final List 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(); + } + + } }