mirror of https://github.com/apache/lucene.git
LUCENE-6217: add IW.isOpen and IW.getTragicException
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1657398 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
a5a4469596
commit
98abb0ed1b
|
@ -65,6 +65,9 @@ API Changes
|
|||
* LUCENE-6204, LUCENE-6208: Simplify CompoundFormat: remove files()
|
||||
and remove files parameter to write(). (Robert Muir)
|
||||
|
||||
* LUCENE-6217: Add IndexWriter.isOpen and getTragicException. (Simon
|
||||
Willnauer, Mike McCandless)
|
||||
|
||||
Other
|
||||
|
||||
* LUCENE-6193: Collapse identical catch branches in try-catch statements.
|
||||
|
|
|
@ -4390,6 +4390,18 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable {
|
|||
IOUtils.reThrow(tragedy);
|
||||
}
|
||||
|
||||
/** If this {@code IndexWriter} was closed as a side-effect of a tragic exception,
|
||||
* e.g. disk full while flushing a new segment, this returns the root cause exception.
|
||||
* Otherwise (no tragic exception has occurred) it returns null. */
|
||||
public Throwable getTragicException() {
|
||||
return tragedy;
|
||||
}
|
||||
|
||||
/** Returns {@code true} if this {@code IndexWriter} is still open. */
|
||||
public boolean isOpen() {
|
||||
return closing == false && closed == false;
|
||||
}
|
||||
|
||||
// Used for testing. Current points:
|
||||
// startDoFlush
|
||||
// startCommitMerge
|
||||
|
|
|
@ -54,7 +54,6 @@ public class TestCompressingStoredFieldsFormat extends BaseStoredFieldsFormatTes
|
|||
return CompressingCodec.randomInstance(random());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testDeletePartiallyWrittenFilesIfAbort() throws IOException {
|
||||
Directory dir = newDirectory();
|
||||
// test explicitly needs files to always be actually deleted
|
||||
|
@ -94,11 +93,13 @@ public class TestCompressingStoredFieldsFormat extends BaseStoredFieldsFormatTes
|
|||
try {
|
||||
iw.addDocument(invalidDoc);
|
||||
iw.commit();
|
||||
} catch(IllegalArgumentException iae) {
|
||||
// expected
|
||||
assertEquals(iae, iw.getTragicException());
|
||||
}
|
||||
finally {
|
||||
// Abort should have closed the deleter:
|
||||
dir.close();
|
||||
}
|
||||
// Writer should be closed by tragedy
|
||||
assertFalse(iw.isOpen());
|
||||
dir.close();
|
||||
}
|
||||
|
||||
public void testZFloat() throws Exception {
|
||||
|
|
|
@ -1520,6 +1520,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1544,6 +1545,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1569,6 +1571,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (NullPointerException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1594,6 +1597,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (NullPointerException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1619,6 +1623,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1644,6 +1649,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
// make sure we see our good doc
|
||||
DirectoryReader r = DirectoryReader.open(dir);
|
||||
|
@ -1675,6 +1681,7 @@ public class TestIndexWriterExceptions extends LuceneTestCase {
|
|||
iw.addDocument(doc);
|
||||
fail("didn't get expected exception");
|
||||
} catch (IllegalArgumentException expected) {}
|
||||
assertNull(iw.getTragicException());
|
||||
iw.close();
|
||||
|
||||
// make sure we see our good doc
|
||||
|
|
Loading…
Reference in New Issue