Ensure tests wait for relocations

This commit is contained in:
Simon Willnauer 2013-06-17 13:54:06 +02:00
parent e7d13971f3
commit deda7a37fc
5 changed files with 48 additions and 48 deletions

View File

@ -301,7 +301,7 @@ public abstract class AbstractSharedClusterTest extends ElasticsearchTestCase {
public ClusterHealthStatus ensureYellow() {
ClusterHealthResponse actionGet = client().admin().cluster()
.health(Requests.clusterHealthRequest().waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet();
.health(Requests.clusterHealthRequest().waitForRelocatingShards(0).waitForYellowStatus().waitForEvents(Priority.LANGUID)).actionGet();
assertThat(actionGet.isTimedOut(), equalTo(false));
return actionGet.getStatus();
}

View File

@ -39,10 +39,8 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest {
@Test
public void testMissing() throws Exception {
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test1").execute().actionGet();
ClusterHealthResponse 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();
@ -138,8 +136,7 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest {
client().admin().indices().prepareCreate("test2").execute().actionGet();
clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
ensureYellow();
client().prepareSearch("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
client().prepareCount("test1", "test2").setQuery(QueryBuilders.matchAllQuery()).execute().actionGet();
@ -158,8 +155,7 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest {
public void testAllMissing() throws Exception {
client().admin().indices().prepareDelete().execute().actionGet();
client().admin().indices().prepareCreate("test1").execute().actionGet();
ClusterHealthResponse clusterHealthResponse = client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
assertThat(clusterHealthResponse.isTimedOut(), equalTo(false));
ensureYellow();
try {
client().prepareSearch("test2").setQuery(QueryBuilders.matchAllQuery()).setIgnoreIndices(IgnoreIndices.MISSING).execute().actionGet();
fail("Exception should have been thrown.");
@ -171,7 +167,8 @@ public class IgnoreIndicesTests extends AbstractSharedClusterTest {
fail("Exception should have been thrown.");
} catch (IndexMissingException e) {
}
//you should still be able to run empty searches without things blowing up
client().prepareSearch().setQuery(QueryBuilders.matchAllQuery()).setIgnoreIndices(IgnoreIndices.MISSING).execute().actionGet();
}

View File

@ -43,10 +43,10 @@ public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest {
public void searchWhileCreatingIndex() {
for (int i = 0; i < 20; i++) {
run(prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10)));
run(client().prepareIndex("test", "type1").setSource("field", "test"));
run(client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test"));
refresh();
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
assertThat("Found unexpected number of hits ShardFailures:" + Arrays.toString(searchResponse.getShardFailures()), searchResponse.getHits().totalHits(), equalTo(1l));
assertThat("Found unexpected number of hits ShardFailures:" + Arrays.toString(searchResponse.getShardFailures()) + " id: " + i, searchResponse.getHits().totalHits(), equalTo(1l));
wipeIndex("test");
}
}

View File

@ -906,7 +906,6 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.endObject().endObject()
.endObject().endObject().endObject())
.execute().actionGet();
waitForRelocation();
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").execute().actionGet();
refresh();
@ -944,10 +943,10 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
refresh();
// simple search on body with standard analyzer with a simple field query
SearchResponse search = client().prepareSearch()
@ -983,10 +982,9 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
refresh();
// simple search on body with standard analyzer with a simple field query
SearchResponse search = client().prepareSearch()
@ -1022,10 +1020,9 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1").setSource("title", "this is a test").execute().actionGet();
client().admin().indices().prepareRefresh().execute().actionGet();
refresh();
// simple search on body with standard analyzer with a simple field query
SearchResponse search = client().prepareSearch()
@ -1057,11 +1054,13 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.startObject("title").field("type", "string").field("store", "yes").field("term_vector", "no").endObject()
.endObject().endObject().endObject())
.execute().actionGet();
ensureGreen();
for (int i = 0; i < 5; i++) {
client().prepareIndex("test", "type1", Integer.toString(i))
.setSource("title", "This is a test for the enabling fast vector highlighter").setRefresh(true).execute().actionGet();
}
refresh();
SearchResponse search = client().prepareSearch()
.setQuery(matchPhraseQuery("title", "this is a test"))
@ -1087,13 +1086,13 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.startObject("title").field("type", "string").field("store", "yes").field("term_vector", "with_positions_offsets").endObject()
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
for (int i = 0; i < 5; i++) {
client().prepareIndex("test", "type1", Integer.toString(i))
.setSource("title", "This is a test for the workaround for the fast vector highlighting SOLR-3724").setRefresh(true).execute().actionGet();
.setSource("title", "This is a test for the workaround for the fast vector highlighting SOLR-3724").execute().actionGet();
}
refresh();
SearchResponse search = client().prepareSearch()
.setQuery(matchPhraseQuery("title", "test for the workaround"))
.addHighlightedField("title", 50, 1, 10)
@ -1152,14 +1151,14 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.startObject("tags").field("type", "string").field("term_vector", "with_positions_offsets").endObject()
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1")
.setSource(jsonBuilder().startObject().field("tags",
"this is a really long tag i would like to highlight",
"here is another one that is very long and has the tag token near the end").endObject())
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
SearchResponse response = client().prepareSearch("test")
.setQuery(QueryBuilders.matchQuery("tags", "tag"))
.addHighlightedField("tags", -1, 0)
@ -1173,12 +1172,13 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
@Test
public void testBoostingQuery() {
client().admin().indices().prepareCreate("test").execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
createIndex("test");
ensureGreen();
client().prepareIndex("test", "type1")
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource()
@ -1196,10 +1196,10 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
@Test
public void testBoostingQueryTermVector() throws ElasticSearchException, IOException {
client().admin().indices().prepareCreate("test").addMapping("type1", type1TermVectorMapping()).execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource()
@ -1219,12 +1219,13 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
@Test
public void testCommonTermsQuery() {
client().admin().indices().prepareCreate("test").execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
createIndex("test");
ensureGreen();
client().prepareIndex("test", "type1")
.setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource()
@ -1242,11 +1243,11 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
@Test
public void testCommonTermsTermVector() throws ElasticSearchException, IOException {
client().admin().indices().prepareCreate("test").addMapping("type1", type1TermVectorMapping()).execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1").setSource("field1", "this is a test", "field2", "The quick brown fox jumps over the lazy dog")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
logger.info("--> highlighting and searching on field1");
SearchSourceBuilder source = searchSource().query(commonTerms("field2", "quick brown").cutoffFrequency(100)).from(0).size(60)
.explain(true).highlight(highlight().field("field2").order("score").preTags("<x>").postTags("</x>"));
@ -1279,14 +1280,15 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
client().admin().indices().prepareCreate("test").setSettings(builder.build()).addMapping("type1", type1TermVectorMapping()).addMapping("type2", type2Mapping).execute().actionGet();
client().admin().cluster().prepareHealth("test").setWaitForGreenStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "0")
.setSource("field0", "The quick brown fox jumps over the lazy dog", "field1", "The quick brown fox jumps over the lazy dog")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
client().prepareIndex("test", "type1", "1")
.setSource("field1", "The quick browse button is a fancy thing, right bro?")
.setRefresh(true).execute().actionGet();
.execute().actionGet();
refresh();
logger.info("--> highlighting and searching on field0");
SearchSourceBuilder source = searchSource()
.query(matchPhrasePrefixQuery("field0", "quick bro"))
@ -1366,8 +1368,7 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.startObject("tags").field("type", "string").endObject()
.endObject().endObject().endObject())
.execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForYellowStatus().execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1")
.setSource(jsonBuilder().startObject().field("tags",
"this is a really long tag i would like to highlight",
@ -1412,7 +1413,7 @@ public class HighlighterSearchTests extends AbstractSharedClusterTest {
.startObject("highlight_field").field("type", "string").field("store", "yes").endObject()
.endObject().endObject().endObject())
.execute().actionGet();
ensureGreen();
client().prepareIndex("test", "type1", "1")
.setSource(jsonBuilder().startObject()
.field("field", "highlight")

View File

@ -194,6 +194,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
jsonBuilder().startObject().startObject("type1").startObject("properties").startObject("field1")
.field("analyzer", "whitespace").field("type", "string").endObject().endObject().endObject().endObject())
.setSettings(ImmutableSettings.settingsBuilder()).execute().actionGet();
ensureGreen();
int numDocs = 1000;
for (int i = 0; i < numDocs; i++) {
@ -203,6 +204,7 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
flush();
optimize(); // make sure we don't have a background merge running
refresh();
ensureGreen();
for (int i = 0; i < numDocs; i++) {
String intToEnglish = English.intToEnglish(i);
String query = intToEnglish.split(" ")[0];
@ -221,11 +223,11 @@ public class QueryRescorerTests extends AbstractSharedClusterTest {
.setRescoreQueryWeight(0.0f)) // no weigth - so we basically use the same score as the actual query
.setRescoreWindow(50).execute().actionGet();
SearchResponse plain = client().prepareSearch()
.setPreference("test") // ensure we hit the same shards for tie-breaking
.setQuery(QueryBuilders.matchQuery("field1", query).operator(MatchQueryBuilder.Operator.OR)).setFrom(0).setSize(10)
.execute().actionGet();
// check equivalence
assertEquivalent(plain, rescored);