From ec5dbbaf51a620debe5e8a1bb0ad803a177d0702 Mon Sep 17 00:00:00 2001 From: Simon Willnauer Date: Fri, 25 Apr 2014 11:03:22 +0200 Subject: [PATCH] [TEST] Expect all shards failed in SearchWithRandomExceptionsTests --- .../basic/SearchWithRandomExceptionsTests.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java index 692ea605c83..0adca7159b9 100644 --- a/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java +++ b/src/test/java/org/elasticsearch/search/basic/SearchWithRandomExceptionsTests.java @@ -152,7 +152,7 @@ public class SearchWithRandomExceptionsTests extends ElasticsearchIntegrationTes } } - NumShards test = getNumShards("test"); + NumShards numShards = getNumShards("test"); logger.info("Start Refresh"); final RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().get(); // don't assert on failures here final boolean refreshFailed = refreshResponse.getShardFailures().length != 0 || refreshResponse.getFailedShards() != 0; @@ -165,20 +165,20 @@ public class SearchWithRandomExceptionsTests extends ElasticsearchIntegrationTes long expectedResults = added[docToQuery] ? 1 : 0; logger.info("Searching for [test:{}]", English.intToEnglish(docToQuery)); SearchResponse searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchQuery("test", English.intToEnglish(docToQuery))).get(); - logger.info("Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), test.numPrimaries); - if (searchResponse.getSuccessfulShards() == test.numPrimaries && !refreshFailed) { + logger.info("Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); + if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { assertThat(searchResponse.getHits().getTotalHits(), Matchers.equalTo(expectedResults)); } // check match all searchResponse = client().prepareSearch().setTypes("type").setQuery(QueryBuilders.matchAllQuery()).get(); - logger.info("Match all Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), test.numPrimaries); - if (searchResponse.getSuccessfulShards() == test.numPrimaries && !refreshFailed) { + logger.info("Match all Successful shards: [{}] numShards: [{}]", searchResponse.getSuccessfulShards(), numShards.numPrimaries); + if (searchResponse.getSuccessfulShards() == numShards.numPrimaries && !refreshFailed) { assertThat(searchResponse.getHits().getTotalHits(), Matchers.equalTo(numCreated)); } } catch (SearchPhaseExecutionException ex) { - if (expectAllShardsFailed || refreshResponse.getSuccessfulShards() == 0) { - logger.info("expected SearchPhaseException: [{}]", ex.getMessage()); - } else { + logger.info("SearchPhaseException: [{}]", ex.getMessage()); + // if a scheduled refresh or flush fails all shards we see all shards failed here + if (!(expectAllShardsFailed || refreshResponse.getSuccessfulShards() == 0 || ex.getMessage().contains("all shards failed"))) { throw ex; } }