Skip to content

Apache Lucene open-source search software

LUCENE-2659: LuceneTestCase ease of use improvements

Robert Muirf68b4b4adb1f
diff --git a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
index 9b708608692..dd2403dd9c6 100644
--- a/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
+++ b/lucene/contrib/misc/src/test/org/apache/lucene/misc/TestHighFreqTerms.java
@@ -36,12 +36,10 @@ public class TestHighFreqTerms extends LuceneTestCase {
private static IndexWriter writer =null;
private static Directory dir = null;
private static IndexReader reader =null;
- private static Random random = null;
@BeforeClass
public static void setUpClass() throws Exception {
- random = newStaticRandom(TestHighFreqTerms.class);
- dir = newDirectory(random);
+ dir = newDirectory();
writer = new IndexWriter(dir, newIndexWriterConfig(random,
TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.WHITESPACE, false))
.setMaxBufferedDocs(2));
diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
index 29a52b99e2b..9dae3b5986b 100644
--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteCachingWrapperFilter.java
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
* limitations under the License.
*/
-import java.util.Random;
-
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -41,20 +39,19 @@ public class TestRemoteCachingWrapperFilter extends RemoteTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
// construct an index
- Random random = newStaticRandom(TestRemoteCachingWrapperFilter.class);
- indexStore = newDirectory(random);
- IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,
+ indexStore = newDirectory();
+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
- doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField(random, "type", "A", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("type", "A", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
//Need a second document to search for
doc = new Document();
- doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField(random, "type", "B", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("type", "B", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
writer.optimize();
writer.close();
diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
index b8c577aea1f..101220a98df 100644
--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSearchable.java
@@ -29,7 +29,6 @@ import org.junit.Test;
import static org.junit.Assert.*;
import java.util.Collections;
-import java.util.Random;
import java.util.Set;
import java.util.HashSet;
@@ -40,13 +39,12 @@ public class TestRemoteSearchable extends RemoteTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
// construct an index
- Random random = newStaticRandom(TestRemoteSearchable.class);
- indexStore = newDirectory(random);
- IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,
+ indexStore = newDirectory();
+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer()));
Document doc = new Document();
- doc.add(newField(random, "test", "test text", Field.Store.YES, Field.Index.ANALYZED));
- doc.add(newField(random, "other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("test", "test text", Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("other", "other test text", Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
writer.optimize();
writer.close();
diff --git a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
index 1798a55d94d..7da14d8bc43 100644
--- a/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
+++ b/lucene/contrib/remote/src/test/org/apache/lucene/search/TestRemoteSort.java
@@ -83,9 +83,8 @@ public class TestRemoteSort extends RemoteTestCase {
// create an index of all the documents, or just the x, or just the y documents
@BeforeClass
public static void beforeClass() throws Exception {
- Random random = newStaticRandom(TestRemoteSort.class);
- indexStore = newDirectory(random);
- IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(random,
+ indexStore = newDirectory();
+ IndexWriter writer = new IndexWriter(indexStore, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(2));
((LogMergePolicy) writer.getConfig().getMergePolicy()).setMergeFactor(1000);
diff --git a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
index 91dca227f8c..5c82159a3d4 100644
--- a/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
+++ b/lucene/src/test/org/apache/lucene/search/BaseTestRangeFilter.java
@@ -94,7 +94,6 @@ public class BaseTestRangeFilter extends LuceneTestCase {
@BeforeClass
public static void beforeClassBaseTestRangeFilter() throws Exception {
- Random random = newStaticRandom(BaseTestRangeFilter.class);
signedIndexDir = new TestIndex(random, Integer.MAX_VALUE, Integer.MIN_VALUE, true);
unsignedIndexDir = new TestIndex(random, Integer.MAX_VALUE, 0, false);
signedIndexReader = build(random, signedIndexDir);
diff --git a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
index 34cab5c1075..aa578ef84fa 100644
--- a/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
+++ b/lucene/src/test/org/apache/lucene/search/TestBoolean2.java
@@ -55,12 +55,11 @@ public class TestBoolean2 extends LuceneTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
- Random random = newStaticRandom(TestBoolean2.class);
- directory = newDirectory(random);
+ directory = newDirectory();
RandomIndexWriter writer= new RandomIndexWriter(random, directory);
for (int i = 0; i < docFields.length; i++) {
Document doc = new Document();
- doc.add(newField(random, field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField(field, docFields[i], Field.Store.NO, Field.Index.ANALYZED));
writer.addDocument(doc);
}
writer.close();
@@ -82,15 +81,15 @@ public class TestBoolean2 extends LuceneTestCase {
} while(docCount < 3000);
RandomIndexWriter w = new RandomIndexWriter(random, dir2,
- newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+ newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
Document doc = new Document();
- doc.add(newField(random, "field2", "xxx", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("field2", "xxx", Field.Store.NO, Field.Index.ANALYZED));
for(int i=0;i<NUM_EXTRA_DOCS/2;i++) {
w.addDocument(doc);
}
doc = new Document();
- doc.add(newField(random, "field2", "big bad bug", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("field2", "big bad bug", Field.Store.NO, Field.Index.ANALYZED));
for(int i=0;i<NUM_EXTRA_DOCS/2;i++) {
w.addDocument(doc);
}
diff --git a/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java b/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
index f5f9ec46483..2c99fb27a80 100644
--- a/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
+++ b/lucene/src/test/org/apache/lucene/search/TestMultiTermConstantScore.java
@@ -34,7 +34,6 @@ import static org.junit.Assert.*;
import java.io.IOException;
import java.text.Collator;
import java.util.Locale;
-import java.util.Random;
import junit.framework.Assert;
@@ -60,20 +59,18 @@ public class TestMultiTermConstantScore extends BaseTestRangeFilter {
"B 2 4 5 6", "Y 3 5 6", null, "C 3 6",
"X 4 5 6" };
- Random random = newStaticRandom(TestMultiTermConstantScore.class);
-
- small = newDirectory(random);
+ small = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, small, new MockAnalyzer(MockTokenizer.WHITESPACE, false));
for (int i = 0; i < data.length; i++) {
Document doc = new Document();
- doc.add(newField(random, "id", String.valueOf(i), Field.Store.YES,
+ doc.add(newField("id", String.valueOf(i), Field.Store.YES,
Field.Index.NOT_ANALYZED));// Field.Keyword("id",String.valueOf(i)));
doc
- .add(newField(random, "all", "all", Field.Store.YES,
+ .add(newField("all", "all", Field.Store.YES,
Field.Index.NOT_ANALYZED));// Field.Keyword("all","all"));
if (null != data[i]) {
- doc.add(newField(random, "data", data[i], Field.Store.YES,
+ doc.add(newField("data", data[i], Field.Store.YES,
Field.Index.ANALYZED));// Field.Text("data",data[i]));
}
writer.addDocument(doc);
diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
index 7848ad12e96..8b507700f2f 100644
--- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
+++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery32.java
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
* limitations under the License.
*/
-import java.util.Random;
-
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -49,14 +47,12 @@ public class TestNumericRangeQuery32 extends LuceneTestCase {
private static Directory directory = null;
private static IndexReader reader = null;
private static IndexSearcher searcher = null;
- private static Random random = null;
@BeforeClass
public static void beforeClass() throws Exception {
- random = newStaticRandom(TestNumericRangeQuery32.class);
- directory = newDirectory(random);
+ directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory,
- newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+ newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
NumericField
diff --git a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
index 151e9ed6716..73caa4c825b 100644
--- a/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
+++ b/lucene/src/test/org/apache/lucene/search/TestNumericRangeQuery64.java
@@ -17,8 +17,6 @@ package org.apache.lucene.search;
* limitations under the License.
*/
-import java.util.Random;
-
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -48,14 +46,12 @@ public class TestNumericRangeQuery64 extends LuceneTestCase {
private static Directory directory = null;
private static IndexReader reader = null;
private static IndexSearcher searcher = null;
- private static Random random = null;
@BeforeClass
public static void beforeClass() throws Exception {
- random = newStaticRandom(TestNumericRangeQuery64.class);
- directory = newDirectory(random);
+ directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory,
- newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer())
+ newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer())
.setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
NumericField
diff --git a/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java b/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java
index d4e5053c600..cafe41dd620 100644
--- a/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java
+++ b/lucene/src/test/org/apache/lucene/search/TestSubScorerFreqs.java
@@ -41,18 +41,17 @@ public class TestSubScorerFreqs extends LuceneTestCase {
@BeforeClass
public static void makeIndex() throws Exception {
dir = new RAMDirectory();
- Random random = newStaticRandom(TestSubScorerFreqs.class);
RandomIndexWriter w = new RandomIndexWriter(
random, dir);
// make sure we have more than one segment occationally
for (int i = 0; i < 31 * RANDOM_MULTIPLIER; i++) {
Document doc = new Document();
- doc.add(newField(random, "f", "a b c d b c d c d d", Field.Store.NO,
+ doc.add(newField("f", "a b c d b c d c d d", Field.Store.NO,
Field.Index.ANALYZED));
w.addDocument(doc);
doc = new Document();
- doc.add(newField(random, "f", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
+ doc.add(newField("f", "a b c d", Field.Store.NO, Field.Index.ANALYZED));
w.addDocument(doc);
}
diff --git a/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java b/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java
index bcd7bbdb3fd..c1a9581c000 100644
--- a/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java
+++ b/lucene/src/test/org/apache/lucene/search/spans/TestBasics.java
@@ -18,7 +18,6 @@ package org.apache.lucene.search.spans;
*/
import java.io.IOException;
-import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer;
@@ -65,15 +64,14 @@ public class TestBasics extends LuceneTestCase {
@BeforeClass
public static void beforeClass() throws Exception {
- Random random = newStaticRandom(TestBasics.class);
- directory = newDirectory(random);
+ directory = newDirectory();
RandomIndexWriter writer = new RandomIndexWriter(random, directory,
- newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true))
+ newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(MockTokenizer.SIMPLE, true))
.setMaxBufferedDocs(_TestUtil.nextInt(random, 50, 1000)));
//writer.infoStream = System.out;
for (int i = 0; i < 1000; i++) {
Document doc = new Document();
- doc.add(newField(random, "field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
+ doc.add(newField("field", English.intToEnglish(i), Field.Store.YES, Field.Index.ANALYZED));
writer.addDocument(doc);
}
reader = writer.getReader();
diff --git a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
index d319c9a9b20..db757810a25 100644
--- a/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
+++ b/lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
@@ -77,6 +77,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Random;
import java.util.TimeZone;
+import java.util.UUID;
import java.util.WeakHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -217,7 +218,7 @@ public abstract class LuceneTestCase extends Assert {
final boolean codecHasParam;
int codecParam = 0;
if (codec.equals("random")) {
- codec = pickRandomCodec(seedRnd);
+ codec = pickRandomCodec(random);
codecHasParam = false;
} else {
Matcher m = codecWithParam.matcher(codec);
@@ -241,10 +242,10 @@ public abstract class LuceneTestCase extends Assert {
}
swapCodec(new MockSepCodec());
- swapCodec(new PulsingCodec(codecHasParam && "Pulsing".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 20)));
- swapCodec(new MockFixedIntBlockCodec(codecHasParam && "MockFixedIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 2000)));
+ swapCodec(new PulsingCodec(codecHasParam && "Pulsing".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 20)));
+ swapCodec(new MockFixedIntBlockCodec(codecHasParam && "MockFixedIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 2000)));
// baseBlockSize cannot be over 127:
- swapCodec(new MockVariableIntBlockCodec(codecHasParam && "MockVariableIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(seedRnd, 1, 127)));
+ swapCodec(new MockVariableIntBlockCodec(codecHasParam && "MockVariableIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 127)));
return cp.lookup(codec);
}
@@ -279,13 +280,15 @@ public abstract class LuceneTestCase extends Assert {
@BeforeClass
public static void beforeClassLuceneTestCaseJ4() {
+ staticSeed = "random".equals(TEST_SEED) ? seedRand.nextLong() : UUID.fromString(TEST_SEED).getMostSignificantBits();
+ random.setSeed(staticSeed);
stores = Collections.synchronizedMap(new IdentityHashMap<MockDirectoryWrapper,StackTraceElement[]>());
codec = installTestCodecs();
savedLocale = Locale.getDefault();
- locale = TEST_LOCALE.equals("random") ? randomLocale(seedRnd) : localeForName(TEST_LOCALE);
+ locale = TEST_LOCALE.equals("random") ? randomLocale(random) : localeForName(TEST_LOCALE);
Locale.setDefault(locale);
savedTimeZone = TimeZone.getDefault();
- timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(seedRnd) : TimeZone.getTimeZone(TEST_TIMEZONE);
+ timeZone = TEST_TIMEZONE.equals("random") ? randomTimeZone(random) : TimeZone.getTimeZone(TEST_TIMEZONE);
TimeZone.setDefault(timeZone);
testsFailed = false;
}
@@ -307,6 +310,11 @@ public abstract class LuceneTestCase extends Assert {
}
}
stores = null;
+ // if tests failed, report some information back
+ if (testsFailed)
+ System.out.println("NOTE: test params are: codec=" + codec +
+ ", locale=" + locale +
+ ", timezone=" + (timeZone == null ? "(null)" : timeZone.getID()));
}
private static boolean testsFailed; /* true if any tests failed */
@@ -335,10 +343,10 @@ public abstract class LuceneTestCase extends Assert {
@Before
public void setUp() throws Exception {
+ seed = "random".equals(TEST_SEED) ? seedRand.nextLong() : UUID.fromString(TEST_SEED).getLeastSignificantBits();
+ random.setSeed(seed);
Assert.assertFalse("ensure your tearDown() calls super.tearDown()!!!", setup);
setup = true;
- seed = Long.valueOf(TEST_SEED.equals("random") ? seedRnd.nextLong() : Long.parseLong(TEST_SEED));
- random = new Random(seed);
savedUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
@@ -350,7 +358,6 @@ public abstract class LuceneTestCase extends Assert {
ConcurrentMergeScheduler.setTestMode();
savedBoolMaxClauseCount = BooleanQuery.getMaxClauseCount();
- seed = null;
}
@@ -512,36 +519,8 @@ public abstract class LuceneTestCase extends Assert {
dumpIterator(label, iter, stream);
}
- private static final Map<Class<? extends LuceneTestCase>,Long> staticSeeds =
- Collections.synchronizedMap(new WeakHashMap<Class<? extends LuceneTestCase>,Long>());
-
- /**
- * Returns a {@link Random} instance for generating random numbers from a beforeclass
- * annotated method.
- * The random seed is logged during test execution and printed to System.out on any failure
- * for reproducing the test using {@link #newStaticRandom(Class, long)} with the recorded seed
- * .
- */
- public static Random newStaticRandom(Class<? extends LuceneTestCase> clazz) {
- Long seed = seedRnd.nextLong();
- staticSeeds.put(clazz, seed);
- return new Random(seed);
- }
-
- /**
- * Returns a {@link Random} instance for generating random numbers from a beforeclass
- * annotated method.
- * If an error occurs in the test that is not reproducible, you can use this method to
- * initialize the number generator with the seed that was printed out during the failing test.
- */
- public static Random newStaticRandom(Class<? extends LuceneTestCase> clazz, long seed) {
- staticSeeds.put(clazz, Long.valueOf(seed));
- System.out.println("WARNING: random static seed of testclass '" + clazz + "' is fixed to: " + seed);
- return new Random(seed);
- }
-
/** create a new index writer config with random defaults */
- public IndexWriterConfig newIndexWriterConfig(Version v, Analyzer a) {
+ public static IndexWriterConfig newIndexWriterConfig(Version v, Analyzer a) {
return newIndexWriterConfig(random, v, a);
}
@@ -586,7 +565,7 @@ public abstract class LuceneTestCase extends Assert {
* some features of Windows, such as not allowing open files to be
* overwritten.
*/
- public MockDirectoryWrapper newDirectory() throws IOException {
+ public static MockDirectoryWrapper newDirectory() throws IOException {
return newDirectory(random);
}
@@ -603,11 +582,11 @@ public abstract class LuceneTestCase extends Assert {
* provided directory. See {@link #newDirectory()} for more
* information.
*/
- public MockDirectoryWrapper newDirectory(Directory d) throws IOException {
+ public static MockDirectoryWrapper newDirectory(Directory d) throws IOException {
return newDirectory(random, d);
}
- private static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
+ public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
StackTraceElement[] stack = new Exception().getStackTrace();
Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
for (String file : d.listAll()) {
@@ -618,15 +597,15 @@ public abstract class LuceneTestCase extends Assert {
return dir;
}
- public Field newField(String name, String value, Index index) {
+ public static Field newField(String name, String value, Index index) {
return newField(random, name, value, index);
}
- public Field newField(String name, String value, Store store, Index index) {
+ public static Field newField(String name, String value, Store store, Index index) {
return newField(random, name, value, store, index);
}
- public Field newField(String name, String value, Store store, Index index, TermVector tv) {
+ public static Field newField(String name, String value, Store store, Index index, TermVector tv) {
return newField(random, name, value, store, index, tv);
}
@@ -751,27 +730,17 @@ public abstract class LuceneTestCase extends Assert {
// We get here from InterceptTestCaseEvents on the 'failed' event....
public void reportAdditionalFailureInfo() {
- Long staticSeed = staticSeeds.get(getClass());
- if (staticSeed != null) {
- System.out.println("NOTE: random static seed of testclass '" + getName() + "' was: " + staticSeed);
- }
-
- System.out.println("NOTE: random codec of testcase '" + getName() + "' was: " + codec);
- if (TEST_LOCALE.equals("random"))
- System.out.println("NOTE: random locale of testcase '" + getName() + "' was: " + locale);
- if (TEST_TIMEZONE.equals("random")) // careful to not deliver NPE here in case they forgot super.setUp
- System.out.println("NOTE: random timezone of testcase '" + getName() + "' was: " + (timeZone == null ? "(null)" : timeZone.getID()));
- if (seed != null) {
- System.out.println("NOTE: random seed of testcase '" + getName() + "' was: " + seed);
- }
+ System.out.println("NOTE: reproduce with: ant test -Dtestcase=" + getClass().getSimpleName()
+ + " -Dtestmethod=" + getName() + " -Dtests.seed=" + new UUID(staticSeed, seed));
}
- // recorded seed
- protected Long seed = null;
- protected Random random = null;
+ // recorded seed: for beforeClass
+ private static long staticSeed;
+ // seed for individual test methods, changed in @before
+ private long seed;
- // static members
- private static final Random seedRnd = new Random();
+ private static final Random seedRand = new Random();
+ protected static final Random random = new Random();
private String name = "<unknown>";