19
19
package org .elasticsearch .search ;
20
20
21
21
import com .carrotsearch .hppc .IntArrayList ;
22
-
23
22
import org .apache .lucene .search .Query ;
24
23
import org .apache .lucene .store .AlreadyClosedException ;
25
24
import org .elasticsearch .action .ActionListener ;
59
58
import org .elasticsearch .script .MockScriptPlugin ;
60
59
import org .elasticsearch .script .Script ;
61
60
import org .elasticsearch .script .ScriptType ;
61
+ import org .elasticsearch .search .aggregations .InternalAggregation ;
62
+ import org .elasticsearch .search .aggregations .MultiBucketConsumerService ;
62
63
import org .elasticsearch .search .aggregations .bucket .global .GlobalAggregationBuilder ;
63
64
import org .elasticsearch .search .aggregations .bucket .terms .TermsAggregationBuilder ;
64
65
import org .elasticsearch .search .aggregations .support .ValueType ;
@@ -155,7 +156,7 @@ protected Settings nodeSettings() {
155
156
return Settings .builder ().put ("search.default_search_timeout" , "5s" ).build ();
156
157
}
157
158
158
- public void testClearOnClose () throws ExecutionException , InterruptedException {
159
+ public void testClearOnClose () {
159
160
createIndex ("index" );
160
161
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
161
162
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -167,7 +168,7 @@ public void testClearOnClose() throws ExecutionException, InterruptedException {
167
168
assertEquals (0 , service .getActiveContexts ());
168
169
}
169
170
170
- public void testClearOnStop () throws ExecutionException , InterruptedException {
171
+ public void testClearOnStop () {
171
172
createIndex ("index" );
172
173
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
173
174
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -179,7 +180,7 @@ public void testClearOnStop() throws ExecutionException, InterruptedException {
179
180
assertEquals (0 , service .getActiveContexts ());
180
181
}
181
182
182
- public void testClearIndexDelete () throws ExecutionException , InterruptedException {
183
+ public void testClearIndexDelete () {
183
184
createIndex ("index" );
184
185
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
185
186
SearchResponse searchResponse = client ().prepareSearch ("index" ).setSize (1 ).setScroll ("1m" ).get ();
@@ -208,7 +209,7 @@ public void testCloseSearchContextOnRewriteException() {
208
209
assertEquals (activeRefs , indexShard .store ().refCount ());
209
210
}
210
211
211
- public void testSearchWhileIndexDeleted () throws IOException , InterruptedException {
212
+ public void testSearchWhileIndexDeleted () throws InterruptedException {
212
213
createIndex ("index" );
213
214
client ().prepareIndex ("index" , "type" , "1" ).setSource ("field" , "value" ).setRefreshPolicy (IMMEDIATE ).get ();
214
215
@@ -443,15 +444,15 @@ protected QueryBuilder doRewrite(QueryRewriteContext queryRewriteContext) {
443
444
}
444
445
445
446
@ Override
446
- protected void doWriteTo (StreamOutput out ) throws IOException {
447
+ protected void doWriteTo (StreamOutput out ) {
447
448
}
448
449
449
450
@ Override
450
- protected void doXContent (XContentBuilder builder , Params params ) throws IOException {
451
+ protected void doXContent (XContentBuilder builder , Params params ) {
451
452
}
452
453
453
454
@ Override
454
- protected Query doToQuery (QueryShardContext context ) throws IOException {
455
+ protected Query doToQuery (QueryShardContext context ) {
455
456
return null ;
456
457
}
457
458
@@ -501,7 +502,6 @@ public void testCanMatch() throws IOException {
501
502
assertFalse (service .canMatch (new ShardSearchLocalRequest (indexShard .shardId (), 1 , SearchType .QUERY_THEN_FETCH ,
502
503
new SearchSourceBuilder ().query (new MatchNoneQueryBuilder ()), Strings .EMPTY_ARRAY , false ,
503
504
new AliasFilter (null , Strings .EMPTY_ARRAY ), 1f , allowPartialSearchResults , null , null )));
504
-
505
505
}
506
506
507
507
public void testCanRewriteToMatchNone () {
@@ -519,7 +519,6 @@ public void testCanRewriteToMatchNone() {
519
519
.suggest (new SuggestBuilder ())));
520
520
assertFalse (SearchService .canRewriteToMatchNone (new SearchSourceBuilder ().query (new TermQueryBuilder ("foo" , "bar" ))
521
521
.suggest (new SuggestBuilder ())));
522
-
523
522
}
524
523
525
524
public void testSetSearchThrottled () {
@@ -568,4 +567,17 @@ public void testExpandSearchThrottled() {
568
567
assertHitCount (client ().prepareSearch ().get (), 0L );
569
568
assertHitCount (client ().prepareSearch ().setIndicesOptions (IndicesOptions .STRICT_EXPAND_OPEN_FORBID_CLOSED ).get (), 1L );
570
569
}
570
+
571
+ public void testCreateReduceContext () {
572
+ final SearchService service = getInstanceFromNode (SearchService .class );
573
+ {
574
+ InternalAggregation .ReduceContext reduceContext = service .createReduceContext (true );
575
+ expectThrows (MultiBucketConsumerService .TooManyBucketsException .class ,
576
+ () -> reduceContext .consumeBucketsAndMaybeBreak (MultiBucketConsumerService .DEFAULT_MAX_BUCKETS + 1 ));
577
+ }
578
+ {
579
+ InternalAggregation .ReduceContext reduceContext = service .createReduceContext (false );
580
+ reduceContext .consumeBucketsAndMaybeBreak (MultiBucketConsumerService .DEFAULT_MAX_BUCKETS + 1 );
581
+ }
582
+ }
571
583
}
0 commit comments