diff --git a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java index 8fe09c8c1b5..5c38750105c 100644 --- a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java +++ b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java @@ -124,9 +124,8 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase { @AfterClass protected static void afterClass() { - TestCluster toRelease = cluster; cluster = null; - ClusterManager.releaseCluster(toRelease); + ClusterManager.releaseCluster(); } public static Client client() { diff --git a/src/test/java/org/elasticsearch/test/integration/ClusterManager.java b/src/test/java/org/elasticsearch/test/integration/ClusterManager.java index 652a75a3b1e..9fb0d28b490 100644 --- a/src/test/java/org/elasticsearch/test/integration/ClusterManager.java +++ b/src/test/java/org/elasticsearch/test/integration/ClusterManager.java @@ -18,41 +18,21 @@ */ package org.elasticsearch.test.integration; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; public class ClusterManager { - private static final ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); private static TestCluster cluster; - private static int generation = 0; public synchronized static TestCluster accquireCluster() { if (cluster == null) { - cluster = new TestCluster(generation++); + cluster = new TestCluster(); } - TestCluster c = cluster; - if (!c.tryAccquire()) { - c = new TestCluster(generation++); - boolean tryAccquire = c.tryAccquire(); - assert tryAccquire; - cluster = c; - } - - c.reset(); - return c; + cluster.reset(); + return cluster; } - public static synchronized void releaseCluster(final TestCluster toRelease) { - toRelease.decrementReference(); - // TODO find a better way -// service.schedule(new Runnable() { -// @Override -// public void run() { -// toRelease.close(); -// } -// }, 3, TimeUnit.MINUTES); + public static synchronized void releaseCluster() { + // doNothing } } diff --git a/src/test/java/org/elasticsearch/test/integration/TestCluster.java b/src/test/java/org/elasticsearch/test/integration/TestCluster.java index 885bca75738..f44f4bc04f7 100644 --- a/src/test/java/org/elasticsearch/test/integration/TestCluster.java +++ b/src/test/java/org/elasticsearch/test/integration/TestCluster.java @@ -35,7 +35,6 @@ import java.util.Random; import java.util.Set; import java.util.UUID; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; import org.apache.lucene.util.IOUtils; import org.elasticsearch.client.Client; @@ -69,15 +68,15 @@ public class TestCluster { * "action.auto_create_index" * "node.local" */ - - protected final ESLogger logger = Loggers.getLogger(getClass()); private Map nodes = newHashMap(); - private final AtomicInteger refCount = new AtomicInteger(1); - private final String clusterName; + + private final AtomicBoolean open = new AtomicBoolean(true); + + private final Settings defaultSettings; @@ -85,8 +84,8 @@ public class TestCluster { private NodeAndClient clientNode; - public TestCluster(int generation) { - this("simple-test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "_gen_" + generation, ImmutableSettings.settingsBuilder().build()); + public TestCluster() { + this("simple-test-cluster-" + NetworkUtils.getLocalAddress().getHostName() + "_" + System.currentTimeMillis(), ImmutableSettings.settingsBuilder().build()); } private TestCluster(String clusterName, Settings defaultSettings) { @@ -103,25 +102,11 @@ public class TestCluster { this.defaultSettings = ImmutableSettings.settingsBuilder().put(defaultSettings).put("cluster.name", clusterName).build(); } - boolean tryAccquire() { - int refs = this.refCount.get(); - while (refs > 0) { - if (this.refCount.compareAndSet(refs, refs + 1)) { - return true; - } - } - return false; - } private void ensureOpen() { - if (this.refCount.get() == 0) { + if (!open.get()) { throw new RuntimeException("Cluster is already closed"); } - assert this.refCount.get() >= 0; - } - - int decrementReference() { - return this.refCount.decrementAndGet(); } public Node getOneNode() { @@ -201,15 +186,13 @@ public class TestCluster { public void close() { ensureOpen(); - while (this.refCount.get() == 1) { - if (this.refCount.compareAndSet(1, 0)) { - IOUtils.closeWhileHandlingException(nodes.values()); - nodes.clear(); + if (this.open.compareAndSet(true, false)) { + IOUtils.closeWhileHandlingException(nodes.values()); + nodes.clear(); + if (clientNode != null) { + IOUtils.closeWhileHandlingException(clientNode); } } - if (clientNode != null) { - IOUtils.closeWhileHandlingException(clientNode); - } } public ImmutableSet waitForNoBlocks(TimeValue timeout, Node node) throws InterruptedException {