Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

allow for -1 exceptionDoc, when timeout was hit in getLeafCollector; fix timout -> timeout typo

Michael McCandless8877c9f7b779
diff --git a/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java b/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
index effb73452e2..b2139ed032b 100644
--- a/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
+++ b/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
@@ -114,7 +114,8 @@ public class TimeLimitingCollector implements Collector {
* A non greedy collector, upon a timeout, would throw a {@link TimeExceededException}
* without allowing the wrapped collector to collect current doc. A greedy one would
* first allow the wrapped hit collector to collect current doc and only then
- * throw a {@link TimeExceededException}.
+ * throw a {@link TimeExceededException}. However, if the timeout is detected in
+ * {@link #getLeafCollector} then no current document is collected.
* @see #setGreedy(boolean)
*/
public boolean isGreedy() {
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
index 29724bc7d54..1ec8847fc4e 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
@@ -182,43 +182,47 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
Collector tlCollector = createTimedCollector(myHc, TIME_ALLOWED, greedy);
// search
- TimeExceededException timoutException = null;
+ TimeExceededException timeoutException = null;
try {
search(tlCollector);
} catch (TimeExceededException x) {
- timoutException = x;
+ timeoutException = x;
} catch (Exception e) {
assertTrue("Unexpected exception: "+e, false); //==fail
}
// must get exception
- assertNotNull( "Timeout expected!", timoutException );
+ assertNotNull( "Timeout expected!", timeoutException );
// greediness affect last doc collected
- int exceptionDoc = timoutException.getLastDocCollected();
+ int exceptionDoc = timeoutException.getLastDocCollected();
int lastCollected = myHc.getLastDocCollected();
- assertTrue( "doc collected at timeout must be > 0! or == -1 but was: " + exceptionDoc, exceptionDoc == -1 || exceptionDoc > 0);
- if (greedy) {
- assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" != lastCollected="+lastCollected, exceptionDoc==lastCollected);
- assertTrue("greedy, but no hits found!", myHc.hitCount() > 0 );
- } else {
- assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" not > lastCollected="+lastCollected, exceptionDoc>lastCollected);
+
+ // exceptionDoc == -1 means we hit the timeout in getLeafCollector:
+ if (exceptionDoc != -1) {
+ assertTrue( "doc collected at timeout must be > 0! or == -1 but was: " + exceptionDoc, exceptionDoc > 0);
+ if (greedy) {
+ assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" != lastCollected="+lastCollected, exceptionDoc==lastCollected);
+ assertTrue("greedy, but no hits found!", myHc.hitCount() > 0 );
+ } else {
+ assertTrue("greedy="+greedy+" exceptionDoc="+exceptionDoc+" not > lastCollected="+lastCollected, exceptionDoc>lastCollected);
+ }
}
// verify that elapsed time at exception is within valid limits
- assertEquals( timoutException.getTimeAllowed(), TIME_ALLOWED);
+ assertEquals( timeoutException.getTimeAllowed(), TIME_ALLOWED);
// a) Not too early
- assertTrue ( "elapsed="+timoutException.getTimeElapsed()+" <= (allowed-resolution)="+(TIME_ALLOWED-counterThread.getResolution()),
- timoutException.getTimeElapsed() > TIME_ALLOWED-counterThread.getResolution());
+ assertTrue ( "elapsed="+timeoutException.getTimeElapsed()+" <= (allowed-resolution)="+(TIME_ALLOWED-counterThread.getResolution()),
+ timeoutException.getTimeElapsed() > TIME_ALLOWED-counterThread.getResolution());
// b) Not too late.
// This part is problematic in a busy test system, so we just print a warning.
// We already verified that a timeout occurred, we just can't be picky about how long it took.
- if (timoutException.getTimeElapsed() > maxTime(multiThreaded)) {
+ if (timeoutException.getTimeElapsed() > maxTime(multiThreaded)) {
System.out.println("Informative: timeout exceeded (no action required: most probably just " +
" because the test machine is slower than usual): " +
"lastDoc="+exceptionDoc+
- " ,&& allowed="+timoutException.getTimeAllowed() +
- " ,&& elapsed="+timoutException.getTimeElapsed() +
+ " ,&& allowed="+timeoutException.getTimeAllowed() +
+ " ,&& elapsed="+timeoutException.getTimeElapsed() +
" >= " + maxTimeStr(multiThreaded));
}
}
@@ -272,17 +276,17 @@ public class TestTimeLimitingCollector extends LuceneTestCase {
MyHitCollector myHc = new MyHitCollector();
Collector collector = createTimedCollector(myHc, -1, random().nextBoolean());
// search
- TimeExceededException timoutException = null;
+ TimeExceededException timeoutException = null;
try {
BooleanQuery.Builder booleanQuery = new BooleanQuery.Builder(); // 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.build(), collector);
} catch (TimeExceededException x) {
- timoutException = x;
+ timeoutException = x;
}
// must get exception
- assertNotNull("Timeout expected!", timoutException);
+ assertNotNull("Timeout expected!", timeoutException);
assertEquals(-1, myHc.getLastDocCollected());
}