lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r1044258 - in /lucene/dev/branches/branch_3x/lucene: ./ src/test/org/apache/lucene/index/TestNRTThreads.java
Date Fri, 10 Dec 2010 09:56:27 GMT
Author: mikemccand
Date: Fri Dec 10 09:56:26 2010
New Revision: 1044258

URL: http://svn.apache.org/viewvc?rev=1044258&view=rev
Log:
fix false test failure

Modified:
    lucene/dev/branches/branch_3x/lucene/   (props changed)
    lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java

Modified: lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java?rev=1044258&r1=1044257&r2=1044258&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java
(original)
+++ lucene/dev/branches/branch_3x/lucene/src/test/org/apache/lucene/index/TestNRTThreads.java
Fri Dec 10 09:56:26 2010
@@ -45,6 +45,7 @@ import static org.junit.Assume.*;
 
 // TODO
 //   - mix in optimize, addIndexes
+//   - randomoly mix in non-congruent docs
 
 public class TestNRTThreads extends LuceneTestCase {
 
@@ -207,71 +208,79 @@ public class TestNRTThreads extends Luce
 
       smokeTestReader(r);
 
-      final IndexSearcher s = new IndexSearcher(r);
+      if (r.numDocs() > 0) {
 
-      // run search threads
-      final long searchStopTime = System.currentTimeMillis() + 500;
-      final Thread[] searchThreads = new Thread[NUM_SEARCH_THREADS];
-      final AtomicInteger totHits = new AtomicInteger();
-      for(int thread=0;thread<NUM_SEARCH_THREADS;thread++) {
-        searchThreads[thread] = new Thread() {
-          @Override
-          public void run() {
-            try {
-              TermEnum termEnum = s.getIndexReader().terms(new Term("body", ""));
-              int seenTermCount = 0;
-              int shift;
-              int trigger;
-              if (totTermCount.get() == 0) {
-                shift = 0;
-                trigger = 1;
-              } else {
-                shift = random.nextInt(totTermCount.get()/10);
-                trigger = totTermCount.get()/10;
-              }
-              while(System.currentTimeMillis() < searchStopTime) {
-                Term term = termEnum.term();
-                if (term == null) {
-                  totTermCount.set(seenTermCount);
-                  seenTermCount = 0;
-                  trigger = totTermCount.get()/10;
-                  //System.out.println("trigger " + trigger);
-                  shift = random.nextInt(totTermCount.get()/10);
-                  termEnum = s.getIndexReader().terms(new Term("body", ""));
-                  continue;
-                }
-                seenTermCount++;
-                // search 10 terms
-                if (trigger == 0) {
-                  trigger = 1;
-                }
-                if ((seenTermCount + shift) % trigger == 0) {
-                  //if (VERBOSE) {
-                  //System.out.println(Thread.currentThread().getName() + " now search body:"
+ term.utf8ToString());
-                  //}
-                  totHits.addAndGet(runQuery(s, new TermQuery(term)));
+        final IndexSearcher s = new IndexSearcher(r);
+
+        // run search threads
+        final long searchStopTime = System.currentTimeMillis() + 500;
+        final Thread[] searchThreads = new Thread[NUM_SEARCH_THREADS];
+        final AtomicInteger totHits = new AtomicInteger();
+        for(int thread=0;thread<NUM_SEARCH_THREADS;thread++) {
+          searchThreads[thread] = new Thread() {
+              @Override
+                public void run() {
+                try {
+                  TermEnum termEnum = s.getIndexReader().terms(new Term("body", ""));
+                  int seenTermCount = 0;
+                  int shift;
+                  int trigger;
+                  if (totTermCount.get() == 0) {
+                    shift = 0;
+                    trigger = 1;
+                  } else {
+                    shift = random.nextInt(totTermCount.get()/10);
+                    trigger = totTermCount.get()/10;
+                  }
+                  while(System.currentTimeMillis() < searchStopTime) {
+                    Term term = termEnum.term();
+                    if (term == null) {
+                      if (seenTermCount == 0) {
+                        break;
+                      }
+                      totTermCount.set(seenTermCount);
+                      seenTermCount = 0;
+                      trigger = totTermCount.get()/10;
+                      //System.out.println("trigger " + trigger);
+                      shift = random.nextInt(totTermCount.get()/10);
+                      termEnum = s.getIndexReader().terms(new Term("body", ""));
+                      continue;
+                    }
+                    seenTermCount++;
+                    // search 10 terms
+                    if (trigger == 0) {
+                      trigger = 1;
+                    }
+                    if ((seenTermCount + shift) % trigger == 0) {
+                      //if (VERBOSE) {
+                      //System.out.println(Thread.currentThread().getName() + " now search
body:" + term.utf8ToString());
+                      //}
+                      totHits.addAndGet(runQuery(s, new TermQuery(term)));
+                    }
+                  }
+                  if (VERBOSE) {
+                    System.out.println(Thread.currentThread().getName() + ": search done");
+                  }
+                } catch (Throwable t) {
+                  failed.set(true);
+                  t.printStackTrace(System.out);
+                  throw new RuntimeException(t);
                 }
               }
-              if (VERBOSE) {
-                System.out.println(Thread.currentThread().getName() + ": search done");
-              }
-            } catch (Throwable t) {
-              failed.set(true);
-              t.printStackTrace(System.out);
-              throw new RuntimeException(t);
-            }
-          }
-          };
-        searchThreads[thread].setDaemon(true);
-        searchThreads[thread].start();
-      }
+            };
+          searchThreads[thread].setDaemon(true);
+          searchThreads[thread].start();
+        }
 
-      for(int thread=0;thread<NUM_SEARCH_THREADS;thread++) {
-        searchThreads[thread].join();
-      }
+        for(int thread=0;thread<NUM_SEARCH_THREADS;thread++) {
+          searchThreads[thread].join();
+        }
 
-      if (VERBOSE) {
-        System.out.println("TEST: DONE search: totHits=" + totHits);
+        if (VERBOSE) {
+          System.out.println("TEST: DONE search: totHits=" + totHits);
+        }
+      } else {
+        Thread.sleep(100);
       }
     }
 



Mime
View raw message