diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java index 6c950b84f9e..fadbc32eaa4 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java @@ -18,7 +18,8 @@ package org.apache.lucene.index; import java.io.IOException; -import java.util.concurrent.CountDownLatch; +import java.util.concurrent.BrokenBarrierException; +import java.util.concurrent.CyclicBarrier; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.Lock; @@ -53,6 +54,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { // Used by test cases below private static class IndexerThread extends Thread { + private final CyclicBarrier syncStart; boolean diskFull; Throwable error; AlreadyClosedException ace; @@ -60,13 +62,20 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { boolean noErrors; volatile int addCount; - public IndexerThread(IndexWriter writer, boolean noErrors) { + public IndexerThread(IndexWriter writer, boolean noErrors, CyclicBarrier syncStart) { this.writer = writer; this.noErrors = noErrors; + this.syncStart = syncStart; } @Override public void run() { + try { + syncStart.await(); + } catch (BrokenBarrierException | InterruptedException e) { + error = e; + throw new RuntimeException(e); + } final Document doc = new Document(); FieldType customType = new FieldType(TextField.TYPE_STORED); @@ -79,7 +88,6 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { int idUpto = 0; int fullCount = 0; - final long stopTime = System.currentTimeMillis() + 200; do { try { @@ -114,7 +122,6 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { // OK: abort closes the writer break; } catch (Throwable t) { - //t.printStackTrace(System.out); if (noErrors) { System.out.println(Thread.currentThread().getName() + ": ERROR: unexpected Throwable:"); t.printStackTrace(System.out); @@ -122,7 +129,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { } break; } - } while(System.currentTimeMillis() < stopTime); + } while (true); } } @@ -133,7 +140,7 @@ public class TestIndexWriterWithThreads extends LuceneTestCase { int NUM_THREADS = 3; final int numIterations = TEST_NIGHTLY ? 10 : 3; - for(int iter=0;iter