Move Thread.sleep test to awaitBusy

This commit is contained in:
Simon Willnauer 2013-12-08 20:55:08 +01:00
parent 1ef349db49
commit 11e2b1bef3
1 changed files with 15 additions and 9 deletions

View File

@ -20,6 +20,7 @@
package org.elasticsearch.gateway.fs; package org.elasticsearch.gateway.fs;
import com.carrotsearch.randomizedtesting.annotations.Nightly; import com.carrotsearch.randomizedtesting.annotations.Nightly;
import com.google.common.base.Predicate;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.apache.lucene.util.SetOnce; import org.apache.lucene.util.SetOnce;
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse; 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.client.Requests.*;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.*;
/** /**
@ -363,17 +365,21 @@ public class IndexGatewayTests extends ElasticsearchIntegrationTest {
assertThat(clusterHealth.isTimedOut(), equalTo(false)); assertThat(clusterHealth.isTimedOut(), equalTo(false));
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN)); assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
client().admin().indices().create(createIndexRequest("test")).actionGet(); assertAcked(client().admin().indices().create(createIndexRequest("test")).actionGet());
cluster().stopRandomNode(); cluster().stopRandomNode();
cluster().startNode(nodeSettings(0)); cluster().startNode(nodeSettings(0));
Thread.sleep(500); assertTrue("index should exists", awaitBusy(new Predicate<Object>() {
try { @Override
client().admin().indices().create(createIndexRequest("test")).actionGet(); public boolean apply(Object input) {
assert false : "index should exists"; try {
} catch (IndexAlreadyExistsException e) { client().admin().indices().create(createIndexRequest("test")).actionGet();
// all is well return false;
} } catch (IndexAlreadyExistsException e) {
// all is well
return true;
}
}
}));
} }
} }