Apache Solr open-source search software
speed up tests to run faster locally
Robert Muir5032ea0010fa
diff --git a/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java b/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.javaindex 0c77fa566ab..7bcbe75b46e 100644--- a/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java+++ b/lucene/core/src/test/org/apache/lucene/analysis/TestGraphTokenizers.java@@ -319,7 +319,7 @@ public class TestGraphTokenizers extends BaseTokenStreamTestCase {};Random random = random();- checkRandomData(random, a, 5, atLeast(1000));+ checkRandomData(random, a, 5, atLeast(100));}}@@ -344,7 +344,7 @@ public class TestGraphTokenizers extends BaseTokenStreamTestCase {};Random random = random();- checkRandomData(random, a, 5, atLeast(1000));+ checkRandomData(random, a, 5, atLeast(100));}}@@ -368,7 +368,7 @@ public class TestGraphTokenizers extends BaseTokenStreamTestCase {};Random random = random();- checkRandomData(random, a, 5, atLeast(1000));+ checkRandomData(random, a, 5, atLeast(100));}}@@ -392,7 +392,7 @@ public class TestGraphTokenizers extends BaseTokenStreamTestCase {};Random random = random();- checkRandomData(random, a, 5, atLeast(1000));+ checkRandomData(random, a, 5, atLeast(100));}}diff --git a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.javaindex f214eb73688..2d294c7993b 100644--- a/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java+++ b/lucene/core/src/test/org/apache/lucene/search/TestMinShouldMatch2.java@@ -44,26 +44,27 @@ import org.apache.lucene.util.BytesRef;import org.apache.lucene.util.LuceneTestCase;import org.apache.lucene.util._TestUtil;import org.apache.lucene.util.LuceneTestCase.SuppressCodecs;+import org.junit.AfterClass;+import org.junit.BeforeClass;/** tests BooleanScorer2's minShouldMatch */@SuppressCodecs({"Lucene40", "Lucene41"})public class TestMinShouldMatch2 extends LuceneTestCase {- Directory dir;- DirectoryReader r;- AtomicReader reader;- IndexSearcher searcher;+ static Directory dir;+ static DirectoryReader r;+ static AtomicReader reader;+ static IndexSearcher searcher;static final String alwaysTerms[] = { "a" };static final String commonTerms[] = { "b", "c", "d" };static final String mediumTerms[] = { "e", "f", "g" };static final String rareTerms[] = { "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z" };- @Override- public void setUp() throws Exception {- super.setUp();+ @BeforeClass+ public static void beforeClass() throws Exception {dir = newDirectory();RandomIndexWriter iw = new RandomIndexWriter(random(), dir);- final int numDocs = 1000;+ final int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {Document doc = new Document();@@ -93,14 +94,17 @@ public class TestMinShouldMatch2 extends LuceneTestCase {});}- @Override- public void tearDown() throws Exception {+ @AfterClass+ public static void afterClass() throws Exception {reader.close();dir.close();- super.tearDown();+ searcher = null;+ reader = null;+ r = null;+ dir = null;}- private void addSome(Document doc, String values[]) {+ private static void addSome(Document doc, String values[]) {List<String> list = Arrays.asList(values);Collections.shuffle(list, random());int howMany = _TestUtil.nextInt(random(), 1, list.size());diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.javaindex 1ee34eeb333..c2f7cd90687 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseDocValuesFormatTestCase.java@@ -1136,7 +1136,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {doc.add(dvField);// index some docs- int numDocs = atLeast(1000);+ int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {idField.setStringValue(Integer.toString(i));long value = _TestUtil.nextLong(random(), minValue, maxValue);@@ -1218,7 +1218,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {doc.add(dvField);// index some docs- int numDocs = atLeast(1000);+ int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {idField.setStringValue(Integer.toString(i));final int length;@@ -1289,7 +1289,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {doc.add(dvField);// index some docs- int numDocs = atLeast(1000);+ int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {idField.setStringValue(Integer.toString(i));final int length;@@ -1801,7 +1801,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);// index some docs- int numDocs = atLeast(1000);+ int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {Document doc = new Document();Field idField = new StringField("id", Integer.toString(i), Field.Store.NO);@@ -1922,7 +1922,7 @@ public abstract class BaseDocValuesFormatTestCase extends LuceneTestCase {RandomIndexWriter writer = new RandomIndexWriter(random(), dir, conf);// index some docs- int numDocs = atLeast(1000);+ int numDocs = atLeast(300);for (int i = 0; i < numDocs; i++) {Document doc = new Document();Field idField = new StringField("id", Integer.toString(i), Field.Store.NO);diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.javaindex 63de145d89f..ac4a69b9c0e 100644--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseTermVectorsFormatTestCase.java@@ -520,7 +520,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {public void testRareVectors() throws IOException {final RandomDocumentFactory docFactory = new RandomDocumentFactory(10, 20);for (Options options : validOptions()) {- final int numDocs = _TestUtil.nextInt(random(), 10, 10000);+ final int numDocs = atLeast(200);final int docWithVectors = random().nextInt(numDocs);final Document emptyDoc = new Document();final Directory dir = newDirectory();@@ -560,7 +560,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {}final Directory dir = newDirectory();final RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- final RandomDocument doc = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 2), _TestUtil.nextInt(random(), 50000, 100000), options);+ final RandomDocument doc = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 2), atLeast(20000), options);writer.addDocument(doc.toDocument());final IndexReader reader = writer.getReader();assertEquals(doc, reader.getTermVectors(0));@@ -575,7 +575,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {for (Options options : validOptions()) {final Directory dir = newDirectory();final RandomIndexWriter writer = new RandomIndexWriter(random(), dir);- final RandomDocument doc = docFactory.newDocument(_TestUtil.nextInt(random(), 500, 1000), 5, options);+ final RandomDocument doc = docFactory.newDocument(atLeast(100), 5, options);writer.addDocument(doc.toDocument());final IndexReader reader = writer.getReader();assertEquals(doc, reader.getTermVectors(0));@@ -614,7 +614,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {public void testRandom() throws IOException {final RandomDocumentFactory docFactory = new RandomDocumentFactory(5, 20);- final int numDocs = _TestUtil.nextInt(random(), 100, 1000);+ final int numDocs = atLeast(100);final RandomDocument[] docs = new RandomDocument[numDocs];for (int i = 0; i < numDocs; ++i) {docs[i] = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 3), _TestUtil.nextInt(random(), 10, 50), randomOptions());@@ -636,7 +636,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {public void testMerge() throws IOException {final RandomDocumentFactory docFactory = new RandomDocumentFactory(5, 20);- final int numDocs = _TestUtil.nextInt(random(), 100, 500);+ final int numDocs = atLeast(100);final int numDeletes = random().nextInt(numDocs);final Set<Integer> deletes = new HashSet<Integer>();while (deletes.size() < numDeletes) {@@ -645,7 +645,7 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {for (Options options : validOptions()) {final RandomDocument[] docs = new RandomDocument[numDocs];for (int i = 0; i < numDocs; ++i) {- docs[i] = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 3), _TestUtil.nextInt(random(), 10, 50), options);+ docs[i] = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 3), atLeast(10), options);}final Directory dir = newDirectory();final RandomIndexWriter writer = new RandomIndexWriter(random(), dir);@@ -677,11 +677,11 @@ public abstract class BaseTermVectorsFormatTestCase extends LuceneTestCase {// don't share mutable datapublic void testClone() throws IOException, InterruptedException {final RandomDocumentFactory docFactory = new RandomDocumentFactory(5, 20);- final int numDocs = _TestUtil.nextInt(random(), 100, 1000);+ final int numDocs = atLeast(100);for (Options options : validOptions()) {final RandomDocument[] docs = new RandomDocument[numDocs];for (int i = 0; i < numDocs; ++i) {- docs[i] = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 3), _TestUtil.nextInt(random(), 10, 50), options);+ docs[i] = docFactory.newDocument(_TestUtil.nextInt(random(), 1, 3), atLeast(10), options);}final Directory dir = newDirectory();final RandomIndexWriter writer = new RandomIndexWriter(random(), dir);diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex 1f8d42a1c0b..447d1e465f5 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -625,7 +625,7 @@ public abstract class LuceneTestCase extends Assert {* is active and {@link #RANDOM_MULTIPLIER}.*/public static boolean rarely(Random random) {- int p = TEST_NIGHTLY ? 10 : 5;+ int p = TEST_NIGHTLY ? 10 : 1;p += (p * Math.log(RANDOM_MULTIPLIER));int min = 100 - Math.min(p, 50); // never more than 50return random.nextInt(100) >= min;diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.javaindex fddb55011d6..3ec2f231b6b 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java@@ -189,7 +189,7 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {return super.toString() + ": " + format.toString() + ", " + dvFormat.toString();}};- } else if ("SimpleText".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 9 && !shouldAvoidCodec("SimpleText"))) {+ } else if ("SimpleText".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 9 && LuceneTestCase.rarely(random) && !shouldAvoidCodec("SimpleText"))) {codec = new SimpleTextCodec();} else if ("CheapBastard".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 8 && !shouldAvoidCodec("CheapBastard") && !shouldAvoidCodec("Lucene41"))) {// we also avoid this codec if Lucene41 is avoided, since thats the postings format it uses.