Apache Lucene open-source search software
fix test failure; add fangs to testcase
Michael McCandless00dcd8c1616d
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.javaindex c4d9014cffd..a3931d3ec3c 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java@@ -1027,18 +1027,15 @@ public class IndexWriter implements Closeable, TwoPhaseCommit{infoStream.message("IW", "now call final commit()");}- // Must do this before commitInternal, in case any of- // the dropped readers in the pool wrote a new live- // docs:- synchronized(this) {- readerPool.dropAll(true);- }-if (doFlush) {commitInternal();}synchronized(this) {+ // commitInternal calls ReaderPool.commit, which+ // writes any pending liveDocs from ReaderPool, so+ // it's safe to drop all readers now:+ readerPool.dropAll(true);deleter.close();}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.javaindex 11ac17a0ad8..f69d07d91f2 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java@@ -1313,6 +1313,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {// to fail in "more evil" places inside BDSshouldFail.set(true);+ boolean doClose = false;try {@@ -1333,9 +1334,16 @@ public class TestIndexWriterDelete extends LuceneTestCase {// throw the exc):assertEquals(docCount-deleteCount, r.numDocs());r.close();-- // TODO: also call w.close() in here, sometimes,- // so we sometimes get a fail via dropAll++ // Sometimes close, so the disk full happens on close:+ if (random().nextBoolean()) {+ if (VERBOSE) {+ System.out.println(" now close writer");+ }+ doClose = true;+ w.close();+ w = null;+ }} catch (FakeIOException ioe) {// expected@@ -1348,13 +1356,23 @@ public class TestIndexWriterDelete extends LuceneTestCase {IndexReader r;- if (random().nextBoolean()) {+ if (doClose && w != null) {+ if (VERBOSE) {+ System.out.println(" now 2nd close writer");+ }+ w.close();+ w = null;+ }++ if (w == null || random().nextBoolean()) {// Open non-NRT reader, to make sure the "on// disk" bits are good:if (VERBOSE) {System.out.println("TEST: verify against non-NRT reader");}- w.commit();+ if (w != null) {+ w.commit();+ }r = DirectoryReader.open(dir);} else {if (VERBOSE) {@@ -1366,7 +1384,7 @@ public class TestIndexWriterDelete extends LuceneTestCase {r.close();// Sometimes re-use RIW, other times open new one:- if (random().nextBoolean()) {+ if (w != null && random().nextBoolean()) {if (VERBOSE) {System.out.println("TEST: close writer");}diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.javaindex 9e4e5a34d46..540f1f3217a 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterWithThreads.java@@ -177,6 +177,9 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {int NUM_THREADS = 3;int numIterations = TEST_NIGHTLY ? 7 : 3;for(int iter=0;iter<numIterations;iter++) {+ if (VERBOSE) {+ System.out.println("\nTEST: iter=" + iter);+ }Directory dir = newDirectory();IndexWriter writer = new IndexWriter(@@ -209,6 +212,9 @@ public class TestIndexWriterWithThreads extends LuceneTestCase {}}+ if (VERBOSE) {+ System.out.println("\nTEST: now close");+ }writer.close(false);// Make sure threads that are adding docs are not hung: