21
21
22
22
import org .elasticsearch .ElasticsearchException ;
23
23
import org .elasticsearch .action .search .SearchResponse ;
24
- import org .elasticsearch .action .search .SearchType ;
25
24
import org .elasticsearch .common .settings .Settings ;
26
25
import org .elasticsearch .common .unit .TimeValue ;
27
26
import org .elasticsearch .plugins .Plugin ;
28
27
import org .elasticsearch .script .MockScriptPlugin ;
29
28
import org .elasticsearch .script .Script ;
30
29
import org .elasticsearch .script .ScriptType ;
31
- import org .elasticsearch .search .aggregations .AggregatorFactories ;
32
- import org .elasticsearch .search .query .QueryPhaseExecutionException ;
33
30
import org .elasticsearch .test .ESIntegTestCase ;
34
31
35
32
import java .util .Collection ;
@@ -57,7 +54,10 @@ protected Settings nodeSettings(int nodeOrdinal) {
57
54
}
58
55
59
56
public void testSimpleTimeout () throws Exception {
60
- client ().prepareIndex ("test" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
57
+ for (int i = 0 ; i < 32 ; i ++) {
58
+ client ().prepareIndex ("test" , "type" , Integer .toString (i )).setSource ("field" , "value" ).get ();
59
+ }
60
+ refresh ("test" );
61
61
62
62
SearchResponse searchResponse = client ().prepareSearch ("test" ).setTimeout (new TimeValue (10 , TimeUnit .MILLISECONDS ))
63
63
.setQuery (scriptQuery (
@@ -66,19 +66,19 @@ public void testSimpleTimeout() throws Exception {
66
66
.execute ().actionGet ();
67
67
assertThat (searchResponse .isTimedOut (), equalTo (true ));
68
68
}
69
-
69
+
70
70
public void testPartialResultsIntolerantTimeout () throws Exception {
71
71
client ().prepareIndex ("test" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
72
-
73
- ElasticsearchException ex = expectThrows (ElasticsearchException .class , () ->
72
+
73
+ ElasticsearchException ex = expectThrows (ElasticsearchException .class , () ->
74
74
client ().prepareSearch ("test" ).setTimeout (new TimeValue (10 , TimeUnit .MILLISECONDS ))
75
75
.setQuery (scriptQuery (
76
76
new Script (ScriptType .INLINE , "mockscript" , SCRIPT_NAME , Collections .emptyMap ())))
77
77
.setAllowPartialSearchResults (false ) // this line causes timeouts to report failures
78
- .execute ().actionGet ()
78
+ .execute ().actionGet ()
79
79
);
80
80
assertTrue (ex .toString ().contains ("Time exceeded" ));
81
- }
81
+ }
82
82
83
83
public static class ScriptedTimeoutPlugin extends MockScriptPlugin {
84
84
static final String SCRIPT_NAME = "search_timeout" ;
0 commit comments