From 00dcd8c1616d91ccee4e31765eee54d75a403f7a Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sat, 12 Oct 2013 20:36:42 +0000 Subject: [PATCH] fix test failure; add fangs to testcase git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1531590 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/lucene/index/IndexWriter.java | 11 +++---- .../lucene/index/TestIndexWriterDelete.java | 30 +++++++++++++++---- .../index/TestIndexWriterWithThreads.java | 6 ++++ 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 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.java index 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 BDS shouldFail.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.java index 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