speed up tests and make some of these actually reproducible

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1642171 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-11-27 15:13:15 +00:00
parent aee51c5eb0
commit d5e118d011
3 changed files with 31 additions and 24 deletions

View File

@ -41,10 +41,12 @@ import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.InfoStream; import org.apache.lucene.util.InfoStream;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;
import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.ThreadInterruptedException; import org.apache.lucene.util.ThreadInterruptedException;
import org.junit.Test; import org.junit.Test;
@SuppressCodecs("SimpleText") // too slow here
public class TestIndexWriterReader extends LuceneTestCase { public class TestIndexWriterReader extends LuceneTestCase {
private final int numThreads = TEST_NIGHTLY ? 5 : 3; private final int numThreads = TEST_NIGHTLY ? 5 : 3;
@ -355,6 +357,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
dir1.close(); dir1.close();
} }
@Slow
public void testAddIndexesAndDoDeletesThreads() throws Throwable { public void testAddIndexesAndDoDeletesThreads() throws Throwable {
final int numIter = 2; final int numIter = 2;
int numDirs = 3; int numDirs = 3;
@ -626,7 +629,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2); ((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(2);
int num = atLeast(100); int num = TEST_NIGHTLY ? atLeast(100) : atLeast(10);
for (int i = 0; i < num; i++) { for (int i = 0; i < num; i++) {
writer.addDocument(DocHelper.createDocument(i, "test", 4)); writer.addDocument(DocHelper.createDocument(i, "test", 4));
} }
@ -705,6 +708,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
} }
// Stress test reopen during addIndexes // Stress test reopen during addIndexes
@Nightly
public void testDuringAddIndexes() throws Exception { public void testDuringAddIndexes() throws Exception {
Directory dir1 = getAssertNoDeletesDirectory(newDirectory()); Directory dir1 = getAssertNoDeletesDirectory(newDirectory());
final IndexWriter writer = new IndexWriter( final IndexWriter writer = new IndexWriter(
@ -724,19 +728,20 @@ public class TestIndexWriterReader extends LuceneTestCase {
DirectoryReader r = writer.getReader(); DirectoryReader r = writer.getReader();
final float SECONDS = 0.5f; final int numIterations = 10;
final long endTime = (long) (System.currentTimeMillis() + 1000.*SECONDS);
final List<Throwable> excs = Collections.synchronizedList(new ArrayList<Throwable>()); final List<Throwable> excs = Collections.synchronizedList(new ArrayList<Throwable>());
// Only one thread can addIndexes at a time, because // Only one thread can addIndexes at a time, because
// IndexWriter acquires a write lock in each directory: // IndexWriter acquires a write lock in each directory:
final Thread[] threads = new Thread[1]; final Thread[] threads = new Thread[1];
final AtomicBoolean threadDone = new AtomicBoolean(false);
for(int i=0;i<threads.length;i++) { for(int i=0;i<threads.length;i++) {
threads[i] = new Thread() { threads[i] = new Thread() {
@Override @Override
public void run() { public void run() {
int count = 0;
do { do {
count++;
try { try {
writer.addIndexes(dirs); writer.addIndexes(dirs);
writer.maybeMerge(); writer.maybeMerge();
@ -744,7 +749,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
excs.add(t); excs.add(t);
throw new RuntimeException(t); throw new RuntimeException(t);
} }
} while(System.currentTimeMillis() < endTime); } while(count < numIterations);
threadDone.set(true);
} }
}; };
threads[i].setDaemon(true); threads[i].setDaemon(true);
@ -752,17 +758,17 @@ public class TestIndexWriterReader extends LuceneTestCase {
} }
int lastCount = 0; int lastCount = 0;
while(System.currentTimeMillis() < endTime) { while(threadDone.get() == false) {
DirectoryReader r2 = DirectoryReader.openIfChanged(r); DirectoryReader r2 = DirectoryReader.openIfChanged(r);
if (r2 != null) { if (r2 != null) {
r.close(); r.close();
r = r2; r = r2;
Query q = new TermQuery(new Term("indexname", "test"));
IndexSearcher searcher = newSearcher(r);
final int count = searcher.search(q, 10).totalHits;
assertTrue(count >= lastCount);
lastCount = count;
} }
Query q = new TermQuery(new Term("indexname", "test"));
IndexSearcher searcher = newSearcher(r);
final int count = searcher.search(q, 10).totalHits;
assertTrue(count >= lastCount);
lastCount = count;
} }
for(int i=0;i<threads.length;i++) { for(int i=0;i<threads.length;i++) {
@ -813,12 +819,11 @@ public class TestIndexWriterReader extends LuceneTestCase {
DirectoryReader r = writer.getReader(); DirectoryReader r = writer.getReader();
final float SECONDS = 0.5f; final int iters = TEST_NIGHTLY ? 1000 : 10;
final long endTime = (long) (System.currentTimeMillis() + 1000.*SECONDS);
final List<Throwable> excs = Collections.synchronizedList(new ArrayList<Throwable>()); final List<Throwable> excs = Collections.synchronizedList(new ArrayList<Throwable>());
final Thread[] threads = new Thread[numThreads]; final Thread[] threads = new Thread[numThreads];
final AtomicInteger remainingThreads = new AtomicInteger(numThreads);
for(int i=0;i<numThreads;i++) { for(int i=0;i<numThreads;i++) {
threads[i] = new Thread() { threads[i] = new Thread() {
final Random r = new Random(random().nextLong()); final Random r = new Random(random().nextLong());
@ -841,7 +846,8 @@ public class TestIndexWriterReader extends LuceneTestCase {
excs.add(t); excs.add(t);
throw new RuntimeException(t); throw new RuntimeException(t);
} }
} while(System.currentTimeMillis() < endTime); } while(count < iters);
remainingThreads.decrementAndGet();
} }
}; };
threads[i].setDaemon(true); threads[i].setDaemon(true);
@ -849,15 +855,15 @@ public class TestIndexWriterReader extends LuceneTestCase {
} }
int sum = 0; int sum = 0;
while(System.currentTimeMillis() < endTime) { while(remainingThreads.get() > 0) {
DirectoryReader r2 = DirectoryReader.openIfChanged(r); DirectoryReader r2 = DirectoryReader.openIfChanged(r);
if (r2 != null) { if (r2 != null) {
r.close(); r.close();
r = r2; r = r2;
Query q = new TermQuery(new Term("indexname", "test"));
IndexSearcher searcher = newSearcher(r);
sum += searcher.search(q, 10).totalHits;
} }
Query q = new TermQuery(new Term("indexname", "test"));
IndexSearcher searcher = newSearcher(r);
sum += searcher.search(q, 10).totalHits;
} }
for(int i=0;i<numThreads;i++) { for(int i=0;i<numThreads;i++) {
@ -977,7 +983,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
assertTrue(didWarm.get()); assertTrue(didWarm.get());
} }
public void testSimpleMergedSegmentWramer() throws Exception { public void testSimpleMergedSegmentWarmer() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
final AtomicBoolean didWarm = new AtomicBoolean(); final AtomicBoolean didWarm = new AtomicBoolean();
InfoStream infoStream = new InfoStream() { InfoStream infoStream = new InfoStream() {
@ -1111,7 +1117,7 @@ public class TestIndexWriterReader extends LuceneTestCase {
/** Make sure if all we do is open NRT reader against /** Make sure if all we do is open NRT reader against
* writer, we don't see merge starvation. */ * writer, we don't see merge starvation. */
public void testTooManySegments() throws Exception { public void testTooManySegments() throws Exception {
Directory dir = getAssertNoDeletesDirectory(newDirectory()); Directory dir = getAssertNoDeletesDirectory(new RAMDirectory());
// Don't use newIndexWriterConfig, because we need a // Don't use newIndexWriterConfig, because we need a
// "sane" mergePolicy: // "sane" mergePolicy:
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random())); IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));

View File

@ -208,8 +208,9 @@ public class TestFixedBitSet extends BaseBitSetTestCase<FixedBitSet> {
// large enough to flush obvious bugs, small enough to run in <.5 sec as part of a // large enough to flush obvious bugs, small enough to run in <.5 sec as part of a
// larger testsuite. // larger testsuite.
public void testSmall() throws IOException { public void testSmall() throws IOException {
doRandomSets(atLeast(1200), atLeast(1000), 1); final int iters = TEST_NIGHTLY ? atLeast(1000) : 100;
doRandomSets(atLeast(1200), atLeast(1000), 2); doRandomSets(atLeast(1200), iters, 1);
doRandomSets(atLeast(1200), iters, 2);
} }
// uncomment to run a bigger test (~2 minutes). // uncomment to run a bigger test (~2 minutes).

View File

@ -176,7 +176,7 @@ public abstract class BaseBitSetTestCase<T extends BitSet> extends LuceneTestCas
final int numBits = 1 + random().nextInt(100000); final int numBits = 1 + random().nextInt(100000);
BitSet set1 = new JavaUtilBitSet(randomSet(numBits, 0), numBits); BitSet set1 = new JavaUtilBitSet(randomSet(numBits, 0), numBits);
T set2 = copyOf(set1, numBits); T set2 = copyOf(set1, numBits);
final int iters = 50 + random().nextInt(50); final int iters = TEST_NIGHTLY ? 50 + random().nextInt(50) : 10 + random().nextInt(10);
for (int i = 0; i < iters; ++i) { for (int i = 0; i < iters; ++i) {
// make extreme percents more likely // make extreme percents more likely
float percentSet2 = rarely() ? 0 : (float) Math.pow(random().nextDouble(), 2); float percentSet2 = rarely() ? 0 : (float) Math.pow(random().nextDouble(), 2);