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:
Simon Willnauer 2015-06-15 08:19:58 +00:00
parent e3563120b5
commit a1876da5ee
3 changed files with 26 additions and 1 deletions

View File

@ -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 =======================

View File

@ -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

View File

@ -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.