From 3b01f812d64d8c957ece77261d10a646df1ca3df Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Thu, 6 Jun 2013 17:03:36 +0200 Subject: [PATCH] Stabelize more tests Wait for relocation before checking statistics or run refresh / optimze. --- .../AbstractSharedClusterTest.java | 20 +++++++++++++++++++ .../document/DocumentActionsTests.java | 6 ++++-- .../indices/IgnoreIndicesTests.java | 6 +++--- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java index 92b911f9c87..f6406cecf9c 100644 --- a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java +++ b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java @@ -23,6 +23,8 @@ import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFa import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; +import org.elasticsearch.action.admin.cluster.health.ClusterHealthRequest; + import java.io.IOException; import java.util.HashSet; import java.util.Iterator; @@ -242,6 +244,24 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase { return actionGet.getStatus(); } + public ClusterHealthStatus waitForRelocation() { + return waitForRelocation(null); + } + + public ClusterHealthStatus waitForRelocation(ClusterHealthStatus status) { + ClusterHealthRequest request = Requests.clusterHealthRequest().waitForRelocatingShards(0); + if (status != null) { + request.waitForStatus(status); + } + ClusterHealthResponse actionGet = client().admin().cluster() + .health(request).actionGet(); + assertThat(actionGet.isTimedOut(), equalTo(false)); + if (status != null) { + assertThat(actionGet.getStatus(), equalTo(status)); + } + return actionGet.getStatus(); + } + public ClusterHealthStatus ensureYellow() { ClusterHealthResponse actionGet = client().admin().cluster() .health(Requests.clusterHealthRequest().waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet(); diff --git a/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java b/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java index 9517f43f12c..a8f68840c5a 100644 --- a/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java +++ b/src/test/java/org/elasticsearch/test/integration/document/DocumentActionsTests.java @@ -107,8 +107,9 @@ public class DocumentActionsTests extends AbstractSharedClusterTest { ClearIndicesCacheResponse clearIndicesCacheResponse = client().admin().indices().clearCache(clearIndicesCacheRequest("test").recycler(true).fieldDataCache(true).filterCache(true).idCache(true)).actionGet(); assertNoFailures(clearIndicesCacheResponse); assertThat(clearIndicesCacheResponse.getSuccessfulShards(), equalTo(10)); - + logger.info("Optimizing"); + waitForRelocation(ClusterHealthStatus.GREEN); OptimizeResponse optimizeResponse = optimize(); assertThat(optimizeResponse.getSuccessfulShards(), equalTo(10)); @@ -279,9 +280,10 @@ public class DocumentActionsTests extends AbstractSharedClusterTest { assertThat(bulkResponse.getItems()[4].getIndex(), equalTo(getConcreteIndexName())); assertThat(bulkResponse.getItems()[4].getType(), equalTo("type1")); + waitForRelocation(ClusterHealthStatus.GREEN); RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet(); + assertNoFailures(refreshResponse); assertThat(refreshResponse.getSuccessfulShards(), equalTo(10)); - assertThat(refreshResponse.getFailedShards(), equalTo(0)); for (int i = 0; i < 5; i++) { diff --git a/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java index 94a877b59ca..3c47353271d 100644 --- a/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java @@ -179,12 +179,12 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest { @Test // For now don't handle closed indices public void testClosed() throws Exception { + cluster().ensureAtLeastNumNodes(2); createIndex("test1", "test2"); - ensureYellow(); + ensureGreen(); client().prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); client().admin().indices().prepareClose("test2").execute().actionGet(); - ensureYellow(); - + ensureGreen(); try { client().prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); fail("Exception should have been thrown");