mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-09 06:25:07 +00:00
[TEST] move more tests to assertBusy from awaitBusy
This commit is contained in:
parent
0a58781d2d
commit
b301132d7b
@ -21,51 +21,27 @@
|
|||||||
package org.elasticsearch.action.bulk;
|
package org.elasticsearch.action.bulk;
|
||||||
|
|
||||||
import com.google.common.base.Charsets;
|
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.action.admin.indices.mapping.get.GetMappingsResponse;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
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
|
@Test
|
||||||
public void testBulkIndexCreatesMapping() throws Exception {
|
public void testBulkIndexCreatesMapping() throws Exception {
|
||||||
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json");
|
String bulkAction = copyToStringFromClasspath("/org/elasticsearch/action/bulk/bulk-log.json");
|
||||||
BulkRequestBuilder bulkBuilder = new BulkRequestBuilder(client());
|
BulkRequestBuilder bulkBuilder = new BulkRequestBuilder(client());
|
||||||
bulkBuilder.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), true, null, null);
|
bulkBuilder.add(bulkAction.getBytes(Charsets.UTF_8), 0, bulkAction.length(), true, null, null);
|
||||||
bulkBuilder.execute().actionGet();
|
bulkBuilder.get();
|
||||||
awaitBusy(new Predicate<Object>() {
|
assertBusy(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Object input) {
|
public void run() {
|
||||||
try {
|
GetMappingsResponse mappingsResponse = client().admin().indices().prepareGetMappings().get();
|
||||||
GetMappingsResponse mappingsResponse = client().admin().indices().getMappings(new GetMappingsRequest()).get();
|
assertTrue(mappingsResponse.getMappings().containsKey("logstash-2014.03.30"));
|
||||||
return mappingsResponse.getMappings().containsKey("logstash-2014.03.30");
|
assertTrue(mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs"));
|
||||||
} 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));
|
|
||||||
assertTrue(mappingsResponse.getMappings().containsKey("logstash-2014.03.30"));
|
|
||||||
assertTrue(mappingsResponse.getMappings().get("logstash-2014.03.30").containsKey("logs"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -63,13 +63,13 @@ public class NoMasterNodeTests extends ElasticsearchIntegrationTest {
|
|||||||
createIndex("test");
|
createIndex("test");
|
||||||
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
|
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
|
||||||
internalCluster().stopRandomDataNode();
|
internalCluster().stopRandomDataNode();
|
||||||
assertThat(awaitBusy(new Predicate<Object>() {
|
assertBusy(new Runnable() {
|
||||||
public boolean apply(Object o) {
|
@Override
|
||||||
|
public void run() {
|
||||||
ClusterState state = client().admin().cluster().prepareState().setLocal(true).execute().actionGet().getState();
|
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 {
|
try {
|
||||||
client().prepareGet("test", "type1", "1").execute().actionGet();
|
client().prepareGet("test", "type1", "1").execute().actionGet();
|
||||||
|
@ -221,16 +221,13 @@ public class EsExecutorsTests extends ElasticsearchTestCase {
|
|||||||
assertThat("wrong pool size", pool.getPoolSize(), equalTo(max));
|
assertThat("wrong pool size", pool.getPoolSize(), equalTo(max));
|
||||||
assertThat("wrong active size", pool.getActiveCount(), equalTo(max));
|
assertThat("wrong active size", pool.getActiveCount(), equalTo(max));
|
||||||
barrier.await();
|
barrier.await();
|
||||||
awaitBusy(new Predicate<Object>() {
|
assertBusy(new Runnable() {
|
||||||
public boolean apply(Object o) {
|
@Override
|
||||||
return pool.getActiveCount() == 0 && pool.getPoolSize() < max;
|
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();
|
pool.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,12 +31,16 @@ import org.elasticsearch.search.aggregations.AggregationBuilders;
|
|||||||
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
|
import org.elasticsearch.search.aggregations.Aggregator.SubAggCollectionMode;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
||||||
|
import org.hamcrest.Matchers;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.concurrent.Callable;
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFailures;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertFailures;
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
|
||||||
|
import static org.hamcrest.Matchers.equalTo;
|
||||||
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
|
|
||||||
@ClusterScope(randomDynamicTemplates = false)
|
@ClusterScope(randomDynamicTemplates = false)
|
||||||
public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
||||||
@ -119,41 +123,24 @@ public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
|||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).get());
|
.endObject()).get());
|
||||||
logger.info(">> put mapping end {}", format);
|
logger.info(">> put mapping end {}", format);
|
||||||
boolean applied = awaitBusy(new Predicate<Object>() {
|
assertBusy(new Callable<Object>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Object input) {
|
public Object call() throws Exception {
|
||||||
try {
|
Set<String> nodes = internalCluster().nodesInclude("test");
|
||||||
Set<String> nodes = internalCluster().nodesInclude("test");
|
assertFalse(nodes.isEmpty());
|
||||||
if (nodes.isEmpty()) { // we expect at least one node to hold an index, so wait if not allocated yet
|
for (String node : nodes) {
|
||||||
return false;
|
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
|
||||||
}
|
IndexService indexService = indicesService.indexService("test");
|
||||||
for (String node : nodes) {
|
assertThat(indexService, notNullValue());
|
||||||
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, node);
|
final SmartNameFieldMappers mappers = indexService.mapperService().smartName("s");
|
||||||
IndexService indexService = indicesService.indexService("test");
|
assertThat(mappers, notNullValue());
|
||||||
if (indexService == null) {
|
assertTrue(mappers.hasMapper());
|
||||||
return false;
|
final String currentFormat = mappers.mapper().fieldDataType().getFormat(ImmutableSettings.EMPTY);
|
||||||
}
|
assertThat(currentFormat, equalTo(format));
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
return true;
|
return null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
waitNoPendingTasksOnAll();
|
|
||||||
logger.info(">> put mapping verified {}, applies {}", format, applied);
|
|
||||||
if (!applied) {
|
|
||||||
fail();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -67,22 +67,14 @@ public class SimpleDeleteMappingTests extends ElasticsearchIntegrationTest {
|
|||||||
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
|
CountResponse countResponse = client().prepareCount().setQuery(matchAllQuery()).execute().actionGet();
|
||||||
assertThat(countResponse.getCount(), equalTo(0l));
|
assertThat(countResponse.getCount(), equalTo(0l));
|
||||||
}
|
}
|
||||||
|
assertBusy(new Runnable() {
|
||||||
boolean applied = awaitBusy(new Predicate<Object>() {
|
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(Object input) {
|
public void run() {
|
||||||
GetMappingsResponse response = client().admin().indices().prepareGetMappings("test").setTypes("type1").get();
|
GetMappingsResponse response = client().admin().indices().prepareGetMappings().get();
|
||||||
ImmutableOpenMap<String, MappingMetaData> mappings = response.getMappings().get("test");
|
assertTrue(response.getMappings().containsKey("test"));
|
||||||
if (mappings == null) {
|
assertFalse(response.getMappings().get("test").containsKey("type1"));
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return !mappings.containsKey("type1");
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (!applied) {
|
|
||||||
fail("failed to wait for the mapping to be removed from the master cluster state");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user