mirror of https://github.com/apache/lucene.git
Harden TestSearchWithThreads to not fail if machine was slow (trunk)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1044100 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
b24f2e33d7
commit
cdf6350cd6
|
@ -66,11 +66,10 @@ public class TestSearchWithThreads extends LuceneTestCase {
|
||||||
final IndexSearcher s = new IndexSearcher(r);
|
final IndexSearcher s = new IndexSearcher(r);
|
||||||
|
|
||||||
final AtomicBoolean failed = new AtomicBoolean();
|
final AtomicBoolean failed = new AtomicBoolean();
|
||||||
final long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
|
|
||||||
final AtomicLong netSearch = new AtomicLong();
|
final AtomicLong netSearch = new AtomicLong();
|
||||||
|
|
||||||
Thread[] threads = new Thread[NUM_SEARCH_THREADS];
|
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() {
|
threads[threadID] = new Thread() {
|
||||||
TotalHitCountCollector col = new TotalHitCountCollector();
|
TotalHitCountCollector col = new TotalHitCountCollector();
|
||||||
@Override
|
@Override
|
||||||
|
@ -78,6 +77,7 @@ public class TestSearchWithThreads extends LuceneTestCase {
|
||||||
try {
|
try {
|
||||||
long totHits = 0;
|
long totHits = 0;
|
||||||
long totSearch = 0;
|
long totSearch = 0;
|
||||||
|
long stopAt = System.currentTimeMillis() + RUN_TIME_MSEC;
|
||||||
while(System.currentTimeMillis() < stopAt && !failed.get()) {
|
while(System.currentTimeMillis() < stopAt && !failed.get()) {
|
||||||
s.search(new TermQuery(new Term("body", "aaa")), col);
|
s.search(new TermQuery(new Term("body", "aaa")), col);
|
||||||
totHits += col.getTotalHits();
|
totHits += col.getTotalHits();
|
||||||
|
@ -85,7 +85,7 @@ public class TestSearchWithThreads extends LuceneTestCase {
|
||||||
totHits += col.getTotalHits();
|
totHits += col.getTotalHits();
|
||||||
totSearch++;
|
totSearch++;
|
||||||
}
|
}
|
||||||
assertTrue(totHits > 0);
|
assertTrue(totSearch > 0 && totHits > 0);
|
||||||
netSearch.addAndGet(totSearch);
|
netSearch.addAndGet(totSearch);
|
||||||
} catch (Exception exc) {
|
} catch (Exception exc) {
|
||||||
failed.set(true);
|
failed.set(true);
|
||||||
|
@ -94,12 +94,16 @@ public class TestSearchWithThreads extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
threads[threadID].setDaemon(true);
|
threads[threadID].setDaemon(true);
|
||||||
threads[threadID].start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for(int threadID=0;threadID<NUM_SEARCH_THREADS;threadID++) {
|
for (Thread t : threads) {
|
||||||
threads[threadID].join();
|
t.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (Thread t : threads) {
|
||||||
|
t.join();
|
||||||
|
}
|
||||||
|
|
||||||
if (VERBOSE) System.out.println(NUM_SEARCH_THREADS + " threads did " + netSearch.get() + " searches");
|
if (VERBOSE) System.out.println(NUM_SEARCH_THREADS + " threads did " + netSearch.get() + " searches");
|
||||||
|
|
||||||
s.close();
|
s.close();
|
||||||
|
|
Loading…
Reference in New Issue