Apache Lucene open-source search software
LUCENE-3894: make the single-threaded checkRandomData private, and allow the multithreaded version to take and respect maxWordLength for more intense tests
Robert Muir8e6704fc207b
diff --git a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.javaindex 6fc1d3d589a..fc43980e248 100644--- a/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java@@ -304,34 +304,20 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {*/public static void checkRandomData(Random random, Analyzer a, int iterations, boolean simple) throws IOException {checkRandomData(random, a, iterations, 20, simple);- // now test with multiple threads- int numThreads = _TestUtil.nextInt(random, 4, 8);- Thread threads[] = new Thread[numThreads];- for (int i = 0; i < threads.length; i++) {- threads[i] = new AnalysisThread(new Random(random.nextLong()), a, iterations, simple);- }- for (int i = 0; i < threads.length; i++) {- threads[i].start();- }- for (int i = 0; i < threads.length; i++) {- try {- threads[i].join();- } catch (InterruptedException e) {- throw new RuntimeException(e);- }- }}static class AnalysisThread extends Thread {final int iterations;+ final int maxWordLength;final Random random;final Analyzer a;final boolean simple;- AnalysisThread(Random random, Analyzer a, int iterations, boolean simple) {+ AnalysisThread(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple) {this.random = random;this.a = a;this.iterations = iterations;+ this.maxWordLength = maxWordLength;this.simple = simple;}@@ -340,7 +326,7 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {try {// see the part in checkRandomData where it replays the same text again// to verify reproducability/reuse: hopefully this would catch thread hazards.- checkRandomData(random, a, iterations, 20, simple);+ checkRandomData(random, a, iterations, maxWordLength, random.nextBoolean(), simple);} catch (IOException e) {throw new RuntimeException(e);}@@ -349,17 +335,33 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {public static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple) throws IOException {checkRandomData(random, a, iterations, maxWordLength, random.nextBoolean(), simple);+ // now test with multiple threads+ int numThreads = _TestUtil.nextInt(random, 4, 8);+ Thread threads[] = new Thread[numThreads];+ for (int i = 0; i < threads.length; i++) {+ threads[i] = new AnalysisThread(new Random(random.nextLong()), a, iterations, maxWordLength, simple);+ }+ for (int i = 0; i < threads.length; i++) {+ threads[i].start();+ }+ for (int i = 0; i < threads.length; i++) {+ try {+ threads[i].join();+ } catch (InterruptedException e) {+ throw new RuntimeException(e);+ }+ }}- public static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple) throws IOException {+ private static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple) throws IOException {for (int i = 0; i < iterations; i++) {String text;if (simple) {- text = random.nextBoolean() ? _TestUtil.randomSimpleString(random) : _TestUtil.randomHtmlishString(random, maxWordLength);+ text = random.nextBoolean() ? _TestUtil.randomSimpleString(random, maxWordLength) : _TestUtil.randomHtmlishString(random, maxWordLength);} else {switch(_TestUtil.nextInt(random, 0, 4)) {case 0:- text = _TestUtil.randomSimpleString(random);+ text = _TestUtil.randomSimpleString(random, maxWordLength);break;case 1:text = _TestUtil.randomRealisticUnicodeString(random, maxWordLength);