Added ElasticsearchIntegrationTest#ensureSearchable() to prepare indices to be searchable
Currently we sometimes see test failures that fail because not all replicase are `searchable` which means they are not started yet or still recovering. Yet, the usual situation is where two nodes have the same clusterstate but the one that acts as the search target has not yet processed that clusterstate. The requester sees the shard as started but it's not mark as such on the target node. For now the #ensureSearchable() just delegates to #ensureYellow() to make sure the cluster is not red. In the future if we have the possibilty to recover from situations like this in the search logic we can easily test this by making the impl a no-op. Note: this problem only occurs if you have low number of docs and the indexing is really quick such that first request are exectued but shards are not fully `started`
This commit is contained in:
parent
d3fde78394
commit
5771f9083c
|
@ -83,6 +83,7 @@ public class DateHistogramTests extends ElasticsearchIntegrationTest {
|
|||
indexDoc(3, 2, 4), // date: Mar 2, dates: Mar 2, Apr 3
|
||||
indexDoc(3, 15, 5), // date: Mar 15, dates: Mar 15, Apr 16
|
||||
indexDoc(3, 23, 6)); // date: Mar 23, dates: Mar 23, Apr 24
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -828,8 +829,6 @@ public class DateHistogramTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.MONTH))
|
||||
.execute().actionGet();
|
||||
|
@ -845,8 +844,6 @@ public class DateHistogramTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(dateHistogram("histo").field("date").interval(DateHistogram.Interval.MONTH))
|
||||
.execute().actionGet();
|
||||
|
|
|
@ -98,6 +98,7 @@ public class DateRangeTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
indexRandom(true, docs);
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -890,8 +891,6 @@ public class DateRangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped_WithStringDates() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(dateRange("range")
|
||||
.field("date")
|
||||
|
@ -938,8 +937,6 @@ public class DateRangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(dateRange("range")
|
||||
.field("date")
|
||||
|
|
|
@ -82,7 +82,7 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
indexRandom(true, highCardBuilders);
|
||||
|
||||
createIndex("idx_unmapped");
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -544,8 +544,6 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
@ -562,8 +560,6 @@ public class DoubleTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
|
|
@ -84,6 +84,7 @@ public class FilterTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
ensureGreen();
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -96,6 +96,7 @@ public class GeoDistanceTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
|
||||
indexRandom(true, cities);
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -228,8 +229,6 @@ public class GeoDistanceTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(geoDistance("amsterdam_rings")
|
||||
.field("location")
|
||||
|
|
|
@ -79,6 +79,7 @@ public class GlobalTests extends ElasticsearchIntegrationTest {
|
|||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -99,7 +99,7 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
.endObject());
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -708,8 +708,6 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval))
|
||||
.execute().actionGet();
|
||||
|
@ -725,8 +723,6 @@ public class HistogramTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(histogram("histo").field("value").interval(interval))
|
||||
.execute().actionGet();
|
||||
|
|
|
@ -75,7 +75,7 @@ public class IPv4RangeTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, builders);
|
||||
createIndex("idx_unmapped");
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -738,8 +738,6 @@ public class IPv4RangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(ipRange("range")
|
||||
.field("ip")
|
||||
|
@ -786,8 +784,6 @@ public class IPv4RangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped")
|
||||
.addAggregation(ipRange("range")
|
||||
.field("ip")
|
||||
|
|
|
@ -27,7 +27,6 @@ import org.elasticsearch.search.aggregations.bucket.histogram.Histogram;
|
|||
import org.elasticsearch.search.aggregations.bucket.terms.Terms;
|
||||
import org.elasticsearch.search.aggregations.metrics.sum.Sum;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.elasticsearch.test.hamcrest.ElasticsearchAssertions;
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
@ -81,6 +80,7 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, highCardBuilders);
|
||||
createIndex("idx_unmapped");
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -538,8 +538,6 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
@ -556,8 +554,6 @@ public class LongTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped", "idx").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
|
|
@ -88,13 +88,11 @@ public class MissingTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
indexRandom(true, builders.toArray(new IndexRequestBuilder[builders.size()]));
|
||||
ensureGreen(); // wait until we are ready to serve requests
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("unmapped_idx").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("unmapped_idx")
|
||||
.addAggregation(missing("missing_tag").field("tag"))
|
||||
.execute().actionGet();
|
||||
|
@ -110,8 +108,6 @@ public class MissingTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("unmapped_idx").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "unmapped_idx")
|
||||
.addAggregation(missing("missing_tag").field("tag"))
|
||||
.execute().actionGet();
|
||||
|
|
|
@ -98,6 +98,7 @@ public class NestedTests extends ElasticsearchIntegrationTest {
|
|||
builders.add(client().prepareIndex("idx", "type", ""+i+1).setSource(source));
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -141,7 +142,6 @@ public class NestedTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void onNonNestedField() throws Exception {
|
||||
|
||||
try {
|
||||
client().prepareSearch("idx")
|
||||
.addAggregation(nested("nested").path("value")
|
||||
|
@ -156,7 +156,6 @@ public class NestedTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void nestedWithSubTermsAgg() throws Exception {
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx")
|
||||
.addAggregation(nested("nested").path("nested")
|
||||
.subAggregation(terms("values").field("nested.value").size(100)))
|
||||
|
|
|
@ -73,7 +73,7 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, builders);
|
||||
createIndex("idx_unmapped");
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -729,8 +729,6 @@ public class RangeTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped")
|
||||
.addAggregation(range("range")
|
||||
.field("value")
|
||||
|
|
|
@ -65,7 +65,6 @@ public class ShardSizeTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void noShardSize_string() throws Exception {
|
||||
|
||||
client().admin().indices().prepareCreate("idx")
|
||||
.addMapping("type", "key", "type=string,index=not_analyzed")
|
||||
.execute().actionGet();
|
||||
|
@ -348,6 +347,7 @@ public class ShardSizeTermsTests extends ElasticsearchIntegrationTest {
|
|||
assertThat(totalOnOne, is(15l));
|
||||
long totalOnTwo = client().prepareSearch("idx").setTypes("type").setRouting("2").setQuery(matchAllQuery()).execute().actionGet().getHits().getTotalHits();
|
||||
assertThat(totalOnTwo, is(12l));
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
private void indexDoc(String shard, String key, int times, List<IndexRequestBuilder> indexOps) throws Exception {
|
||||
|
|
|
@ -81,7 +81,7 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
}
|
||||
indexRandom(true, highCardBuilders);
|
||||
createIndex("idx_unmapped");
|
||||
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -654,8 +654,6 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void unmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
@ -671,8 +669,6 @@ public class StringTermsTests extends ElasticsearchIntegrationTest {
|
|||
|
||||
@Test
|
||||
public void partiallyUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForYellowStatus().execute().actionGet();
|
||||
|
||||
SearchResponse response = client().prepareSearch("idx", "idx_unmapped").setTypes("type")
|
||||
.addAggregation(terms("terms")
|
||||
.field("value"))
|
||||
|
|
|
@ -72,6 +72,7 @@ public abstract class AbstractNumericTests extends ElasticsearchIntegrationTest
|
|||
.endObject()));
|
||||
}
|
||||
indexRandom(true, builders);
|
||||
ensureSearchable();
|
||||
}
|
||||
|
||||
public abstract void testEmptyAggregation() throws Exception;
|
||||
|
|
|
@ -57,8 +57,6 @@ public class AvgTests extends AbstractNumericTests {
|
|||
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(avg("avg").field("value"))
|
||||
|
|
|
@ -77,8 +77,6 @@ public class ExtendedStatsTests extends AbstractNumericTests {
|
|||
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(extendedStats("stats").field("value"))
|
||||
|
|
|
@ -56,7 +56,6 @@ public class MaxTests extends AbstractNumericTests {
|
|||
}
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
|
|
|
@ -57,8 +57,6 @@ public class MinTests extends AbstractNumericTests {
|
|||
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(min("min").field("value"))
|
||||
|
|
|
@ -64,8 +64,6 @@ public class StatsTests extends AbstractNumericTests {
|
|||
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(stats("stats").field("value"))
|
||||
|
|
|
@ -57,8 +57,6 @@ public class SumTests extends AbstractNumericTests {
|
|||
|
||||
@Test
|
||||
public void testUnmapped() throws Exception {
|
||||
client().admin().cluster().prepareHealth("idx_unmapped").setWaitForGreenStatus().execute().actionGet();
|
||||
|
||||
SearchResponse searchResponse = client().prepareSearch("idx_unmapped")
|
||||
.setQuery(matchAllQuery())
|
||||
.addAggregation(sum("sum").field("value"))
|
||||
|
|
|
@ -438,9 +438,9 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
|||
* It is useful to ensure that all action on the cluster have finished and all shards that were currently relocating
|
||||
* are now allocated and started.
|
||||
*/
|
||||
public ClusterHealthStatus ensureGreen() {
|
||||
public ClusterHealthStatus ensureGreen(String...indices) {
|
||||
ClusterHealthResponse actionGet = client().admin().cluster()
|
||||
.health(Requests.clusterHealthRequest().waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
|
||||
.health(Requests.clusterHealthRequest(indices).waitForGreenStatus().waitForEvents(Priority.LANGUID).waitForRelocatingShards(0)).actionGet();
|
||||
if (actionGet.isTimedOut()) {
|
||||
logger.info("ensureGreen timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint());
|
||||
assertThat("timed out waiting for green state", actionGet.isTimedOut(), equalTo(false));
|
||||
|
@ -480,9 +480,9 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
|||
/**
|
||||
* Ensures the cluster has a yellow state via the cluster health API.
|
||||
*/
|
||||
public ClusterHealthStatus ensureYellow() {
|
||||
public ClusterHealthStatus ensureYellow(String...indices) {
|
||||
ClusterHealthResponse actionGet = client().admin().cluster()
|
||||
.health(Requests.clusterHealthRequest().waitForRelocatingShards(0).waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet();
|
||||
.health(Requests.clusterHealthRequest(indices).waitForRelocatingShards(0).waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet();
|
||||
if (actionGet.isTimedOut()) {
|
||||
logger.info("ensureYellow timed out, cluster state:\n{}\n{}", client().admin().cluster().prepareState().get().getState().prettyPrint(), client().admin().cluster().preparePendingClusterTasks().get().prettyPrint());
|
||||
assertThat("timed out waiting for yellow", actionGet.isTimedOut(), equalTo(false));
|
||||
|
@ -490,6 +490,16 @@ public abstract class ElasticsearchIntegrationTest extends ElasticsearchTestCase
|
|||
return actionGet.getStatus();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Ensures the cluster is in a searchable state for the given indices. This means a searchable copy of each
|
||||
* shard is available on the cluster.
|
||||
*/
|
||||
protected ClusterHealthStatus ensureSearchable(String...indices) {
|
||||
// this is just a temporary thing but it's easier to change if it is encapsulated.
|
||||
return ensureYellow(indices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syntactic sugar for:
|
||||
* <pre>
|
||||
|
|
Loading…
Reference in New Issue