In testNewMembers the smallCluster wasn't getting closed at the end of the test.
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/d4f15297 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/d4f15297 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/d4f15297 Branch: refs/heads/CURATOR-411 Commit: d4f15297d3594b80b94cf686210999f9c141d5b4 Parents: 9403703 Author: randgalt <[email protected]> Authored: Sun May 28 09:10:38 2017 -0500 Committer: randgalt <[email protected]> Committed: Sun May 28 09:10:38 2017 -0500 ---------------------------------------------------------------------- .../framework/imps/TestReconfiguration.java | 56 ++++++++++++-------- 1 file changed, 34 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/d4f15297/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java index 83ebf74..fc89134 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestReconfiguration.java @@ -290,34 +290,46 @@ public class TestReconfiguration extends BaseClassForTests public void testNewMembers() throws Exception { cluster.close(); - cluster = new TestingCluster(5); - List<TestingZooKeeperServer> servers = cluster.getServers(); - List<InstanceSpec> smallCluster = Lists.newArrayList(); - for ( int i = 0; i < 3; ++i ) // only start 3 of the 5 - { - TestingZooKeeperServer server = servers.get(i); - server.start(); - smallCluster.add(server.getInstanceSpec()); - } + cluster = null; - try ( CuratorFramework client = newClient(new TestingCluster(smallCluster).getConnectString())) + TestingCluster smallCluster = null; + TestingCluster localCluster = new TestingCluster(5); + try { - client.start(); + List<TestingZooKeeperServer> servers = localCluster.getServers(); + List<InstanceSpec> smallClusterInstances = Lists.newArrayList(); + for ( int i = 0; i < 3; ++i ) // only start 3 of the 5 + { + TestingZooKeeperServer server = servers.get(i); + server.start(); + smallClusterInstances.add(server.getInstanceSpec()); + } - QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble()); - Assert.assertEquals(oldConfig.getAllMembers().size(), 5); - assertConfig(oldConfig, cluster.getInstances()); + smallCluster = new TestingCluster(smallClusterInstances); + try ( CuratorFramework client = newClient(smallCluster.getConnectString())) + { + client.start(); - CountDownLatch latch = setChangeWaiter(client); + QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble()); + Assert.assertEquals(oldConfig.getAllMembers().size(), 5); + assertConfig(oldConfig, localCluster.getInstances()); - client.reconfig().withNewMembers(toReconfigSpec(smallCluster)).forEnsemble(); + CountDownLatch latch = setChangeWaiter(client); - Assert.assertTrue(timing.awaitLatch(latch)); - byte[] newConfigData = client.getConfig().forEnsemble(); - QuorumVerifier newConfig = toQuorumVerifier(newConfigData); - Assert.assertEquals(newConfig.getAllMembers().size(), 3); - assertConfig(newConfig, smallCluster); - Assert.assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString()); + client.reconfig().withNewMembers(toReconfigSpec(smallClusterInstances)).forEnsemble(); + + Assert.assertTrue(timing.awaitLatch(latch)); + byte[] newConfigData = client.getConfig().forEnsemble(); + QuorumVerifier newConfig = toQuorumVerifier(newConfigData); + Assert.assertEquals(newConfig.getAllMembers().size(), 3); + assertConfig(newConfig, smallClusterInstances); + Assert.assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString()); + } + } + finally + { + CloseableUtils.closeQuietly(smallCluster); + CloseableUtils.closeQuietly(localCluster); } }
