You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by mi...@apache.org on 2015/06/19 15:40:22 UTC

svn commit: r1686413 - in /lucene/dev/trunk/lucene/core/src: java/org/apache/lucene/search/TimeLimitingCollector.java test/org/apache/lucene/search/TestTimeLimitingCollector.java

Author: mikemccand
Date: Fri Jun 19 13:40:22 2015
New Revision: 1686413

URL: http://svn.apache.org/r1686413
Log:
allow for -1 exceptionDoc, when timeout was hit in getLeafCollector; fix timout -> timeout typo

Modified:
    lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
    lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java

Modified: lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java?rev=1686413&r1=1686412&r2=1686413&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java (original)
+++ lucene/dev/trunk/lucene/core/src/java/org/apache/lucene/search/TimeLimitingCollector.java Fri Jun 19 13:40:22 2015
@@ -114,7 +114,8 @@ public class TimeLimitingCollector imple
    * 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() {

Modified: lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java?rev=1686413&r1=1686412&r2=1686413&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java (original)
+++ lucene/dev/trunk/lucene/core/src/test/org/apache/lucene/search/TestTimeLimitingCollector.java Fri Jun 19 13:40:22 2015
@@ -182,43 +182,47 @@ public class TestTimeLimitingCollector e
     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 e
     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());
   }