Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

test analyzers with multiple threads in BaseTokenStreamTestCase.checkRandomData

Robert Muir6fb676d1a273
diff --git a/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java b/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
index c9b1e3c0722..91ce7848d5e 100644
--- a/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
+++ b/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
@@ -249,7 +249,46 @@ 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.
public static void checkRandomData(Random random, Analyzer a, int iterations) throws IOException {
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 {
for (int i = 0; i < iterations; i++) {