From 8df7f2af0dcde01b34063285ededeec955697d06 Mon Sep 17 00:00:00 2001 From: Igor Motov Date: Wed, 30 Jan 2013 19:51:41 -0500 Subject: [PATCH] Improve testReusePeerRecovery test --- .../local/SimpleRecoveryLocalGatewayTests.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java b/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java index 8a64ac16743..1c20568caa2 100644 --- a/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java +++ b/src/test/java/org/elasticsearch/test/integration/gateway/local/SimpleRecoveryLocalGatewayTests.java @@ -26,6 +26,7 @@ import org.elasticsearch.action.admin.indices.status.IndicesStatusResponse; import org.elasticsearch.action.admin.indices.status.ShardStatus; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.common.settings.ImmutableSettings; +import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.gateway.Gateway; import org.elasticsearch.index.query.FilterBuilders; @@ -359,7 +360,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests { logger.info("--> shutting down the nodes"); client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet(); - Thread.sleep(2000); + assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), 4), equalTo(true)); logger.info("--> start the nodes back up"); startNode("node1", settings); startNode("node2", settings); @@ -374,7 +375,7 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests { logger.info("--> shutting down the nodes"); client("node1").admin().cluster().prepareNodesShutdown().setDelay("10ms").setExit(false).execute().actionGet(); - Thread.sleep(2000); + assertThat(waitForNodesToShutdown(TimeValue.timeValueSeconds(30), 4), equalTo(true)); logger.info("--> start the nodes back up"); startNode("node1", settings); @@ -428,4 +429,17 @@ public class SimpleRecoveryLocalGatewayTests extends AbstractNodesTests { assertThat(client("node2").admin().indices().prepareExists("test").execute().actionGet().exists(), equalTo(true)); assertThat(client("node2").prepareCount("test").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet().count(), equalTo(1l)); } + + private boolean waitForNodesToShutdown(TimeValue timeout, int numberOfNodes) throws InterruptedException { + long start = System.currentTimeMillis(); + WAIT_FOR_CLOSING: + while ((System.currentTimeMillis() - start) < timeout.millis()) { + Thread.sleep(100); + for (int i = 1; i < numberOfNodes + 1; i++) { + if (!node("node" + i).isClosed()) continue WAIT_FOR_CLOSING; + } + return true; + } + return false; + } }