mirror of
https://github.com/apache/lucene.git
synced 2025-02-09 11:35:14 +00:00
add startingGun to BaseTokenStreamTestCase to release all threads at once
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1580020 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
bf2086c831
commit
f02e15f9f2
@ -26,6 +26,7 @@ import java.io.StringReader;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
|
||||||
import org.apache.lucene.analysis.tokenattributes.*;
|
import org.apache.lucene.analysis.tokenattributes.*;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
@ -450,13 +451,14 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
|||||||
final boolean simple;
|
final boolean simple;
|
||||||
final boolean offsetsAreCorrect;
|
final boolean offsetsAreCorrect;
|
||||||
final RandomIndexWriter iw;
|
final RandomIndexWriter iw;
|
||||||
|
final CountDownLatch latch;
|
||||||
|
|
||||||
// NOTE: not volatile because we don't want the tests to
|
// NOTE: not volatile because we don't want the tests to
|
||||||
// add memory barriers (ie alter how threads
|
// add memory barriers (ie alter how threads
|
||||||
// interact)... so this is just "best effort":
|
// interact)... so this is just "best effort":
|
||||||
public boolean failed;
|
public boolean failed;
|
||||||
|
|
||||||
AnalysisThread(long seed, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect, RandomIndexWriter iw) {
|
AnalysisThread(long seed, CountDownLatch latch, Analyzer a, int iterations, int maxWordLength, boolean useCharFilter, boolean simple, boolean offsetsAreCorrect, RandomIndexWriter iw) {
|
||||||
this.seed = seed;
|
this.seed = seed;
|
||||||
this.a = a;
|
this.a = a;
|
||||||
this.iterations = iterations;
|
this.iterations = iterations;
|
||||||
@ -465,17 +467,19 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
|||||||
this.simple = simple;
|
this.simple = simple;
|
||||||
this.offsetsAreCorrect = offsetsAreCorrect;
|
this.offsetsAreCorrect = offsetsAreCorrect;
|
||||||
this.iw = iw;
|
this.iw = iw;
|
||||||
|
this.latch = latch;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
try {
|
try {
|
||||||
|
latch.await();
|
||||||
// see the part in checkRandomData where it replays the same text again
|
// see the part in checkRandomData where it replays the same text again
|
||||||
// to verify reproducability/reuse: hopefully this would catch thread hazards.
|
// to verify reproducability/reuse: hopefully this would catch thread hazards.
|
||||||
checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
|
checkRandomData(new Random(seed), a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
|
||||||
success = true;
|
success = true;
|
||||||
} catch (IOException e) {
|
} catch (Exception e) {
|
||||||
Rethrow.rethrow(e);
|
Rethrow.rethrow(e);
|
||||||
} finally {
|
} finally {
|
||||||
failed = !success;
|
failed = !success;
|
||||||
@ -507,13 +511,15 @@ public abstract class BaseTokenStreamTestCase extends LuceneTestCase {
|
|||||||
// now test with multiple threads: note we do the EXACT same thing we did before in each thread,
|
// 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
|
// so this should only really fail from another thread if its an actual thread problem
|
||||||
int numThreads = TestUtil.nextInt(random, 2, 4);
|
int numThreads = TestUtil.nextInt(random, 2, 4);
|
||||||
|
final CountDownLatch startingGun = new CountDownLatch(1);
|
||||||
AnalysisThread threads[] = new AnalysisThread[numThreads];
|
AnalysisThread threads[] = new AnalysisThread[numThreads];
|
||||||
for (int i = 0; i < threads.length; i++) {
|
for (int i = 0; i < threads.length; i++) {
|
||||||
threads[i] = new AnalysisThread(seed, a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
|
threads[i] = new AnalysisThread(seed, startingGun, a, iterations, maxWordLength, useCharFilter, simple, offsetsAreCorrect, iw);
|
||||||
}
|
}
|
||||||
for (int i = 0; i < threads.length; i++) {
|
for (int i = 0; i < threads.length; i++) {
|
||||||
threads[i].start();
|
threads[i].start();
|
||||||
}
|
}
|
||||||
|
startingGun.countDown();
|
||||||
for (int i = 0; i < threads.length; i++) {
|
for (int i = 0; i < threads.length; i++) {
|
||||||
try {
|
try {
|
||||||
threads[i].join();
|
threads[i].join();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user