[TEST] move tribe tests to use assertBusy

This commit is contained in:
Shay Banon 2014-07-08 19:06:59 +02:00
parent 10030a63cc
commit bb92d46163

View File

@ -46,6 +46,7 @@ import java.util.Map;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertHitCount;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
/**
* Note, when talking to tribe client, no need to set the local flag on master read operations, it
@ -267,12 +268,12 @@ public class TribeTests extends ElasticsearchIntegrationTest {
logger.info("verify they are there");
assertHitCount(tribeClient.prepareCount().get(), 2l);
assertHitCount(tribeClient.prepareSearch().get(), 2l);
awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object o) {
public void run() {
ClusterState tribeState = tribeNode.client().admin().cluster().prepareState().get().getState();
return tribeState.getMetaData().index("test1").mapping("type1") != null &&
tribeState.getMetaData().index("test2").mapping("type2") != null;
assertThat(tribeState.getMetaData().index("test1").mapping("type1"), notNullValue());
assertThat(tribeState.getMetaData().index("test2").mapping("type1"), notNullValue());
}
});
@ -286,12 +287,14 @@ public class TribeTests extends ElasticsearchIntegrationTest {
logger.info("verify they are there");
assertHitCount(tribeClient.prepareCount().get(), 4l);
assertHitCount(tribeClient.prepareSearch().get(), 4l);
awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object o) {
public void run() {
ClusterState tribeState = tribeNode.client().admin().cluster().prepareState().get().getState();
return tribeState.getMetaData().index("test1").mapping("type1") != null && tribeState.getMetaData().index("test1").mapping("type2") != null &&
tribeState.getMetaData().index("test2").mapping("type1") != null && tribeState.getMetaData().index("test2").mapping("type2") != null;
assertThat(tribeState.getMetaData().index("test1").mapping("type1"), notNullValue());
assertThat(tribeState.getMetaData().index("test1").mapping("type2"), notNullValue());
assertThat(tribeState.getMetaData().index("test2").mapping("type1"), notNullValue());
assertThat(tribeState.getMetaData().index("test2").mapping("type2"), notNullValue());
}
});
@ -305,12 +308,14 @@ public class TribeTests extends ElasticsearchIntegrationTest {
logger.info("delete an index, and make sure its reflected");
cluster2.client().admin().indices().prepareDelete("test2").get();
awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object o) {
public void run() {
ClusterState tribeState = tribeNode.client().admin().cluster().prepareState().get().getState();
return tribeState.getMetaData().hasIndex("test1") && !tribeState.getMetaData().hasIndex("test2") &&
tribeState.getRoutingTable().hasIndex("test1") && !tribeState.getRoutingTable().hasIndex("test2");
assertTrue(tribeState.getMetaData().hasIndex("test1"));
assertFalse(tribeState.getMetaData().hasIndex("test2"));
assertTrue(tribeState.getRoutingTable().hasIndex("test1"));
assertFalse(tribeState.getRoutingTable().hasIndex("test2"));
}
});
@ -320,30 +325,25 @@ public class TribeTests extends ElasticsearchIntegrationTest {
}
private void awaitIndicesInClusterState(final String... indices) throws Exception {
awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object o) {
public void run() {
ClusterState tribeState = tribeNode.client().admin().cluster().prepareState().get().getState();
for (String index : indices) {
if (!tribeState.getMetaData().hasIndex(index)) {
return false;
}
if (!tribeState.getRoutingTable().hasIndex(index)) {
return false;
}
assertTrue(tribeState.getMetaData().hasIndex(index));
assertTrue(tribeState.getRoutingTable().hasIndex(index));
}
return true;
}
});
}
private void awaitSameNodeCounts() throws Exception {
awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object o) {
public void run() {
DiscoveryNodes tribeNodes = tribeNode.client().admin().cluster().prepareState().get().getState().getNodes();
return countDataNodesForTribe("t1", tribeNodes) == internalCluster().client().admin().cluster().prepareState().get().getState().getNodes().dataNodes().size()
&& countDataNodesForTribe("t2", tribeNodes) == cluster2.client().admin().cluster().prepareState().get().getState().getNodes().dataNodes().size();
assertThat(countDataNodesForTribe("t1", tribeNodes), equalTo(internalCluster().client().admin().cluster().prepareState().get().getState().getNodes().dataNodes().size()));
assertThat(countDataNodesForTribe("t2", tribeNodes), equalTo(cluster2.client().admin().cluster().prepareState().get().getState().getNodes().dataNodes().size()));
}
});
}