From 8862348e4f7c0d8d31bd4b3ec431f1f906017877 Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 24 Aug 2015 13:39:05 +0200 Subject: [PATCH] test: moved ensureStableCluster(...) to base integ test class --- .../DiscoveryWithServiceDisruptionsIT.java | 32 ------------------ .../elasticsearch/test/ESIntegTestCase.java | 33 +++++++++++++++++++ 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java index 02173a0c0b6..c18abdc5bef 100644 --- a/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java +++ b/core/src/test/java/org/elasticsearch/discovery/DiscoveryWithServiceDisruptionsIT.java @@ -1001,38 +1001,6 @@ public class DiscoveryWithServiceDisruptionsIT extends ESIntegTestCase { return list.get(0); } - private void ensureStableCluster(int nodeCount) { - ensureStableCluster(nodeCount, TimeValue.timeValueSeconds(30)); - } - - private void ensureStableCluster(int nodeCount, TimeValue timeValue) { - ensureStableCluster(nodeCount, timeValue, false, null); - } - - private void ensureStableCluster(int nodeCount, @Nullable String viaNode) { - ensureStableCluster(nodeCount, TimeValue.timeValueSeconds(30), false, viaNode); - } - - private void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) { - if (viaNode == null) { - viaNode = randomFrom(internalCluster().getNodeNames()); - } - logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue); - ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth() - .setWaitForEvents(Priority.LANGUID) - .setWaitForNodes(Integer.toString(nodeCount)) - .setTimeout(timeValue) - .setLocal(local) - .setWaitForRelocatingShards(0) - .get(); - if (clusterHealthResponse.isTimedOut()) { - ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get(); - fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n" - + stateResponse.getState().prettyPrint()); - } - assertThat(clusterHealthResponse.isTimedOut(), is(false)); - } - private ClusterState getNodeClusterState(String node) { return client(node).admin().cluster().prepareState().setLocal(true).get().getState(); } diff --git a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java index faaab9a4c44..798c66ca8f7 100644 --- a/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java +++ b/core/src/test/java/org/elasticsearch/test/ESIntegTestCase.java @@ -29,6 +29,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Lists; import org.apache.http.impl.client.HttpClients; +import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse; import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.routing.UnassignedInfo; import org.elasticsearch.cluster.routing.allocation.decider.EnableAllocationDecider; @@ -1088,6 +1089,38 @@ public abstract class ESIntegTestCase extends ESTestCase { return ensureGreen(indices); } + protected void ensureStableCluster(int nodeCount) { + ensureStableCluster(nodeCount, TimeValue.timeValueSeconds(30)); + } + + protected void ensureStableCluster(int nodeCount, TimeValue timeValue) { + ensureStableCluster(nodeCount, timeValue, false, null); + } + + protected void ensureStableCluster(int nodeCount, @Nullable String viaNode) { + ensureStableCluster(nodeCount, TimeValue.timeValueSeconds(30), false, viaNode); + } + + protected void ensureStableCluster(int nodeCount, TimeValue timeValue, boolean local, @Nullable String viaNode) { + if (viaNode == null) { + viaNode = randomFrom(internalCluster().getNodeNames()); + } + logger.debug("ensuring cluster is stable with [{}] nodes. access node: [{}]. timeout: [{}]", nodeCount, viaNode, timeValue); + ClusterHealthResponse clusterHealthResponse = client(viaNode).admin().cluster().prepareHealth() + .setWaitForEvents(Priority.LANGUID) + .setWaitForNodes(Integer.toString(nodeCount)) + .setTimeout(timeValue) + .setLocal(local) + .setWaitForRelocatingShards(0) + .get(); + if (clusterHealthResponse.isTimedOut()) { + ClusterStateResponse stateResponse = client(viaNode).admin().cluster().prepareState().get(); + fail("failed to reach a stable cluster of [" + nodeCount + "] nodes. Tried via [" + viaNode + "]. last cluster state:\n" + + stateResponse.getState().prettyPrint()); + } + assertThat(clusterHealthResponse.isTimedOut(), is(false)); + } + /** * Syntactic sugar for: *