mirror of https://github.com/apache/lucene.git
LUCENE-6559: TimeLimitingCollector should check timeout also when LeafCollector is pulled
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1685507 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e3563120b5
commit
a1876da5ee
|
@ -161,6 +161,9 @@ Bug Fixes
|
|||
* LUCENE-6527: Queries now get a dummy Similarity when scores are not needed
|
||||
in order to not load unnecessary information like norms. (Adrien Grand)
|
||||
|
||||
* LUCENE-6559: TimeLimitingCollector now also checks for timeout when a new
|
||||
leaf reader is pulled ie. if we move from one segment to another even without
|
||||
collecting a hit. (Simon Willnauer)
|
||||
|
||||
======================= Lucene 5.2.0 =======================
|
||||
|
||||
|
|
|
@ -136,6 +136,10 @@ public class TimeLimitingCollector implements Collector {
|
|||
if (Long.MIN_VALUE == t0) {
|
||||
setBaseline();
|
||||
}
|
||||
final long time = clock.get();
|
||||
if (time - timeout > 0L) {
|
||||
throw new TimeExceededException(timeout - t0, time - t0, -1);
|
||||
}
|
||||
return new FilterLeafCollector(collector.getLeafCollector(context)) {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -152,7 +152,7 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
|
|||
e.printStackTrace();
|
||||
assertTrue("Unexpected exception: "+e, false); //==fail
|
||||
}
|
||||
assertEquals( "Wrong number of results!", totalResults, totalTLCResults );
|
||||
assertEquals("Wrong number of results!", totalResults, totalTLCResults);
|
||||
}
|
||||
|
||||
private Collector createTimedCollector(MyHitCollector hc, long timeAllowed, boolean greedy) {
|
||||
|
@ -267,6 +267,24 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
|
|||
counterThread.setResolution(TimerThread.DEFAULT_RESOLUTION);
|
||||
}
|
||||
}
|
||||
|
||||
public void testNoHits() throws IOException {
|
||||
MyHitCollector myHc = new MyHitCollector();
|
||||
Collector collector = createTimedCollector(myHc, -1, random().nextBoolean());
|
||||
// search
|
||||
TimeExceededException timoutException = null;
|
||||
try {
|
||||
BooleanQuery booleanQuery = new BooleanQuery(); // won't match - we only test if we check timeout when collectors are pulled
|
||||
booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "one")), BooleanClause.Occur.MUST);
|
||||
booleanQuery.add(new TermQuery(new Term(FIELD_NAME, "blueberry")), BooleanClause.Occur.MUST);
|
||||
searcher.search(booleanQuery, collector);
|
||||
} catch (TimeExceededException x) {
|
||||
timoutException = x;
|
||||
}
|
||||
// must get exception
|
||||
assertNotNull("Timeout expected!", timoutException);
|
||||
assertEquals(-1, myHc.getLastDocCollected());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test correctness with multiple searching threads.
|
||||
|
|
Loading…
Reference in New Issue