This is an automated email from the ASF dual-hosted git repository. randgalt pushed a commit to branch CURATOR-559-fix-nested-retry-loops-reopen in repository https://gitbox.apache.org/repos/asf/curator.git
commit 1e8fb6a5d57fc21108c652e5013b7fba89ff412c Author: randgalt <[email protected]> AuthorDate: Mon Apr 20 17:14:41 2020 -0500 CURATOR-559 - background thread retries are spoiling the test. Try to work around this --- .../curator/connection/TestThreadLocalRetryLoop.java | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/curator-recipes/src/test/java/org/apache/curator/connection/TestThreadLocalRetryLoop.java b/curator-recipes/src/test/java/org/apache/curator/connection/TestThreadLocalRetryLoop.java index 686109c..d1cc243 100644 --- a/curator-recipes/src/test/java/org/apache/curator/connection/TestThreadLocalRetryLoop.java +++ b/curator-recipes/src/test/java/org/apache/curator/connection/TestThreadLocalRetryLoop.java @@ -18,6 +18,7 @@ */ package org.apache.curator.connection; +import org.apache.curator.RetryLoop; import org.apache.curator.RetryPolicy; import org.apache.curator.RetrySleeper; import org.apache.curator.framework.CuratorFramework; @@ -25,6 +26,7 @@ import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.retry.RetryNTimes; import org.apache.curator.test.compatibility.CuratorTestBase; +import org.apache.curator.utils.ThreadUtils; import org.apache.zookeeper.KeeperException; import org.testng.Assert; import org.testng.annotations.Test; @@ -37,6 +39,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class TestThreadLocalRetryLoop extends CuratorTestBase { private static final int retryCount = 4; + private static final String backgroundThreadNameBase = "ignore-curator-background-thread"; @Test(description = "Check for fix for CURATOR-559") public void testRecursingRetry() throws Exception @@ -79,7 +82,7 @@ public class TestThreadLocalRetryLoop extends CuratorTestBase private CuratorFramework newClient(AtomicInteger count) { RetryPolicy retryPolicy = makeRetryPolicy(count); - return CuratorFrameworkFactory.newClient(server.getConnectString(), 100, 100, retryPolicy); + return CuratorFrameworkFactory.builder().connectString(server.getConnectString()).connectionTimeoutMs(100).sessionTimeoutMs(100).retryPolicy(retryPolicy).threadFactory(ThreadUtils.newThreadFactory(backgroundThreadNameBase)).build(); } private void prep(CuratorFramework client, AtomicInteger count) throws Exception @@ -88,7 +91,8 @@ public class TestThreadLocalRetryLoop extends CuratorTestBase client.create().forPath("/test"); CountDownLatch lostLatch = new CountDownLatch(1); client.getConnectionStateListenable().addListener((__, newState) -> { - if (newState == ConnectionState.LOST) { + if ( newState == ConnectionState.LOST ) + { lostLatch.countDown(); } }); @@ -101,10 +105,13 @@ public class TestThreadLocalRetryLoop extends CuratorTestBase { try { - client.checkExists().forPath("/hey"); + RetryLoop.callWithRetry(client.getZookeeperClient(), () -> { + client.checkExists().forPath("/hey"); + return null; + }); Assert.fail("Should have thrown an exception"); } - catch ( KeeperException ignore ) + catch ( KeeperException dummy ) { // correct } @@ -118,7 +125,10 @@ public class TestThreadLocalRetryLoop extends CuratorTestBase @Override public boolean allowRetry(int retryCount, long elapsedTimeMs, RetrySleeper sleeper) { - count.incrementAndGet(); + if ( !Thread.currentThread().getName().contains(backgroundThreadNameBase) ) // if it does, it's Curator's background thread - don't count these + { + count.incrementAndGet(); + } return super.allowRetry(retryCount, elapsedTimeMs, sleeper); } };
