diff --git a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java index 777840d2b9c..8d8e9e996f3 100644 --- a/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java +++ b/src/test/java/org/elasticsearch/action/bulk/BulkIntegrationTests.java @@ -21,51 +21,27 @@ 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{ +public class BulkIntegrationTests extends ElasticsearchIntegrationTest { @Test public void testBulkIndexCreatesMapping() throws Exception { 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() { + 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; - } + 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")); } }); - awaitBusy(new Predicate() { - @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)); - assertTrue(mappingsResponse.getMappings().containsKey("logstash-2014.03.30")); - assertTrue(mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs")); } } diff --git a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java index 89add3846fb..0ffa4842290 100644 --- a/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java +++ b/src/test/java/org/elasticsearch/cluster/NoMasterNodeTests.java @@ -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() { - 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(); diff --git a/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java b/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java index d4d46db5d0a..d35adf63687 100644 --- a/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java +++ b/src/test/java/org/elasticsearch/common/util/concurrent/EsExecutorsTests.java @@ -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() { - 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(); } } diff --git a/src/test/java/org/elasticsearch/index/fielddata/DisabledFieldDataFormatTests.java b/src/test/java/org/elasticsearch/index/fielddata/DisabledFieldDataFormatTests.java index fad078d33c8..0efe710ea99 100644 --- a/src/test/java/org/elasticsearch/index/fielddata/DisabledFieldDataFormatTests.java +++ b/src/test/java/org/elasticsearch/index/fielddata/DisabledFieldDataFormatTests.java @@ -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() { + assertBusy(new Callable() { @Override - public boolean apply(Object input) { - try { - Set 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; - } - for (String node : nodes) { - IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node); - IndexService indexService = indicesService.indexService("test"); - if (indexService == null) { - return false; - } - final SmartNameFieldMappers mappers = indexService.mapperService().smartName("s"); - if (mappers == null || !mappers.hasMapper()) { - return false; - } - final String currentFormat = mappers.mapper().fieldDataType().getFormat(ImmutableSettings.EMPTY); - if (!format.equals(currentFormat)) { - return false; - } - } - } catch (Exception e) { - logger.info("got exception waiting for concrete mappings", e); - return false; + public Object call() throws Exception { + Set nodes = internalCluster().nodesInclude("test"); + assertFalse(nodes.isEmpty()); + for (String node : nodes) { + IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node); + IndexService indexService = indicesService.indexService("test"); + assertThat(indexService, notNullValue()); + final SmartNameFieldMappers mappers = indexService.mapperService().smartName("s"); + assertThat(mappers, notNullValue()); + assertTrue(mappers.hasMapper()); + final String currentFormat = mappers.mapper().fieldDataType().getFormat(ImmutableSettings.EMPTY); + assertThat(currentFormat, equalTo(format)); } - return true; + return null; } }); - waitNoPendingTasksOnAll(); - logger.info(">> put mapping verified {}, applies {}", format, applied); - if (!applied) { - fail(); - } } } diff --git a/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java b/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java index a394d5f8e12..af97fe72a34 100644 --- a/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java +++ b/src/test/java/org/elasticsearch/indices/mapping/SimpleDeleteMappingTests.java @@ -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() { + assertBusy(new Runnable() { @Override - public boolean apply(Object input) { - GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").setTypes("type1").get(); - ImmutableOpenMap 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"); - } - }