Apache Lucene open-source search software
LUCENE-6559: TimeLimitingCollector should check timeout also when LeafCollector is pulled
Simon Willnauera1876da5eed1
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 4eaf785e13b..b96480d912c 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -161,6 +161,9 @@ Bug Fixes* LUCENE-6527: Queries now get a dummy Similarity when scores are not neededin 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 =======================diff --git a/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java b/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.javaindex 2aa67d105a8..effb73452e2 100644--- a/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java+++ b/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java@@ -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)) {@Overridediff --git a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.javaindex c7b6a0863b6..33c1901a903 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java@@ -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.