You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2012/03/21 02:23:25 UTC
svn commit: r1303246 -
/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
Author: rmuir
Date: Wed Mar 21 01:23:24 2012
New Revision: 1303246
URL: http://svn.apache.org/viewvc?rev=1303246&view=rev
Log:
LUCENE-3894: make the single-threaded checkRandomData private, and allow the multithreaded version to take and respect maxWordLength for more intense tests
Modified:
lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
Modified: lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java?rev=1303246&r1=1303245&r2=1303246&view=diff
==============================================================================
--- lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java (original)
+++ lucene/dev/trunk/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java Wed Mar 21 01:23:24 2012
@@ -304,34 +304,20 @@ public abstract class BaseTokenStreamTes
*/
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 BaseTokenStreamTes
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 BaseTokenStreamTes
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);