mirror of https://github.com/apache/lucene.git
test analyzers with multiple threads in BaseTokenStreamTestCase.checkRandomData
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1226793 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
8b751984d7
commit
6fb676d1a2
|
@ -249,8 +249,47 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
||||||
// TODO: add a MockCharStream, and use it here too, to ensure that correctOffset etc is being done by tokenizers.
|
// TODO: add a MockCharStream, and use it here too, to ensure that correctOffset etc is being done by tokenizers.
|
||||||
public static void checkRandomData(Random random, Analyzer a, int iterations) throws IOException {
|
public static void checkRandomData(Random random, Analyzer a, int iterations) throws IOException {
|
||||||
checkRandomData(random, a, iterations, 20);
|
checkRandomData(random, a, iterations, 20);
|
||||||
|
// 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);
|
||||||
|
}
|
||||||
|
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 Random random;
|
||||||
|
final Analyzer a;
|
||||||
|
|
||||||
|
AnalysisThread(Random random, Analyzer a, int iterations) {
|
||||||
|
this.random = random;
|
||||||
|
this.a = a;
|
||||||
|
this.iterations = iterations;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
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);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength) throws IOException {
|
public static void checkRandomData(Random random, Analyzer a, int iterations, int maxWordLength) throws IOException {
|
||||||
for (int i = 0; i < iterations; i++) {
|
for (int i = 0; i < iterations; i++) {
|
||||||
String text;
|
String text;
|
||||||
|
|
Loading…
Reference in New Issue