Randomized SearchScanTests

This commit is contained in:
Simon Willnauer 2013-09-17 23:29:49 +02:00
parent 1499881c36
commit 81bd1f9fd2
1 changed files with 13 additions and 28 deletions

View File

@ -21,13 +21,14 @@ package org.elasticsearch.search.scan;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import org.apache.lucene.util.LuceneTestCase.Slow; import org.apache.lucene.util.LuceneTestCase.Slow;
import org.elasticsearch.AbstractSharedClusterTest;
import org.elasticsearch.action.index.IndexRequestBuilder;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType; import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.Priority; import org.elasticsearch.common.Priority;
import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.search.SearchHit; import org.elasticsearch.search.SearchHit;
import org.elasticsearch.AbstractSharedClusterTest;
import org.junit.Test; import org.junit.Test;
import java.util.Set; import java.util.Set;
@ -40,40 +41,24 @@ public class SearchScanTests extends AbstractSharedClusterTest {
@Test @Test
@Slow @Slow
// TODO Randomize and reduce execution time
public void testNarrowingQuery() throws Exception { public void testNarrowingQuery() throws Exception {
try { client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", between(1,5))).execute().actionGet();
client().admin().indices().prepareDelete("test").execute().actionGet();
} catch (Exception e) {
// ignore
}
client().admin().indices().prepareCreate("test").setSettings(ImmutableSettings.settingsBuilder().put("index.number_of_shards", 5)).execute().actionGet();
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet(); client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
Set<String> ids = Sets.newHashSet(); Set<String> ids = Sets.newHashSet();
Set<String> expectedIds = Sets.newHashSet(); Set<String> expectedIds = Sets.newHashSet();
IndexRequestBuilder[] builders = new IndexRequestBuilder[atLeast(50)];
for (int i = 0; i < 100; i++) { for (int i = 0; i < builders.length/2; i++) {
expectedIds.add(Integer.toString(i)); expectedIds.add(Integer.toString(i));
client().prepareIndex("test", "tweet", Integer.toString(i)).setSource( builders[i] = client().prepareIndex("test", "tweet", Integer.toString(i)).setSource(
jsonBuilder().startObject().field("user", "kimchy1").field("postDate", System.currentTimeMillis()).field("message", "test").endObject()).execute().actionGet(); jsonBuilder().startObject().field("user", "kimchy1").field("postDate", System.currentTimeMillis()).field("message", "test").endObject());
// make some segments
if (i % 10 == 0) {
client().admin().indices().prepareFlush().execute().actionGet();
}
} }
for (int i = 100; i < 200; i++) { for (int i = builders.length/2; i < builders.length; i++) {
client().prepareIndex("test", "tweet", Integer.toString(i)).setSource( builders[i] = client().prepareIndex("test", "tweet", Integer.toString(i)).setSource(
jsonBuilder().startObject().field("user", "kimchy2").field("postDate", System.currentTimeMillis()).field("message", "test").endObject()).execute().actionGet(); jsonBuilder().startObject().field("user", "kimchy2").field("postDate", System.currentTimeMillis()).field("message", "test").endObject());
// make some segments
if (i % 10 == 0) {
client().admin().indices().prepareFlush().execute().actionGet();
}
} }
indexRandom(true, builders);
client().admin().indices().prepareRefresh().execute().actionGet();
SearchResponse searchResponse = client().prepareSearch() SearchResponse searchResponse = client().prepareSearch()
.setSearchType(SearchType.SCAN) .setSearchType(SearchType.SCAN)
@ -82,12 +67,12 @@ public class SearchScanTests extends AbstractSharedClusterTest {
.setScroll(TimeValue.timeValueMinutes(2)) .setScroll(TimeValue.timeValueMinutes(2))
.execute().actionGet(); .execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(100l)); assertThat(searchResponse.getHits().totalHits(), equalTo((long)builders.length/2));
// start scrolling, until we get not results // start scrolling, until we get not results
while (true) { while (true) {
searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet(); searchResponse = client().prepareSearchScroll(searchResponse.getScrollId()).setScroll(TimeValue.timeValueMinutes(2)).execute().actionGet();
assertThat(searchResponse.getHits().totalHits(), equalTo(100l)); assertThat(searchResponse.getHits().totalHits(), equalTo((long)builders.length/2));
assertThat(searchResponse.getFailedShards(), equalTo(0)); assertThat(searchResponse.getFailedShards(), equalTo(0));
for (SearchHit hit : searchResponse.getHits()) { for (SearchHit hit : searchResponse.getHits()) {
assertThat(hit.id() + "should not exists in the result set", ids.contains(hit.id()), equalTo(false)); assertThat(hit.id() + "should not exists in the result set", ids.contains(hit.id()), equalTo(false));