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 1D45E101CE for ; Tue, 24 Sep 2013 01:55:00 +0000 (UTC) Received: (qmail 88513 invoked by uid 500); 24 Sep 2013 01:55:00 -0000 Delivered-To: apmail-curator-commits-archive@curator.apache.org Received: (qmail 88484 invoked by uid 500); 24 Sep 2013 01:55:00 -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 88477 invoked by uid 99); 24 Sep 2013 01:55:00 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 24 Sep 2013 01:55:00 +0000 X-ASF-Spam-Status: No, hits=-2002.3 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; Tue, 24 Sep 2013 01:54:58 +0000 Received: (qmail 88080 invoked by uid 99); 24 Sep 2013 01:54:38 -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, 24 Sep 2013 01:54:38 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 06831907E26; Tue, 24 Sep 2013 01:54:37 +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 Date: Tue, 24 Sep 2013 01:54:37 -0000 Message-Id: <699924b5456e41f486da36b36c19b84b@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/4] git commit: Added test from user Michael Morello that exposes major retry hole in background operations. The getZooKeeper() method is not retried X-Virus-Checked: Checked by ClamAV on apache.org Updated Branches: refs/heads/master 38a29687f -> 695837099 Added test from user Michael Morello that exposes major retry hole in background operations. The getZooKeeper() method is not retried Project: http://git-wip-us.apache.org/repos/asf/incubator-curator/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-curator/commit/6d7f726b Tree: http://git-wip-us.apache.org/repos/asf/incubator-curator/tree/6d7f726b Diff: http://git-wip-us.apache.org/repos/asf/incubator-curator/diff/6d7f726b Branch: refs/heads/master Commit: 6d7f726bea4919562cf521d48a105f4ffc23c30b Parents: aa17424 Author: jordan.zimmerman Authored: Tue Sep 10 15:11:33 2013 -0500 Committer: jordan.zimmerman Committed: Tue Sep 10 15:11:33 2013 -0500 ---------------------------------------------------------------------- .../framework/imps/TestFrameworkEdges.java | 178 +++++++++++-------- 1 file changed, 104 insertions(+), 74 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-curator/blob/6d7f726b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java index 35d67b3..25ddf04 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestFrameworkEdges.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.Queues; @@ -52,16 +53,45 @@ import java.util.concurrent.atomic.AtomicInteger; public class TestFrameworkEdges extends BaseClassForTests { @Test - public void testReconnectAfterLoss() throws Exception + public void connectionLossWithBackgroundTest() 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(), 1, new RetryOneTime(1)); + try + { + final CountDownLatch latch = new CountDownLatch(1); + client.start(); + client.getZookeeperClient().blockUntilConnectedOrTimedOut(); + server.close(); + client.getChildren().inBackground + ( + new BackgroundCallback() + { + public void processResult(CuratorFramework client, CuratorEvent event) throws Exception + { + latch.countDown(); + } + } + ).forPath("/"); + Assert.assertTrue(timing.awaitLatch(latch)); + } + finally + { + client.close(); + } + } + + @Test + public void testReconnectAfterLoss() throws Exception + { + Timing timing = new Timing(); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try { client.start(); - final CountDownLatch lostLatch = new CountDownLatch(1); - ConnectionStateListener listener = new ConnectionStateListener() + final CountDownLatch lostLatch = new CountDownLatch(1); + ConnectionStateListener listener = new ConnectionStateListener() { @Override public void stateChanged(CuratorFramework client, ConnectionState newState) @@ -100,10 +130,10 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testGetAclNoStat() throws Exception + public void testGetAclNoStat() throws Exception { - CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { @@ -123,17 +153,17 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testMissedResponseOnBackgroundESCreate() throws Exception + public void testMissedResponseOnBackgroundESCreate() throws Exception { - CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { - CreateBuilderImpl createBuilder = (CreateBuilderImpl)client.create(); + CreateBuilderImpl createBuilder = (CreateBuilderImpl)client.create(); createBuilder.failNextCreateForTesting = true; - final BlockingQueue queue = Queues.newArrayBlockingQueue(1); - BackgroundCallback callback = new BackgroundCallback() + final BlockingQueue queue = Queues.newArrayBlockingQueue(1); + BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception @@ -142,7 +172,7 @@ public class TestFrameworkEdges extends BaseClassForTests } }; createBuilder.withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).inBackground(callback).forPath("/"); - String ourPath = queue.poll(10, TimeUnit.SECONDS); + String ourPath = queue.poll(10, TimeUnit.SECONDS); Assert.assertTrue(ourPath.startsWith(ZKPaths.makePath("/", CreateBuilderImpl.PROTECTED_PREFIX))); Assert.assertFalse(createBuilder.failNextCreateForTesting); } @@ -153,15 +183,15 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testMissedResponseOnESCreate() throws Exception + public void testMissedResponseOnESCreate() throws Exception { - CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); + CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { - CreateBuilderImpl createBuilder = (CreateBuilderImpl)client.create(); + CreateBuilderImpl createBuilder = (CreateBuilderImpl)client.create(); createBuilder.failNextCreateForTesting = true; - String ourPath = createBuilder.withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/"); + String ourPath = createBuilder.withProtection().withMode(CreateMode.EPHEMERAL_SEQUENTIAL).forPath("/"); Assert.assertTrue(ourPath.startsWith(ZKPaths.makePath("/", CreateBuilderImpl.PROTECTED_PREFIX))); Assert.assertFalse(createBuilder.failNextCreateForTesting); } @@ -172,7 +202,7 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testSessionKilled() throws Exception + public void testSessionKilled() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); @@ -180,8 +210,8 @@ public class TestFrameworkEdges extends BaseClassForTests { client.create().forPath("/sessionTest"); - final AtomicBoolean sessionDied = new AtomicBoolean(false); - Watcher watcher = new Watcher() + final AtomicBoolean sessionDied = new AtomicBoolean(false); + Watcher watcher = new Watcher() { @Override public void process(WatchedEvent event) @@ -204,35 +234,35 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testNestedCalls() throws Exception + public void testNestedCalls() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); client.start(); try { client.getCuratorListenable().addListener - ( - new CuratorListener() - { - @Override - public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception + ( + new CuratorListener() { - if ( event.getType() == CuratorEventType.EXISTS ) + @Override + public void eventReceived(CuratorFramework client, CuratorEvent event) throws Exception { - Stat stat = client.checkExists().forPath("/yo/yo/yo"); - Assert.assertNull(stat); + if ( event.getType() == CuratorEventType.EXISTS ) + { + Stat stat = client.checkExists().forPath("/yo/yo/yo"); + Assert.assertNull(stat); - client.create().inBackground(event.getContext()).forPath("/what"); - } - else if ( event.getType() == CuratorEventType.CREATE ) - { - ((CountDownLatch)event.getContext()).countDown(); + client.create().inBackground(event.getContext()).forPath("/what"); + } + else if ( event.getType() == CuratorEventType.CREATE ) + { + ((CountDownLatch)event.getContext()).countDown(); + } } } - } - ); + ); - CountDownLatch latch = new CountDownLatch(1); + CountDownLatch latch = new CountDownLatch(1); client.checkExists().inBackground(latch).forPath("/hey"); Assert.assertTrue(latch.await(10, TimeUnit.SECONDS)); } @@ -243,28 +273,28 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testBackgroundFailure() throws Exception + public void testBackgroundFailure() 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)); client.start(); try { - final CountDownLatch latch = new CountDownLatch(1); + final CountDownLatch latch = new CountDownLatch(1); client.getConnectionStateListenable().addListener - ( - new ConnectionStateListener() - { - @Override - public void stateChanged(CuratorFramework client, ConnectionState newState) + ( + new ConnectionStateListener() { - if ( newState == ConnectionState.LOST ) + @Override + public void stateChanged(CuratorFramework client, ConnectionState newState) { - latch.countDown(); + if ( newState == ConnectionState.LOST ) + { + latch.countDown(); + } } } - } - ); + ); client.checkExists().forPath("/hey"); client.checkExists().inBackground().forPath("/hey"); @@ -281,7 +311,7 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testFailure() throws Exception + public void testFailure() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), 100, 100, new RetryOneTime(1)); client.start(); @@ -306,40 +336,40 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testRetry() throws Exception + public void testRetry() throws Exception { - final int MAX_RETRIES = 3; - final int serverPort = server.getPort(); + final int MAX_RETRIES = 3; + final int serverPort = server.getPort(); final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), 1000, 1000, new RetryOneTime(10)); client.start(); try { - final AtomicInteger retries = new AtomicInteger(0); - final Semaphore semaphore = new Semaphore(0); + final AtomicInteger retries = new AtomicInteger(0); + final Semaphore semaphore = new Semaphore(0); client.getZookeeperClient().setRetryPolicy - ( - new RetryPolicy() - { - @Override - public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) + ( + new RetryPolicy() { - semaphore.release(); - if ( retries.incrementAndGet() == MAX_RETRIES ) + @Override + public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) { - try + semaphore.release(); + if ( retries.incrementAndGet() == MAX_RETRIES ) { - server = new TestingServer(serverPort); - } - catch ( Exception e ) - { - throw new Error(e); + try + { + server = new TestingServer(serverPort); + } + catch ( Exception e ) + { + throw new Error(e); + } } + return true; } - return true; } - } - ); + ); server.stop(); @@ -367,7 +397,7 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testNotStarted() throws Exception + public void testNotStarted() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try @@ -386,7 +416,7 @@ public class TestFrameworkEdges extends BaseClassForTests } @Test - public void testStopped() throws Exception + public void testStopped() throws Exception { CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new RetryOneTime(1)); try