mirror of https://github.com/apache/lucene.git
allow for -1 exceptionDoc, when timeout was hit in getLeafCollector; fix timout -> timeout typo
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1686413 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
2a1bab86b9
commit
8877c9f7b7
|
@ -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() {
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue