Skip to content

Commit

Permalink
test: Index more docs, so that it is less likely the search request
Browse files Browse the repository at this point in the history
does not time out.

Closes #29221
  • Loading branch information
martijnvg committed Apr 12, 2018
1 parent 02ca61c commit df33e0f
Showing 1 changed file with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.script.MockScriptPlugin;
import org.elasticsearch.script.Script;
import org.elasticsearch.script.ScriptType;
import org.elasticsearch.search.aggregations.AggregatorFactories;
import org.elasticsearch.search.query.QueryPhaseExecutionException;
import org.elasticsearch.test.ESIntegTestCase;

import java.util.Collection;
Expand Down Expand Up @@ -57,7 +54,10 @@ protected Settings nodeSettings(int nodeOrdinal) {
}

public void testSimpleTimeout() throws Exception {
client().prepareIndex("test", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
for (int i = 0; i < 32; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("field", "value").get();
}
refresh("test");

SearchResponse searchResponse = client().prepareSearch("test").setTimeout(new TimeValue(10, TimeUnit.MILLISECONDS))
.setQuery(scriptQuery(
Expand All @@ -66,19 +66,19 @@ public void testSimpleTimeout() throws Exception {
.execute().actionGet();
assertThat(searchResponse.isTimedOut(), equalTo(true));
}

public void testPartialResultsIntolerantTimeout() throws Exception {
client().prepareIndex("test", "type", "1").setSource("field", "value").setRefreshPolicy(IMMEDIATE).get();
ElasticsearchException ex = expectThrows(ElasticsearchException.class, () ->

ElasticsearchException ex = expectThrows(ElasticsearchException.class, () ->
client().prepareSearch("test").setTimeout(new TimeValue(10, TimeUnit.MILLISECONDS))
.setQuery(scriptQuery(
new Script(ScriptType.INLINE, "mockscript", SCRIPT_NAME, Collections.emptyMap())))
.setAllowPartialSearchResults(false) // this line causes timeouts to report failures
.execute().actionGet()
.execute().actionGet()
);
assertTrue(ex.toString().contains("Time exceeded"));
}
}

public static class ScriptedTimeoutPlugin extends MockScriptPlugin {
static final String SCRIPT_NAME = "search_timeout";
Expand Down

0 comments on commit df33e0f

Please sign in to comment.