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 8D91E1169B for ; Tue, 29 Jul 2014 00:16:11 +0000 (UTC) Received: (qmail 9256 invoked by uid 500); 29 Jul 2014 00:16:11 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 9225 invoked by uid 500); 29 Jul 2014 00:16:11 -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 9216 invoked by uid 99); 29 Jul 2014 00:16:11 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Jul 2014 00:16:11 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 237D39B91AE; Tue, 29 Jul 2014 00:16:11 +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: Tue, 29 Jul 2014 00:16:10 -0000 Message-Id: In-Reply-To: <02c86d6ef1eb4008a043a748ec145f5e@git.apache.org> References: <02c86d6ef1eb4008a043a748ec145f5e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [2/3] git commit: CURATOR-126 - Added a unit test to reproduce this case. CURATOR-126 - Added a unit test to reproduce this case. Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/a8a3e147 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/a8a3e147 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/a8a3e147 Branch: refs/heads/master Commit: a8a3e14755ea69aaa186a40e67173ad7b686d9e3 Parents: 785e9f6 Author: Cameron McKenzie Authored: Tue Jul 29 09:28:14 2014 +1000 Committer: Cameron McKenzie Committed: Tue Jul 29 09:28:14 2014 +1000 ---------------------------------------------------------------------- .../framework/imps/TestFrameworkBackground.java | 86 ++++++++++++++++++++ 1 file changed, 86 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/a8a3e147/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 44792d9..f9fea4f 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 @@ -20,12 +20,15 @@ package org.apache.curator.framework.imps; import com.google.common.collect.Lists; + import org.apache.curator.test.BaseClassForTests; import org.apache.curator.utils.CloseableUtils; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.api.BackgroundCallback; import org.apache.curator.framework.api.CuratorEvent; +import org.apache.curator.framework.api.UnhandledErrorListener; +import org.apache.curator.framework.imps.OperationAndData.ErrorCallback; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.curator.retry.RetryNTimes; @@ -35,10 +38,12 @@ 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.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -215,4 +220,85 @@ public class TestFrameworkBackground extends BaseClassForTests } } + + /** + * CURATOR-126 + * Shutdown the Curator client while there are still background operations running. + */ + @Test + public void testShutdown() throws Exception + { + final int MAX_CLOSE_WAIT_MS = 5000; + Timing timing = new Timing(); + CuratorFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).sessionTimeoutMs(timing.session()). + connectionTimeoutMs(timing.connection()).retryPolicy(new RetryOneTime(1)).maxCloseWaitMs(MAX_CLOSE_WAIT_MS).build(); + try + { + client.start(); + + BackgroundCallback callback = new BackgroundCallback() + { + @Override + public void processResult(CuratorFramework client, CuratorEvent event) throws Exception + { + } + }; + + final CountDownLatch operationReadyLatch = new CountDownLatch(1); + + //This gets called just before the operation is run. + ((CuratorFrameworkImpl)client).debugListener = new CuratorFrameworkImpl.DebugBackgroundListener() + { + @Override + public void listen(OperationAndData data) + { + operationReadyLatch.countDown(); + + try { + Thread.sleep(MAX_CLOSE_WAIT_MS / 2); + } catch(InterruptedException e) { + } + } + }; + + Assert.assertTrue(client.getZookeeperClient().blockUntilConnectedOrTimedOut(), "Failed to connect"); + + server.stop(); + + BackgroundOperation background = new BackgroundOperation() + { + + @Override + public void performBackgroundOperation(OperationAndData data) + throws Exception + { + } + }; + + ErrorCallback errorCallback = new ErrorCallback() + { + + @Override + public void retriesExhausted( + OperationAndData operationAndData) + { + } + }; + + OperationAndData operation = new OperationAndData(background, + "thedata", callback, errorCallback, null); + + ((CuratorFrameworkImpl)client).queueOperation(operation); + + operationReadyLatch.await(); + + client.close(); + } + finally + { + CloseableUtils.closeQuietly(client); + } + } + + }