From d5e118d01121d8c38e0adbb387b9a708e32e32bb Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 27 Nov 2014 15:13:15 +0000 Subject: [PATCH] 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 --- .../lucene/index/TestIndexWriterReader.java | 48 +++++++++++-------- .../apache/lucene/util/TestFixedBitSet.java | 5 +- .../lucene/util/BaseBitSetTestCase.java | 2 +- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java index 5021fe8a30c..da088607fb0 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterReader.java @@ -41,10 +41,12 @@ import org.apache.lucene.store.RAMDirectory; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.InfoStream; import org.apache.lucene.util.LuceneTestCase; +import org.apache.lucene.util.LuceneTestCase.SuppressCodecs; import org.apache.lucene.util.TestUtil; import org.apache.lucene.util.ThreadInterruptedException; import org.junit.Test; +@SuppressCodecs("SimpleText") // too slow here public class TestIndexWriterReader extends LuceneTestCase { private final int numThreads = TEST_NIGHTLY ? 5 : 3; @@ -355,6 +357,7 @@ public class TestIndexWriterReader extends LuceneTestCase { dir1.close(); } + @Slow public void testAddIndexesAndDoDeletesThreads() throws Throwable { final int numIter = 2; int numDirs = 3; @@ -626,7 +629,7 @@ public class TestIndexWriterReader extends LuceneTestCase { ((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++) { writer.addDocument(DocHelper.createDocument(i, "test", 4)); } @@ -705,6 +708,7 @@ public class TestIndexWriterReader extends LuceneTestCase { } // Stress test reopen during addIndexes + @Nightly public void testDuringAddIndexes() throws Exception { Directory dir1 = getAssertNoDeletesDirectory(newDirectory()); final IndexWriter writer = new IndexWriter( @@ -724,19 +728,20 @@ public class TestIndexWriterReader extends LuceneTestCase { DirectoryReader r = writer.getReader(); - final float SECONDS = 0.5f; - - final long endTime = (long) (System.currentTimeMillis() + 1000.*SECONDS); + final int numIterations = 10; final List excs = Collections.synchronizedList(new ArrayList()); // Only one thread can addIndexes at a time, because // IndexWriter acquires a write lock in each directory: final Thread[] threads = new Thread[1]; + final AtomicBoolean threadDone = new AtomicBoolean(false); for(int i=0;i= 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 excs = Collections.synchronizedList(new ArrayList()); final Thread[] threads = new Thread[numThreads]; + final AtomicInteger remainingThreads = new AtomicInteger(numThreads); for(int i=0;i 0) { DirectoryReader r2 = DirectoryReader.openIfChanged(r); if (r2 != null) { r.close(); 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 { // large enough to flush obvious bugs, small enough to run in <.5 sec as part of a // larger testsuite. public void testSmall() throws IOException { - doRandomSets(atLeast(1200), atLeast(1000), 1); - doRandomSets(atLeast(1200), atLeast(1000), 2); + final int iters = TEST_NIGHTLY ? atLeast(1000) : 100; + doRandomSets(atLeast(1200), iters, 1); + doRandomSets(atLeast(1200), iters, 2); } // uncomment to run a bigger test (~2 minutes). diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/BaseBitSetTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/BaseBitSetTestCase.java index 661998b0dab..b61971bfe32 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/BaseBitSetTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/BaseBitSetTestCase.java @@ -176,7 +176,7 @@ public abstract class BaseBitSetTestCase extends LuceneTestCas final int numBits = 1 + random().nextInt(100000); BitSet set1 = new JavaUtilBitSet(randomSet(numBits, 0), 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) { // make extreme percents more likely float percentSet2 = rarely() ? 0 : (float) Math.pow(random().nextDouble(), 2);