use the same client and preference when failing
This commit is contained in:
parent
46753122aa
commit
b092a0dade
|
@ -24,6 +24,7 @@ import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
|||
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
|
||||
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.test.AbstractIntegrationTest;
|
||||
import org.junit.Test;
|
||||
|
@ -89,13 +90,15 @@ public class SearchWhileCreatingIndexTests extends AbstractIntegrationTest {
|
|||
SearchResponse searchResponse = client().prepareSearch("test").setPreference("_primary").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
assertHitCount(searchResponse, 1);
|
||||
// now, let it go to primary or replica, though in a randomized re-creatable manner
|
||||
searchResponse = client().prepareSearch("test").setPreference(randomAsciiOfLength(5)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
String preference = randomAsciiOfLength(5);
|
||||
Client client = client();
|
||||
searchResponse = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
if (searchResponse.getHits().getTotalHits() != 1) {
|
||||
refresh();
|
||||
SearchResponse searchResponseAfterRefresh = client().prepareSearch("test").setPreference(randomAsciiOfLength(5)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
logger.info("hits count mismatch on any shard search failed, post explicit refresh hits are {}", searchResponseAfterRefresh.getHits().getTotalHits());
|
||||
ensureGreen();
|
||||
SearchResponse searchResponseAfterGreen = client().prepareSearch("test").setPreference(randomAsciiOfLength(5)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
SearchResponse searchResponseAfterGreen = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
|
||||
logger.info("hits count mismatch on any shard search failed, post explicit wait for green hits are {}", searchResponseAfterGreen.getHits().getTotalHits());
|
||||
assertHitCount(searchResponse, 1);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue