[TESTS] Make DisabledFieldDataFormatTests less evil.
This commit is contained in:
parent
a4f974dcaa
commit
feefc41127
|
@ -23,32 +23,16 @@ import org.elasticsearch.action.search.SearchPhaseExecutionException;
|
||||||
import org.elasticsearch.action.search.SearchResponse;
|
import org.elasticsearch.action.search.SearchResponse;
|
||||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||||
import org.elasticsearch.index.mapper.MapperService.SmartNameFieldMappers;
|
|
||||||
import org.elasticsearch.index.service.IndexService;
|
|
||||||
import org.elasticsearch.indices.IndicesService;
|
|
||||||
import org.elasticsearch.search.aggregations.AggregationBuilders;
|
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.ElasticsearchSingleNodeTest;
|
||||||
import org.elasticsearch.test.ElasticsearchIntegrationTest.ClusterScope;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.concurrent.Callable;
|
|
||||||
|
|
||||||
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.*;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
|
||||||
|
|
||||||
@ClusterScope(randomDynamicTemplates = false)
|
public class DisabledFieldDataFormatTests extends ElasticsearchSingleNodeTest {
|
||||||
public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int numberOfReplicas() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void test() throws Exception {
|
public void test() throws Exception {
|
||||||
prepareCreate("test").addMapping("type", "s", "type=string").execute().actionGet();
|
createIndex("test", ImmutableSettings.EMPTY, "type", "s", "type=string");
|
||||||
ensureGreen();
|
|
||||||
logger.info("indexing data start");
|
logger.info("indexing data start");
|
||||||
for (int i = 0; i < 10; ++i) {
|
for (int i = 0; i < 10; ++i) {
|
||||||
client().prepareIndex("test", "type", Integer.toString(i)).setSource("s", "value" + i).execute().actionGet();
|
client().prepareIndex("test", "type", Integer.toString(i)).setSource("s", "value" + i).execute().actionGet();
|
||||||
|
@ -57,7 +41,7 @@ public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
final int searchCycles = 1;
|
final int searchCycles = 1;
|
||||||
|
|
||||||
refresh();
|
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||||
|
|
||||||
// disable field data
|
// disable field data
|
||||||
updateFormat("disabled");
|
updateFormat("disabled");
|
||||||
|
@ -97,7 +81,7 @@ public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
||||||
|
|
||||||
// but add more docs and the new segment won't be loaded
|
// but add more docs and the new segment won't be loaded
|
||||||
client().prepareIndex("test", "type", "-1").setSource("s", "value").execute().actionGet();
|
client().prepareIndex("test", "type", "-1").setSource("s", "value").execute().actionGet();
|
||||||
refresh();
|
client().admin().indices().prepareRefresh().execute().actionGet();
|
||||||
for (int i = 0; i < searchCycles; i++) {
|
for (int i = 0; i < searchCycles; i++) {
|
||||||
try {
|
try {
|
||||||
resp = client().prepareSearch("test").setPreference(Integer.toString(i)).addAggregation(AggregationBuilders.terms("t").field("s")
|
resp = client().prepareSearch("test").setPreference(Integer.toString(i)).addAggregation(AggregationBuilders.terms("t").field("s")
|
||||||
|
@ -124,24 +108,6 @@ public class DisabledFieldDataFormatTests extends ElasticsearchIntegrationTest {
|
||||||
.endObject()
|
.endObject()
|
||||||
.endObject()).get());
|
.endObject()).get());
|
||||||
logger.info(">> put mapping end {}", format);
|
logger.info(">> put mapping end {}", format);
|
||||||
assertBusy(new Callable<Object>() {
|
|
||||||
@Override
|
|
||||||
public Object call() throws Exception {
|
|
||||||
Set<String> 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 null;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||||
import org.elasticsearch.cache.recycler.CacheRecycler;
|
import org.elasticsearch.cache.recycler.CacheRecycler;
|
||||||
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
import org.elasticsearch.cache.recycler.PageCacheRecycler;
|
||||||
|
import org.elasticsearch.client.Client;
|
||||||
import org.elasticsearch.client.Requests;
|
import org.elasticsearch.client.Requests;
|
||||||
import org.elasticsearch.cluster.ClusterName;
|
import org.elasticsearch.cluster.ClusterName;
|
||||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||||
|
@ -60,8 +61,8 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cleanup() {
|
static void cleanup() {
|
||||||
assertAcked(Holder.NODE.client().admin().indices().prepareDelete("*").get());
|
assertAcked(client().admin().indices().prepareDelete("*").get());
|
||||||
MetaData metaData = Holder.NODE.client().admin().cluster().prepareState().get().getState().getMetaData();
|
MetaData metaData = client().admin().cluster().prepareState().get().getState().getMetaData();
|
||||||
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
|
assertThat("test leaves persistent cluster metadata behind: " + metaData.persistentSettings().getAsMap(),
|
||||||
metaData.persistentSettings().getAsMap().size(), equalTo(0));
|
metaData.persistentSettings().getAsMap().size(), equalTo(0));
|
||||||
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(),
|
assertThat("test leaves transient cluster metadata behind: " + metaData.transientSettings().getAsMap(),
|
||||||
|
@ -89,6 +90,13 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a client to the single-node cluster.
|
||||||
|
*/
|
||||||
|
public static Client client() {
|
||||||
|
return Holder.NODE.client();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the single test nodes name.
|
* Returns the single test nodes name.
|
||||||
*/
|
*/
|
||||||
|
@ -128,21 +136,36 @@ public abstract class ElasticsearchSingleNodeTest extends ElasticsearchTestCase
|
||||||
* Create a new index on the singleton node with the provided index settings.
|
* Create a new index on the singleton node with the provided index settings.
|
||||||
*/
|
*/
|
||||||
protected static IndexService createIndex(String index, Settings settings) {
|
protected static IndexService createIndex(String index, Settings settings) {
|
||||||
return createIndex(index, settings, null, null);
|
return createIndex(index, settings, null, (XContentBuilder) null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new index on the singleton node with the provided index settings.
|
* Create a new index on the singleton node with the provided index settings.
|
||||||
*/
|
*/
|
||||||
protected static IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) {
|
protected static IndexService createIndex(String index, Settings settings, String type, XContentBuilder mappings) {
|
||||||
CreateIndexRequestBuilder createIndexRequestBuilder = Holder.NODE.client().admin().indices().prepareCreate(index).setSettings(settings);
|
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
|
||||||
if (type != null && mappings != null) {
|
if (type != null && mappings != null) {
|
||||||
createIndexRequestBuilder.addMapping(type, mappings);
|
createIndexRequestBuilder.addMapping(type, mappings);
|
||||||
}
|
}
|
||||||
|
return createIndex(index, createIndexRequestBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new index on the singleton node with the provided index settings.
|
||||||
|
*/
|
||||||
|
protected static IndexService createIndex(String index, Settings settings, String type, Object... mappings) {
|
||||||
|
CreateIndexRequestBuilder createIndexRequestBuilder = client().admin().indices().prepareCreate(index).setSettings(settings);
|
||||||
|
if (type != null && mappings != null) {
|
||||||
|
createIndexRequestBuilder.addMapping(type, mappings);
|
||||||
|
}
|
||||||
|
return createIndex(index, createIndexRequestBuilder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static IndexService createIndex(String index, CreateIndexRequestBuilder createIndexRequestBuilder) {
|
||||||
assertAcked(createIndexRequestBuilder.get());
|
assertAcked(createIndexRequestBuilder.get());
|
||||||
// Wait for the index to be allocated so that cluster state updates don't override
|
// Wait for the index to be allocated so that cluster state updates don't override
|
||||||
// changes that would have been done locally
|
// changes that would have been done locally
|
||||||
ClusterHealthResponse health = Holder.NODE.client().admin().cluster()
|
ClusterHealthResponse health = client().admin().cluster()
|
||||||
.health(Requests.clusterHealthRequest(index).waitForYellowStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
|
.health(Requests.clusterHealthRequest(index).waitForYellowStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
|
||||||
assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW));
|
assertThat(health.getStatus(), lessThanOrEqualTo(ClusterHealthStatus.YELLOW));
|
||||||
assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1));
|
assertThat("Cluster must be a single node cluster", health.getNumberOfDataNodes(), equalTo(1));
|
||||||
|
|
Loading…
Reference in New Issue