lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sh...@apache.org
Subject svn commit: r1044099 - /lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
Date Thu, 09 Dec 2010 19:24:16 GMT
Author: shaie
Date: Thu Dec  9 19:24:16 2010
New Revision: 1044099

URL: http://svn.apache.org/viewvc?rev=1044099&view=rev
Log:
Harden TestSearchWithThreads to not fail if machine was slow (3x)

Modified:
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java?rev=1044099&r1=1044098&r2=1044099&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/search/TestSearchWithThreads.java
Thu Dec  9 19:24:16 2010
@@ -66,11 +66,10 @@ public class TestSearchWithThreads exten
     final IndexSearcher s = new IndexSearcher(r);
 
     final AtomicBoolean failed = new AtomicBoolean();
-    final long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
     final AtomicLong netSearch = new AtomicLong();
 
     Thread[] threads = new Thread[NUM_SEARCH_THREADS];
-    for(int threadID=0;threadID<NUM_SEARCH_THREADS;threadID++) {
+    for (int threadID = 0; threadID < NUM_SEARCH_THREADS; threadID++) {
       threads[threadID] = new Thread() {
         TotalHitCountCollector col = new TotalHitCountCollector();
           @Override
@@ -78,6 +77,7 @@ public class TestSearchWithThreads exten
             try {
               long totHits = 0;
               long totSearch = 0;
+              long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
               while(System.currentTimeMillis() < stopAt && !failed.get()) {
                 s.search(new TermQuery(new Term("body", "aaa")), col);
                 totHits += col.getTotalHits();
@@ -85,7 +85,7 @@ public class TestSearchWithThreads exten
                 totHits += col.getTotalHits();
                 totSearch++;
               }
-              assertTrue(totHits > 0);
+              assertTrue(totSearch > 0 && totHits > 0);
               netSearch.addAndGet(totSearch);
             } catch (Exception exc) {
               failed.set(true);
@@ -94,12 +94,16 @@ public class TestSearchWithThreads exten
           }
         };
       threads[threadID].setDaemon(true);
-      threads[threadID].start();
     }
 
-    for(int threadID=0;threadID<NUM_SEARCH_THREADS;threadID++) {
-      threads[threadID].join();
+    for (Thread t : threads) {
+      t.start();
     }
+    
+    for (Thread t : threads) {
+      t.join();
+    }
+
     if (VERBOSE) System.out.println(NUM_SEARCH_THREADS + " threads did " + netSearch.get()
+ " searches");
 
     s.close();



Mime
View raw message