From a73286bcc4d0da258ed3d2820ecbcd9eaaca92d1 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Thu, 17 Apr 2014 11:51:11 +0700 Subject: [PATCH] [TEST] Use startNodesAsync in unicast discovery tests. --- ...icastDiscoveryTestsMinimumMasterNodes.java | 42 +----------------- ...ZenUnicastDiscoveryTestsSpecificNodes.java | 43 +------------------ 2 files changed, 4 insertions(+), 81 deletions(-) diff --git a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsMinimumMasterNodes.java b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsMinimumMasterNodes.java index fb7c9a36e7d..ea97433587f 100644 --- a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsMinimumMasterNodes.java +++ b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsMinimumMasterNodes.java @@ -25,13 +25,12 @@ import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope; import org.elasticsearch.test.ElasticsearchIntegrationTest.Scope; import org.junit.Test; -import java.util.concurrent.CountDownLatch; +import java.util.List; import static org.hamcrest.Matchers.equalTo; @@ -50,44 +49,7 @@ public class ZenUnicastDiscoveryTestsMinimumMasterNodes extends ElasticsearchInt .put("transport.tcp.port", "25400-25500") // Need to use custom tcp port range otherwise we collide with the shared cluster .build(); - final CountDownLatch latch = new CountDownLatch(3); - final AtomicArray nodes = new AtomicArray<>(3); - Runnable r1 = new Runnable() { - - @Override - public void run() { - logger.info("--> start first node"); - nodes.set(0, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r1).start(); - - sleep(between(500, 3000)); - Runnable r2 = new Runnable() { - - @Override - public void run() { - logger.info("--> start second node"); - nodes.set(1, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r2).start(); - - - sleep(between(500, 3000)); - Runnable r3 = new Runnable() { - - @Override - public void run() { - logger.info("--> start third node"); - nodes.set(2, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r3).start(); - latch.await(); + List nodes = cluster().startNodesAsync(3, settings).get(); ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("3").execute().actionGet(); assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); diff --git a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsSpecificNodes.java b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsSpecificNodes.java index b9d8b7deb13..0d83fee364a 100644 --- a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsSpecificNodes.java +++ b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTestsSpecificNodes.java @@ -25,12 +25,11 @@ import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.node.DiscoveryNode; import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.Settings; -import org.elasticsearch.common.util.concurrent.AtomicArray; import org.elasticsearch.test.ElasticsearchIntegrationTest; import org.elasticsearch.test.junit.annotations.TestLogging; import org.junit.Test; -import java.util.concurrent.CountDownLatch; +import java.util.List; import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder; import static org.hamcrest.Matchers.equalTo; @@ -55,45 +54,7 @@ public class ZenUnicastDiscoveryTestsSpecificNodes extends ElasticsearchIntegrat .put("discovery.zen.ping.unicast.hosts", "localhost:15300,localhost:15301,localhost:15302") .put("transport.tcp.port", "15300-15400") .build(); - - final CountDownLatch latch = new CountDownLatch(3); - final AtomicArray nodes = new AtomicArray<>(3); - Runnable r1 = new Runnable() { - - @Override - public void run() { - logger.info("--> start first node"); - nodes.set(0, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r1).start(); - - sleep(between(500, 3000)); - Runnable r2 = new Runnable() { - - @Override - public void run() { - logger.info("--> start second node"); - nodes.set(1, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r2).start(); - - - sleep(between(500, 3000)); - Runnable r3 = new Runnable() { - - @Override - public void run() { - logger.info("--> start third node"); - nodes.set(2, cluster().startNode(settings)); - latch.countDown(); - } - }; - new Thread(r3).start(); - latch.await(); + List nodes = cluster().startNodesAsync(3, settings).get(); ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForNodes("3").execute().actionGet(); assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));