CURATOR-190 - Fixed up unit tests that were failing due to server restart. Removed unnecessary use of PersistentEphemeralNode from testConnectionStateListener()
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/017e199a Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/017e199a Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/017e199a Branch: refs/heads/CURATOR-3.0 Commit: 017e199a32647d7c7a4bbd8eaf4339b5e45d472a Parents: 9fe802e Author: Cameron McKenzie <came...@unico.com.au> Authored: Tue Apr 28 10:59:39 2015 +1000 Committer: Cameron McKenzie <came...@unico.com.au> Committed: Tue Apr 28 10:59:39 2015 +1000 ---------------------------------------------------------------------- .../framework/client/TestBackgroundStates.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/017e199a/curator-recipes/src/test/java/org/apache/curator/framework/client/TestBackgroundStates.java ---------------------------------------------------------------------- diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/client/TestBackgroundStates.java b/curator-recipes/src/test/java/org/apache/curator/framework/client/TestBackgroundStates.java index ac7c7a9..19cb9a2 100644 --- a/curator-recipes/src/test/java/org/apache/curator/framework/client/TestBackgroundStates.java +++ b/curator-recipes/src/test/java/org/apache/curator/framework/client/TestBackgroundStates.java @@ -48,10 +48,11 @@ public class TestBackgroundStates extends BaseClassForTests Timing timing = new Timing(); CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); + PersistentEphemeralNode node = null; try { client.start(); - PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes()); + node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes()); node.start(); final CountDownLatch connectedLatch = new CountDownLatch(1); @@ -79,9 +80,9 @@ public class TestBackgroundStates extends BaseClassForTests Assert.assertTrue(timing.awaitLatch(connectedLatch)); timing.sleepABit(); Assert.assertTrue(node.waitForInitialCreate(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS)); - server.close(); + server.restart(); timing.sleepABit(); - server = new TestingServer(server.getPort()); + //server = new TestingServer(server.getPort()); timing.sleepABit(); Assert.assertTrue(timing.awaitLatch(reconnectedLatch)); timing.sleepABit(); @@ -90,6 +91,7 @@ public class TestBackgroundStates extends BaseClassForTests finally { CloseableUtils.closeQuietly(client); + CloseableUtils.closeQuietly(node); } } @@ -103,8 +105,6 @@ public class TestBackgroundStates extends BaseClassForTests try { client.start(); - PersistentEphemeralNode node = new PersistentEphemeralNode(client, PersistentEphemeralNode.Mode.EPHEMERAL, "/abc/node", "hello".getBytes()); - node.start(); final BlockingQueue<ConnectionState> stateVector = Queues.newLinkedBlockingQueue(1); ConnectionStateListener listener = new ConnectionStateListener() @@ -121,10 +121,10 @@ public class TestBackgroundStates extends BaseClassForTests client.getConnectionStateListenable().addListener(listener); server = new TestingServer(server.getPort()); Assert.assertEquals(stateVector.poll(waitingTiming.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.CONNECTED); - server.close(); + server.stop(); Assert.assertEquals(stateVector.poll(waitingTiming.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.SUSPENDED); Assert.assertEquals(stateVector.poll(waitingTiming.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.LOST); - server = new TestingServer(server.getPort()); + server.restart(); Assert.assertEquals(stateVector.poll(waitingTiming.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.RECONNECTED); server.close(); Assert.assertEquals(stateVector.poll(waitingTiming.milliseconds(), TimeUnit.MILLISECONDS), ConnectionState.SUSPENDED);