Skip to content

Commit 11e2b1b

Browse files
committed
Move Thread.sleep test to awaitBusy
1 parent 1ef349d commit 11e2b1b

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/test/java/org/elasticsearch/gateway/fs/IndexGatewayTests.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.elasticsearch.gateway.fs;
2121

2222
import com.carrotsearch.randomizedtesting.annotations.Nightly;
23+
import com.google.common.base.Predicate;
2324
import org.apache.lucene.util.LuceneTestCase.Slow;
2425
import org.apache.lucene.util.SetOnce;
2526
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
@@ -45,6 +46,7 @@
4546

4647
import static org.elasticsearch.client.Requests.*;
4748
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
49+
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
4850
import static org.hamcrest.Matchers.*;
4951

5052
/**
@@ -363,17 +365,21 @@ public void testIndexActions() throws Exception {
363365
assertThat(clusterHealth.isTimedOut(), equalTo(false));
364366
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
365367

366-
client().admin().indices().create(createIndexRequest("test")).actionGet();
368+
assertAcked(client().admin().indices().create(createIndexRequest("test")).actionGet());
367369

368370
cluster().stopRandomNode();
369-
370371
cluster().startNode(nodeSettings(0));
371-
Thread.sleep(500);
372-
try {
373-
client().admin().indices().create(createIndexRequest("test")).actionGet();
374-
assert false : "index should exists";
375-
} catch (IndexAlreadyExistsException e) {
376-
// all is well
377-
}
372+
assertTrue("index should exists", awaitBusy(new Predicate<Object>() {
373+
@Override
374+
public boolean apply(Object input) {
375+
try {
376+
client().admin().indices().create(createIndexRequest("test")).actionGet();
377+
return false;
378+
} catch (IndexAlreadyExistsException e) {
379+
// all is well
380+
return true;
381+
}
382+
}
383+
}));
378384
}
379385
}

0 commit comments

Comments
 (0)