From 3142fec2063d6ce769e366b26cbfd3f34a96e051 Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 15 Sep 2014 11:18:39 +0200 Subject: [PATCH] Test: ZenUnicastDiscoveryTests.testNormalClusterForming should start unicast hosts first The test starts a cluster with random nodes as unicast hosts but *doesn't* use min_master_nodes. If the unicast hosts are started last, nodes may elect themselves as master as they do not have mechanism yet to share information. --- .../discovery/ZenUnicastDiscoveryTests.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java index c36834d7cf9..fb1b32f8925 100644 --- a/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java +++ b/src/test/java/org/elasticsearch/discovery/ZenUnicastDiscoveryTests.java @@ -52,10 +52,19 @@ public class ZenUnicastDiscoveryTests extends ElasticsearchIntegrationTest { @Test public void testNormalClusterForming() throws ExecutionException, InterruptedException { int currentNumNodes = randomIntBetween(3, 5); - int currentNumOfUnicastHosts = randomIntBetween(1, currentNumNodes); - discoveryConfig = new ClusterDiscoveryConfiguration.UnicastZen(currentNumNodes, currentNumOfUnicastHosts); - internalCluster().startNodesAsync(currentNumNodes).get(); + // use explicit unicast hosts so we can start those first + int[] unicastHostOrdinals = new int[randomIntBetween(1, currentNumNodes)]; + for (int i = 0; i < unicastHostOrdinals.length; i++) { + unicastHostOrdinals[i] = i; + } + discoveryConfig = new ClusterDiscoveryConfiguration.UnicastZen(currentNumNodes, unicastHostOrdinals); + + // start the unicast hosts + internalCluster().startNodesAsync(unicastHostOrdinals.length).get(); + + // start the rest of the cluster + internalCluster().startNodesAsync(currentNumNodes - unicastHostOrdinals.length).get(); if (client().admin().cluster().prepareHealth().setWaitForNodes("" + currentNumNodes).get().isTimedOut()) { logger.info("cluster forming timed out, cluster state:\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint());