mirror of https://github.com/apache/lucene.git
fix false test failure
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1044257 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
cdf6350cd6
commit
14f4e0475d
|
@ -48,6 +48,7 @@ import static org.junit.Assume.*;
|
|||
|
||||
// TODO
|
||||
// - mix in optimize, addIndexes
|
||||
// - randomoly mix in non-congruent docs
|
||||
|
||||
public class TestNRTThreads extends LuceneTestCase {
|
||||
|
||||
|
@ -216,71 +217,79 @@ public class TestNRTThreads extends LuceneTestCase {
|
|||
|
||||
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 {
|
||||
TermsEnum termsEnum = MultiFields.getTerms(s.getIndexReader(), "body").iterator();
|
||||
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) {
|
||||
BytesRef term = termsEnum.next();
|
||||
if (term == null) {
|
||||
totTermCount.set(seenTermCount);
|
||||
seenTermCount = 0;
|
||||
trigger = totTermCount.get()/10;
|
||||
//System.out.println("trigger " + trigger);
|
||||
shift = random.nextInt(totTermCount.get()/10);
|
||||
termsEnum.seek(new BytesRef(""));
|
||||
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(new Term("body", 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 {
|
||||
TermsEnum termsEnum = MultiFields.getTerms(s.getIndexReader(), "body").iterator();
|
||||
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) {
|
||||
BytesRef term = termsEnum.next();
|
||||
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);
|
||||
termsEnum.seek(new BytesRef(""));
|
||||
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(new Term("body", 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue