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/01/03 15:56:09 UTC
svn commit: r1226795 - in /lucene/dev/branches/branch_3x: ./ lucene/
lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
Author: rmuir
Date: Tue Jan 3 14:56:09 2012
New Revision: 1226795
URL: http://svn.apache.org/viewvc?rev=1226795&view=rev
Log:
test analyzers with multiple threads in BaseTokenStreamTestCase.checkRandomData
Modified:
lucene/dev/branches/branch_3x/ (props changed)
lucene/dev/branches/branch_3x/lucene/ (props changed)
lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
Modified: lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java?rev=1226795&r1=1226794&r2=1226795&view=diff
==============================================================================
--- lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java (original)
+++ lucene/dev/branches/branch_3x/lucene/src/test-framework/java/org/apache/lucene/analysis/BaseTokenStreamTestCase.java Tue Jan 3 14:56:09 2012
@@ -249,7 +249,46 @@ public abstract class BaseTokenStreamTes
// 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++) {