From 11e2b1bef3dcb24e561076152f0f1af8869d7eff Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Sun, 8 Dec 2013 20:55:08 +0100 Subject: [PATCH] Move Thread.sleep test to awaitBusy --- .../gateway/fs/IndexGatewayTests.java | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/elasticsearch/gateway/fs/IndexGatewayTests.java b/src/test/java/org/elasticsearch/gateway/fs/IndexGatewayTests.java index 3317d5f6f2d..ed6ebe32d60 100644 --- a/src/test/java/org/elasticsearch/gateway/fs/IndexGatewayTests.java +++ b/src/test/java/org/elasticsearch/gateway/fs/IndexGatewayTests.java @@ -20,6 +20,7 @@ package org.elasticsearch.gateway.fs; import com.carrotsearch.randomizedtesting.annotations.Nightly; +import com.google.common.base.Predicate; import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.SetOnce; import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; @@ -45,6 +46,7 @@ import org.junit.Test; import static org.elasticsearch.client.Requests.*; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; import static org.hamcrest.Matchers.*; /** @@ -363,17 +365,21 @@ public class IndexGatewayTests extends ElasticsearchIntegrationTest { assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); - client().admin().indices().create(createIndexRequest("test")).actionGet(); + assertAcked(client().admin().indices().create(createIndexRequest("test")).actionGet()); cluster().stopRandomNode(); - cluster().startNode(nodeSettings(0)); - Thread.sleep(500); - try { - client().admin().indices().create(createIndexRequest("test")).actionGet(); - assert false : "index should exists"; - } catch (IndexAlreadyExistsException e) { - // all is well - } + assertTrue("index should exists", awaitBusy(new Predicate() { + @Override + public boolean apply(Object input) { + try { + client().admin().indices().create(createIndexRequest("test")).actionGet(); + return false; + } catch (IndexAlreadyExistsException e) { + // all is well + return true; + } + } + })); } }