diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java index 410b7f49f21..870794c13a1 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterThreadsToSegments.java @@ -253,7 +253,7 @@ public class TestIndexWriterThreadsToSegments extends LuceneTestCase { startingGun.await(); Document doc = new Document(); doc.add(new TextField("field", "here is some text that is a bit longer than normal trivial text", Field.Store.NO)); - while (true) { + for(int j=0;j<1000;j++) { w.addDocument(doc); } } catch (AlreadyClosedException ace) { @@ -269,10 +269,15 @@ public class TestIndexWriterThreadsToSegments extends LuceneTestCase { startingGun.countDown(); Thread.sleep(100); - w.close(); + try { + w.close(); + } catch (IllegalStateException ise) { + // OK but not required + } for(Thread t : threads) { t.join(); } + w.close(); dir.close(); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java index 6645dfa99c5..6aac9e34381 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/RandomIndexWriter.java @@ -351,12 +351,12 @@ public class RandomIndexWriter implements Closeable { */ @Override public void close() throws IOException { - if (!w.isClosed()) { + if (w.isClosed() == false) { LuceneTestCase.maybeChangeLiveIndexWriterConfig(r, w.getConfig()); } // if someone isn't using getReader() API, we want to be sure to // forceMerge since presumably they might open a reader on the dir. - if (getReaderCalled == false && r.nextInt(8) == 2) { + if (getReaderCalled == false && r.nextInt(8) == 2 && w.isClosed() == false) { doRandomForceMerge(); if (w.getConfig().getCommitOnClose() == false) { // index may have changed, must commit the changes, or otherwise they are discarded by the call to close()