File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed
main/java/org/elasticsearch/search/internal
test/java/org/elasticsearch/search Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -191,6 +191,12 @@ public boolean hasCancellations() {
191191 return this .cancellable .isEnabled ();
192192 }
193193
194+ public void checkCancelled () {
195+ if (this .cancellable .isEnabled ()) {
196+ this .cancellable .checkCancelled ();
197+ }
198+ }
199+
194200 public void setAggregatedDfs (AggregatedDfs aggregatedDfs ) {
195201 this .aggregatedDfs = aggregatedDfs ;
196202 }
Original file line number Diff line number Diff line change @@ -120,6 +120,25 @@ public void testCancellableCollector() throws IOException {
120120 assertThat (totalHits2 , equalTo (reader .numDocs ()));
121121 }
122122
123+ public void testCheckCancelled () throws IOException {
124+ Runnable cancellation = () -> { throw new TaskCancelledException ("cancelled" ); };
125+ ContextIndexSearcher searcher = new ContextIndexSearcher (
126+ reader ,
127+ IndexSearcher .getDefaultSimilarity (),
128+ IndexSearcher .getDefaultQueryCache (),
129+ IndexSearcher .getDefaultQueryCachingPolicy (),
130+ true
131+ );
132+
133+ searcher .checkCancelled ();
134+
135+ searcher .addQueryCancellation (cancellation );
136+ expectThrows (TaskCancelledException .class , searcher ::checkCancelled );
137+
138+ searcher .removeQueryCancellation (cancellation );
139+ searcher .checkCancelled ();
140+ }
141+
123142 public void testExitableDirectoryReader () throws IOException {
124143 AtomicBoolean cancelled = new AtomicBoolean (true );
125144 Runnable cancellation = () -> {
You can’t perform that action at this time.
0 commit comments