diff --git a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java index c38eedeb155..09c3344db2c 100644 --- a/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java +++ b/src/test/java/org/elasticsearch/test/integration/AbstractSharedClusterTest.java @@ -148,7 +148,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase { for (String name : names) { try { prepareCreate(name).setSettings(getSettings()).execute().actionGet(); - return; + continue; } catch (IndexAlreadyExistsException ex) { wipeIndex(name); } @@ -236,6 +236,13 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase { assertThat(actionGet.isTimedOut(), equalTo(false)); return actionGet.getStatus(); } + + public ClusterHealthStatus ensureYellow() { + ClusterHealthResponse actionGet = client().admin().cluster() + .health(Requests.clusterHealthRequest().waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet(); + assertThat(actionGet.isTimedOut(), equalTo(false)); + return actionGet.getStatus(); + } public static String commaString(Iterable strings) { return Joiner.on(',').join(strings); diff --git a/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java index 4f97683e84f..94a877b59ca 100644 --- a/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java +++ b/src/test/java/org/elasticsearch/test/integration/indices/IgnoreIndicesTests.java @@ -179,20 +179,11 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest { @Test // For now don't handle closed indices public void testClosed() throws Exception { - client().admin().indices().prepareDelete().execute().actionGet(); - - client().admin().indices().prepareCreate("test1").execute().actionGet(); - client().admin().indices().prepareCreate("test2").execute().actionGet(); - - ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); - + createIndex("test1", "test2"); + ensureYellow(); client().prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); - client().admin().indices().prepareClose("test2").execute().actionGet(); - - clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet(); - assertThat(clusterHealthResponse.isTimedOut(), equalTo(false)); + ensureYellow(); try { client().prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet(); diff --git a/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java b/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java index 65f0e02b6f7..144f621cb69 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/sort/SimpleSortTests.java @@ -50,6 +50,7 @@ import org.elasticsearch.common.Priority; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.text.Text; +import org.elasticsearch.common.xcontent.XContentBuilder; import org.elasticsearch.common.xcontent.XContentFactory; import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.sort.SortBuilders; @@ -526,31 +527,18 @@ public class SimpleSortTests extends AbstractSharedClusterTest { @Test public void testSortScript() throws IOException { - String mapping = jsonBuilder().startObject().startObject("profile").field("dynamic", "strict") - .startObject("properties") - .startObject("id").field("type", "integer").field("index", "not_analyzed").field("store", true).endObject() - .startObject("groups_code").startObject("properties").field("type", "integer").field("index", "not_analyzed").endObject().endObject() - .startObject("date").field("type", "date").field("index", "not_analyzed").field("format", "date_time_no_millis").endObject() - .endObject().endObject().endObject().string(); - prepareCreate("test") - .setSettings(randomSettingsBuilder().put("index.number_of_shards", 2).put("index.number_of_replicas", 0)).addMapping("test", mapping); + createIndexMapped("test", "test", "value", "string"); ensureGreen(); - - client().prepareIndex("test", "test", "1").setSource(jsonBuilder().startObject() - .startArray("groups_code").startObject().field("id", 47642).field("date", "2010-08-12T07:54:55Z").endObject().endArray() - .endObject()).execute().actionGet(); - client().prepareIndex("test", "test", "2").setSource(jsonBuilder().startObject() - .startArray("groups_code").startObject().field("id", 47642).field("date", "2010-05-04T12:10:54Z").endObject().endArray() - .endObject()).execute().actionGet(); - client().admin().indices().prepareRefresh("test").execute().actionGet(); - + for (int i = 0; i < 10; i++) { + client().prepareIndex("test", "test", "1").setSource(jsonBuilder().startObject() + .field("value", "" + i).endObject()).execute().actionGet(); + } + refresh(); SearchResponse searchResponse = client().prepareSearch() .setQuery(matchAllQuery()) .addSort(SortBuilders.scriptSort("\u0027\u0027", "string")).setSize(10) .execute().actionGet(); - assertThat("Failures " + Arrays.toString(searchResponse.getShardFailures()), searchResponse.getShardFailures().length, equalTo(0)); - } @Test diff --git a/src/test/java/org/elasticsearch/test/integration/search/stats/SearchStatsTests.java b/src/test/java/org/elasticsearch/test/integration/search/stats/SearchStatsTests.java index c8176d309de..5f85c8f8b50 100644 --- a/src/test/java/org/elasticsearch/test/integration/search/stats/SearchStatsTests.java +++ b/src/test/java/org/elasticsearch/test/integration/search/stats/SearchStatsTests.java @@ -52,6 +52,8 @@ public class SearchStatsTests extends AbstractSharedClusterTest { @Test public void testSimpleStats() throws Exception { + // clear all stats first + client().admin().indices().prepareStats().clear().execute().actionGet(); createIndex("test1"); for (int i = 0; i < 500; i++) { client().prepareIndex("test1", "type", Integer.toString(i)).setSource("field", "value").execute().actionGet();