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/04/10 21:31:02 UTC
svn commit: r1311950 - in /lucene/dev/branches/lucene3969:
lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
Author: rmuir
Date: Tue Apr 10 19:31:01 2012
New Revision: 1311950
URL: http://svn.apache.org/viewvc?rev=1311950&view=rev
Log:
LUCENE-3969: fix BaseTokenTest to do the same work in multi-threads that it did in single-threads, so it really shouldnt fail from another thread unless you have an actual thread problem
Modified:
lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
lucene/dev/branches/lucene3969/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
Modified: lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java?rev=1311950&r1=1311949&r2=1311950&view=diff
==============================================================================
--- lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java (original)
+++ lucene/dev/branches/lucene3969/lucene/test-framework/src/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java Tue Apr 10 19:31:01 2012
@@ -382,17 +382,19 @@ public abstract class BaseTokenStreamTes
static class AnalysisThread extends Thread {
final int iterations;
final int maxWordLength;
- final Random random;
+ final long seed;
final Analyzer a;
+ final boolean useCharFilter;
final boolean simple;
final boolean offsetsAreCorrect;
public boolean failed;
- AnalysisThread(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple, boolean offsetsAreCorrect) {
- this.random = random;
+ AnalysisThread(long seed, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect) {
+ this.seed = seed;
this.a = a;
this.iterations = iterations;
this.maxWordLength = maxWordLength;
+ this.useCharFilter = useCharFilter;
this.simple = simple;
this.offsetsAreCorrect = offsetsAreCorrect;
}
@@ -403,7 +405,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, maxWordLength, random.nextBoolean(), simple, offsetsAreCorrect);
+ checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect);
success = true;
} catch (IOException e) {
Rethrow.rethrow(e);
@@ -418,12 +420,15 @@ public abstract class BaseTokenStreamTes
}
public static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength, boolean simple, boolean offsetsAreCorrect) throws IOException {
- checkRandomData(random, a, iterations, maxWordLength, random.nextBoolean(), simple, offsetsAreCorrect);
- // now test with multiple threads
+ long seed = random.nextLong();
+ boolean useCharFilter = random.nextBoolean();
+ checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect);
+ // now test with multiple threads: note we do the EXACT same thing we did before in each thread,
+ // so this should only really fail from another thread if its an actual thread problem
int numThreads = _TestUtil.nextInt(random, 4, 8);
AnalysisThread threads[] = new AnalysisThread[numThreads];
for (int i = 0; i < threads.length; i++) {
- threads[i] = new AnalysisThread(new Random(random.nextLong()), a, iterations, maxWordLength, simple, offsetsAreCorrect);
+ threads[i] = new AnalysisThread(seed, a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect);
}
for (int i = 0; i < threads.length; i++) {
threads[i].start();
Modified: lucene/dev/branches/lucene3969/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3969/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java?rev=1311950&r1=1311949&r2=1311950&view=diff
==============================================================================
--- lucene/dev/branches/lucene3969/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java (original)
+++ lucene/dev/branches/lucene3969/modules/analysis/common/src/test/org/apache/lucene/analysis/core/TestRandomChains.java Tue Apr 10 19:31:01 2012
@@ -792,8 +792,7 @@ public class TestRandomChains extends Ba
int numIterations = atLeast(20);
for (int i = 0; i < numIterations; i++) {
MockRandomAnalyzer a = new MockRandomAnalyzer(random.nextLong());
- // nocommit: wrap the uncaught handler with our own that prints the analyzer
- if (true || VERBOSE) {
+ if (VERBOSE) {
System.out.println("Creating random analyzer:" + a);
}
try {