improve test

the test checks that even though some shards might not be active, search will still work
This commit is contained in:
Shay Banon 2013-07-28 15:23:41 +02:00
parent c30fa15ddf
commit 29cf346f13
1 changed files with 11 additions and 12 deletions

View File

@ -19,22 +19,21 @@
package org.elasticsearch.test.integration.search.basic;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import java.util.Arrays;
import org.elasticsearch.action.admin.indices.refresh.RefreshResponse;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.test.integration.AbstractSharedClusterTest;
import org.junit.Test;
import java.util.Arrays;
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest {
protected int numberOfNodes() {
return 1;
}
@ -45,13 +44,13 @@ public class SearchWhileCreatingIndexTests extends AbstractSharedClusterTest {
*/
@Test
public void searchWhileCreatingIndex() {
cluster().ensureAtMostNumNodes(1); // this test is very fragile with more than one node...
for (int i = 0; i < 20; i++) {
run(prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10)));
run(client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test"));
refresh();
prepareCreate("test").setSettings(settingsBuilder().put("index.number_of_shards", 10));
client().prepareIndex("test", "type1", "id:" + i).setSource("field", "test").execute().actionGet();
RefreshResponse refreshResponse = client().admin().indices().prepareRefresh("test").execute().actionGet();
assertThat(refreshResponse.getSuccessfulShards(), greaterThanOrEqualTo(1)); // at least one shard should be successful when refreshing
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
assertThat("Found unexpected number of hits ShardFailures:" + Arrays.toString(searchResponse.getShardFailures()) + " id: " + i, searchResponse.getHits().totalHits(), equalTo(1l));
assertThat("found unexpected number of hits, shard_failures (we expected to potentially non active ones!):" + Arrays.toString(searchResponse.getShardFailures()) + " id: " + i, searchResponse.getHits().totalHits(), equalTo(1l));
wipeIndex("test");
}
}