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 DC61717F1C for ; Wed, 20 May 2015 00:53:10 +0000 (UTC) Received: (qmail 94406 invoked by uid 500); 20 May 2015 00:53:10 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 94328 invoked by uid 500); 20 May 2015 00:53:10 -0000 Mailing-List: contact commits-help@curator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@curator.apache.org Delivered-To: mailing list commits@curator.apache.org Received: (qmail 94302 invoked by uid 99); 20 May 2015 00:53:10 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 20 May 2015 00:53:10 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 9268BE3D34; Wed, 20 May 2015 00:53:10 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: randgalt@apache.org To: commits@curator.apache.org Date: Wed, 20 May 2015 00:53:12 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [3/7] curator git commit: CURATOR-161 - Some progress in getting locally() to work. Working now for the foreground case, but still not working for the background case because it tries to guarantee a connection before the command is executed. CURATOR-161 - Some progress in getting locally() to work. Working now for the foreground case, but still not working for the background case because it tries to guarantee a connection before the command is executed. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/04caf36c Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/04caf36c Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/04caf36c Branch: refs/heads/CURATOR-217 Commit: 04caf36cd4ee76b358c7866da18c858b5608ebca Parents: 389e0b0 Author: Cameron McKenzie Authored: Tue May 12 07:46:43 2015 +1000 Committer: Cameron McKenzie Committed: Tue May 12 07:46:43 2015 +1000 ---------------------------------------------------------------------- .../framework/api/RemoveWatchesLocal.java | 2 +- .../imps/RemoveWatchesBuilderImpl.java | 62 ++++++++++++-------- .../framework/imps/TestRemoveWatches.java | 42 +++++++++++-- 3 files changed, 77 insertions(+), 29 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/04caf36c/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java index 3769d1f..e002857 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/api/RemoveWatchesLocal.java @@ -9,7 +9,7 @@ public interface RemoveWatchesLocal extends BackgroundPathableQuietly /** * Specify if the client should just remove client side watches if a connection to ZK - * is not available. + * is not available. Note that the standard Curator retry loop will not be used in t * @return */ public BackgroundPathableQuietly locally(); http://git-wip-us.apache.org/repos/asf/curator/blob/04caf36c/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java index 5a34f7d..c9868f4 100644 --- a/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java +++ b/curator-framework/src/main/java/org/apache/curator/framework/imps/RemoveWatchesBuilderImpl.java @@ -151,36 +151,52 @@ public class RemoveWatchesBuilderImpl implements RemoveWatchesBuilder, RemoveWat private void pathInForeground(final String path) throws Exception { - RetryLoop.callWithRetry(client.getZookeeperClient(), - new Callable() - { - @Override - public Void call() throws Exception + if(local) + { + ZooKeeper zkClient = client.getZooKeeper(); + if(watcher == null) + { + zkClient.removeAllWatches(path, watcherType, local); + } + else + { + zkClient.removeWatches(path, watcher, watcherType, local); + } + } + else + { + RetryLoop.callWithRetry(client.getZookeeperClient(), + new Callable() { - try + @Override + public Void call() throws Exception { - ZooKeeper zkClient = client.getZooKeeper(); - if(watcher == null) + try { - zkClient.removeAllWatches(path, watcherType, local); + ZooKeeper zkClient = client.getZookeeperClient().getZooKeeper(); + + if(watcher == null) + { + zkClient.removeAllWatches(path, watcherType, local); + } + else + { + zkClient.removeWatches(path, watcher, watcherType, local); + } } - else + catch(KeeperException.NoWatcherException e) { - zkClient.removeWatches(path, watcher, watcherType, local); + //Swallow this exception if the quietly flag is set, otherwise rethrow. + if(!quietly) + { + throw e; + } } - } - catch(KeeperException.NoWatcherException e) - { - //Swallow this exception if the quietly flag is set, otherwise rethrow. - if(!quietly) - { - throw e; - } - } - return null; - } - }); + return null; + } + }); + } } @Override http://git-wip-us.apache.org/repos/asf/curator/blob/04caf36c/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java index 414c819..0912c70 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestRemoveWatches.java @@ -20,6 +20,8 @@ import org.apache.zookeeper.WatchedEvent; import org.apache.zookeeper.Watcher; import org.apache.zookeeper.Watcher.Event.EventType; import org.apache.zookeeper.Watcher.WatcherType; +import org.apache.zookeeper.ZooKeeper; +import org.apache.zookeeper.data.Stat; import org.testng.Assert; import org.testng.annotations.Test; @@ -302,10 +304,6 @@ public class TestRemoveWatches extends BaseClassForTests } } - /** - * TODO: THIS IS STILL A WORK IN PROGRESS. local() is currently broken if no connection to ZK is available. - * @throws Exception - */ @Test public void testRemoveLocalWatch() throws Exception { Timing timing = new Timing(); @@ -329,7 +327,7 @@ public class TestRemoveWatches extends BaseClassForTests server.stop(); timing.sleepABit(); - + client.watches().removeAll().locally().forPath(path); Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); @@ -340,6 +338,40 @@ public class TestRemoveWatches extends BaseClassForTests } } + @Test + public void testRemoveLocalWatchInBackground() throws Exception { + Timing timing = new Timing(); + CuratorFramework client = CuratorFrameworkFactory.builder(). + connectString(server.getConnectString()). + retryPolicy(new RetryOneTime(1)). + build(); + try + { + client.start(); + + final String path = "/"; + + final CountDownLatch removedLatch = new CountDownLatch(1); + + Watcher watcher = new CountDownWatcher(path, removedLatch, EventType.DataWatchRemoved); + + client.checkExists().usingWatcher(watcher).forPath(path); + + //Stop the server so we can check if we can remove watches locally when offline + server.stop(); + + timing.sleepABit(); + + client.watches().removeAll().locally().inBackground().forPath(path); + + Assert.assertTrue(timing.awaitLatch(removedLatch), "Timed out waiting for watch removal"); + } + finally + { + CloseableUtils.closeQuietly(client); + } + } + /** * Test the case where we try and remove an unregistered watcher. In this case we expect a NoWatcherException to * be thrown.