[TEST] move more tests to assertBusy from awaitBusy

This commit is contained in:
Shay Banon 2014-07-09 21:16:15 +02:00
parent 0a58781d2d
commit b301132d7b
5 changed files with 40 additions and 88 deletions

View File

@ -21,17 +21,12 @@
package org.elasticsearch.action.bulk;
import com.google.common.base.Charsets;
import com.google.common.base.Predicate;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
import static org.elasticsearch.test.ElasticsearchIntegrationTest.*;
import static org.hamcrest.Matchers.equalTo;
@ClusterScope(scope= Scope.SUITE, numDataNodes =1)
public class BulkIntegrationTests extends ElasticsearchIntegrationTest {
@Test
@ -39,33 +34,14 @@ public class BulkIntegrationTests extends ElasticsearchIntegrationTest{
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json");
BulkRequestBuilder bulkBuilder = new BulkRequestBuilder(client());
bulkBuilder.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), true, null, null);
bulkBuilder.execute().actionGet();
awaitBusy(new Predicate<Object>() {
bulkBuilder.get();
assertBusy(new Runnable() {
@Override
public boolean apply(Object input) {
try {
GetMappingsResponse mappingsResponse = client().admin().indices().getMappings(new GetMappingsRequest()).get();
return mappingsResponse.getMappings().containsKey("logstash-2014.03.30");
} catch (Throwable t) {
return false;
}
}
});
awaitBusy(new Predicate<Object>() {
@Override
public boolean apply(Object input) {
try {
GetMappingsResponse mappingsResponse = client().admin().indices().getMappings(new GetMappingsRequest()).get();
return mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs");
} catch (Throwable t) {
return false;
}
}
});
ensureYellow();
GetMappingsResponse mappingsResponse = client().admin().indices().getMappings(new GetMappingsRequest()).get();
assertThat(mappingsResponse.mappings().size(), equalTo(1));
public void run() {
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get();
assertTrue(mappingsResponse.getMappings().containsKey("logstash-2014.03.30"));
assertTrue(mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs"));
}
});
}
}

View File

@ -63,13 +63,13 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest {
createIndex("test");
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
internalCluster().stopRandomDataNode();
assertThat(awaitBusy(new Predicate<Object>() {
public boolean apply(Object o) {
assertBusy(new Runnable() {
@Override
public void run() {
ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
return state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK);
assertTrue(state.blocks().hasGlobalBlock(Discovery.NO_MASTER_BLOCK));
}
}), equalTo(true));
});
try {
client().prepareGet("test", "type1", "1").execute().actionGet();

View File

@ -221,16 +221,13 @@ public class EsExecutorsTests extends ElasticsearchTestCase {
assertThat("wrong pool size", pool.getPoolSize(), equalTo(max));
assertThat("wrong active size", pool.getActiveCount(), equalTo(max));
barrier.await();
awaitBusy(new Predicate<Object>() {
public boolean apply(Object o) {
return pool.getActiveCount() == 0 && pool.getPoolSize() < max;
assertBusy(new Runnable() {
@Override
public void run() {
assertThat("wrong active count", pool.getActiveCount(), equalTo(0));
assertThat("idle threads didn't shrink below max. (" + pool.getPoolSize() + ")", pool.getPoolSize(), lessThan(max));
}
});
//assertThat("not all tasks completed", pool.getCompletedTaskCount(), equalTo((long) max));
assertThat("wrong active count", pool.getActiveCount(), equalTo(0));
//assertThat("wrong pool size. ", min, equalTo(pool.getPoolSize())); //BUG in ThreadPool - Bug ID: 6458662
//assertThat("idle threads didn't stay above min (" + pool.getPoolSize() + ")", pool.getPoolSize(), greaterThan(0));
assertThat("idle threads didn't shrink below max. (" + pool.getPoolSize() + ")", pool.getPoolSize(), lessThan(max));
pool.shutdown();
}
}

View File

@ -31,12 +31,16 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
import org.hamcrest.Matchers;
import java.util.Set;
import java.util.concurrent.Callable;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFailures;
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
@ClusterScope(randomDynamicTemplates = false)
public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
@ -119,41 +123,24 @@ public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
.endObject()
.endObject()).get());
logger.info(">> put mapping end {}", format);
boolean applied = awaitBusy(new Predicate<Object>() {
assertBusy(new Callable<Object>() {
@Override
public boolean apply(Object input) {
try {
public Object call() throws Exception {
Set<String> nodes = internalCluster().nodesInclude("test");
if (nodes.isEmpty()) { // we expect at least one node to hold an index, so wait if not allocated yet
return false;
}
assertFalse(nodes.isEmpty());
for (String node : nodes) {
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
IndexService indexService = indicesService.indexService("test");
if (indexService == null) {
return false;
}
assertThat(indexService, notNullValue());
final SmartNameFieldMappers mappers = indexService.mapperService().smartName("s");
if (mappers == null || !mappers.hasMapper()) {
return false;
}
assertThat(mappers, notNullValue());
assertTrue(mappers.hasMapper());
final String currentFormat = mappers.mapper().fieldDataType().getFormat(ImmutableSettings.EMPTY);
if (!format.equals(currentFormat)) {
return false;
assertThat(currentFormat, equalTo(format));
}
}
} catch (Exception e) {
logger.info("got exception waiting for concrete mappings", e);
return false;
}
return true;
return null;
}
});
waitNoPendingTasksOnAll();
logger.info(">> put mapping verified {}, applies {}", format, applied);
if (!applied) {
fail();
}
}
}

View File

@ -67,22 +67,14 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
assertThat(countResponse.getCount(), equalTo(0l));
}
boolean applied = awaitBusy(new Predicate<Object>() {
assertBusy(new Runnable() {
@Override
public boolean apply(Object input) {
GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").setTypes("type1").get();
ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get("test");
if (mappings == null) {
return true;
}
return !mappings.containsKey("type1");
public void run() {
GetMappingsResponse response = client().admin().indices().prepareGetMappings().get();
assertTrue(response.getMappings().containsKey("test"));
assertFalse(response.getMappings().get("test").containsKey("type1"));
}
});
if (!applied) {
fail("failed to wait for the mapping to be removed from the master cluster state");
}
}