Search in sources :

Example 1 with CancellableCollector

use of org.elasticsearch.search.query.CancellableCollector in project elasticsearch by elastic.

the class SearchCancellationTests method testCancellableCollector.

public void testCancellableCollector() throws IOException {
    TotalHitCountCollector collector = new TotalHitCountCollector();
    AtomicBoolean cancelled = new AtomicBoolean();
    CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, false, collector);
    final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0));
    leafCollector.collect(0);
    cancelled.set(true);
    leafCollector.collect(1);
    expectThrows(TaskCancelledException.class, () -> cancellableCollector.getLeafCollector(reader.leaves().get(1)));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LeafCollector(org.apache.lucene.search.LeafCollector) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) CancellableCollector(org.elasticsearch.search.query.CancellableCollector)

Example 2 with CancellableCollector

use of org.elasticsearch.search.query.CancellableCollector in project elasticsearch by elastic.

the class SearchCancellationTests method testLowLevelCancellableCollector.

public void testLowLevelCancellableCollector() throws IOException {
    TotalHitCountCollector collector = new TotalHitCountCollector();
    AtomicBoolean cancelled = new AtomicBoolean();
    CancellableCollector cancellableCollector = new CancellableCollector(cancelled::get, true, collector);
    final LeafCollector leafCollector = cancellableCollector.getLeafCollector(reader.leaves().get(0));
    leafCollector.collect(0);
    cancelled.set(true);
    expectThrows(TaskCancelledException.class, () -> leafCollector.collect(1));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LeafCollector(org.apache.lucene.search.LeafCollector) TotalHitCountCollector(org.apache.lucene.search.TotalHitCountCollector) CancellableCollector(org.elasticsearch.search.query.CancellableCollector)

Aggregations

AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 LeafCollector (org.apache.lucene.search.LeafCollector)2 TotalHitCountCollector (org.apache.lucene.search.TotalHitCountCollector)2 CancellableCollector (org.elasticsearch.search.query.CancellableCollector)2