[09/10] curator git commit: better test - shouldn't fail if slow
better test - shouldn't fail if slow Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/a7076bc8 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/a7076bc8 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/a7076bc8 Branch: refs/heads/CURATOR-3.0 Commit: a7076bc8dd806bb824e33dcd2f8b5e53626b5691 Parents: c108466 Author: randgalt Authored: Sat Sep 26 10:03:20 2015 -0500 Committer: randgalt Committed: Sat Sep 26 10:03:20 2015 -0500 -- .../framework/imps/TestFrameworkBackground.java| 17 - 1 file changed, 8 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/curator/blob/a7076bc8/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 26cc941..6575018 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,6 +20,7 @@ package org.apache.curator.framework.imps; import com.google.common.collect.Lists; +import com.google.common.collect.Queues; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.api.BackgroundCallback; @@ -30,15 +31,15 @@ import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.curator.retry.RetryNTimes; import org.apache.curator.retry.RetryOneTime; import org.apache.curator.test.BaseClassForTests; -import org.apache.curator.test.TestingServer; import org.apache.curator.test.Timing; import org.apache.curator.utils.CloseableUtils; 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.BlockingQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -149,24 +150,22 @@ public class TestFrameworkBackground extends BaseClassForTests { client.start(); -final CountDownLatch latch = new CountDownLatch(3); -final List paths = Lists.newArrayList(); -BackgroundCallback callback = new BackgroundCallback() +final BlockingQueue paths = Queues.newLinkedBlockingQueue(); +BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { paths.add(event.getPath()); -latch.countDown(); } }; client.create().inBackground(callback).forPath("/one"); client.create().inBackground(callback).forPath("/one/two"); client.create().inBackground(callback).forPath("/one/two/three"); -latch.await(); - -Assert.assertEquals(paths, Arrays.asList("/one", "/one/two", "/one/two/three")); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one"); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one/two"); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one/two/three"); } finally {
curator git commit: better test - shouldn't fail if slow
Repository: curator Updated Branches: refs/heads/CURATOR-265 c1084663a -> a7076bc8d better test - shouldn't fail if slow Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/a7076bc8 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/a7076bc8 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/a7076bc8 Branch: refs/heads/CURATOR-265 Commit: a7076bc8dd806bb824e33dcd2f8b5e53626b5691 Parents: c108466 Author: randgalt Authored: Sat Sep 26 10:03:20 2015 -0500 Committer: randgalt Committed: Sat Sep 26 10:03:20 2015 -0500 -- .../framework/imps/TestFrameworkBackground.java| 17 - 1 file changed, 8 insertions(+), 9 deletions(-) -- http://git-wip-us.apache.org/repos/asf/curator/blob/a7076bc8/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 26cc941..6575018 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,6 +20,7 @@ package org.apache.curator.framework.imps; import com.google.common.collect.Lists; +import com.google.common.collect.Queues; import org.apache.curator.framework.CuratorFramework; import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.api.BackgroundCallback; @@ -30,15 +31,15 @@ import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.curator.retry.RetryNTimes; import org.apache.curator.retry.RetryOneTime; import org.apache.curator.test.BaseClassForTests; -import org.apache.curator.test.TestingServer; import org.apache.curator.test.Timing; import org.apache.curator.utils.CloseableUtils; 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.BlockingQueue; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicReference; @@ -149,24 +150,22 @@ public class TestFrameworkBackground extends BaseClassForTests { client.start(); -final CountDownLatch latch = new CountDownLatch(3); -final List paths = Lists.newArrayList(); -BackgroundCallback callback = new BackgroundCallback() +final BlockingQueue paths = Queues.newLinkedBlockingQueue(); +BackgroundCallback callback = new BackgroundCallback() { @Override public void processResult(CuratorFramework client, CuratorEvent event) throws Exception { paths.add(event.getPath()); -latch.countDown(); } }; client.create().inBackground(callback).forPath("/one"); client.create().inBackground(callback).forPath("/one/two"); client.create().inBackground(callback).forPath("/one/two/three"); -latch.await(); - -Assert.assertEquals(paths, Arrays.asList("/one", "/one/two", "/one/two/three")); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one"); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one/two"); +Assert.assertEquals(paths.poll(timing.milliseconds(), TimeUnit.MILLISECONDS), "/one/two/three"); } finally {