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 9DB6A11DA9 for ; Sun, 20 Jul 2014 22:30:26 +0000 (UTC) Received: (qmail 77674 invoked by uid 500); 20 Jul 2014 22:30:24 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 77644 invoked by uid 500); 20 Jul 2014 22:30:24 -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 77633 invoked by uid 99); 20 Jul 2014 22:30:24 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 20 Jul 2014 22:30:24 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 0F87C9A62BC; Sun, 20 Jul 2014 22:30:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: cammckenzie@apache.org To: commits@curator.apache.org Message-Id: <395a54ce285c4e2ab4df6e2979e614e1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: CURATOR-121 - Modified exception handling on the operation queue to ignore InterruptedException during shutdown. Added additional unit test for this case. Date: Sun, 20 Jul 2014 22:30:23 +0000 (UTC) Repository: curator Updated Branches: refs/heads/CURATOR-121 [created] 51109813e CURATOR-121 - Modified exception handling on the operation queue to ignore InterruptedException during shutdown. Added additional unit test for this case. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/51109813 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/51109813 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/51109813 Branch: refs/heads/CURATOR-121 Commit: 51109813ebd3104b74181be26532c3692f41bb02 Parents: c358bbc Author: Cam McKenzie Authored: Sun Jul 20 04:10:32 2014 +1000 Committer: Cam McKenzie Committed: Sun Jul 20 04:10:32 2014 +1000 ---------------------------------------------------------------------- .../recipes/cache/PathChildrenCache.java | 11 ++++- .../recipes/cache/TestPathChildrenCache.java | 46 ++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/51109813/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java index dd41b5f..077cfb3 100644 --- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java +++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/PathChildrenCache.java @@ -745,7 +745,7 @@ public class PathChildrenCache implements Closeable return (uninitializedChildren.size() != 0); } - private void offerOperation(final Operation operation) + void offerOperation(final Operation operation) { if ( operationsQuantizer.add(operation) ) { @@ -761,6 +761,15 @@ public class PathChildrenCache implements Closeable operationsQuantizer.remove(operation); operation.invoke(); } + catch ( InterruptedException e ) + { + //We expect to get interrupted during shutdown, + //so just ignore these events + if ( state.get() != State.CLOSED ) + { + handleException(e); + } + } catch ( Exception e ) { handleException(e); http://git-wip-us.apache.org/repos/asf/curator/blob/51109813/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java index bf57ed8..653a8b1 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestPathChildrenCache.java @@ -841,6 +841,52 @@ public class TestPathChildrenCache extends BaseClassForTests } } + + /** + * Tests the case where there's an outstanding operation being executed when the cache is + * shut down. See CURATOR-121, this was causing misleading warning messages to be logged. + * @throws Exception + */ + @Test + public void testInterruptedOperationOnShutdown() throws Exception + { + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), 30000, 30000, new RetryOneTime(1)); + client.start(); + + try + { + final CountDownLatch latch = new CountDownLatch(1); + final PathChildrenCache cache = new PathChildrenCache(client, "/test", false) { + @Override + protected void handleException(Throwable e) + { + latch.countDown(); + } + }; + cache.start(); + + cache.offerOperation(new Operation() + { + + @Override + public void invoke() throws Exception + { + Thread.sleep(5000); + } + }); + + Thread.sleep(1000); + + cache.close(); + + latch.await(5, TimeUnit.SECONDS); + + Assert.assertTrue(latch.getCount() == 1, "Unexpected exception occurred"); + } finally + { + CloseableUtils.closeQuietly(client); + } + } public static class ExecuteCalledWatchingExecutorService extends DelegatingExecutorService {