LUCENE-5635: add some deletes and open reader from writer

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1591708 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-05-01 16:50:15 +00:00
parent 01829ad787
commit 07eac25dd0
1 changed files with 18 additions and 3 deletions

View File

@ -31,6 +31,7 @@ import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util.TestUtil;
import org.apache.lucene.util.Rethrow;
@ -88,6 +89,10 @@ public class TestIndexWriterExceptions2 extends LuceneTestCase {
// TODO: sometimes update dv
try {
iw.addDocument(doc);
// we made it, sometimes delete our doc
if (random().nextInt(4) == 0) {
iw.deleteDocuments(new Term("id", Integer.toString(i)));
}
} catch (Exception e) {
if (e.getMessage() != null && e.getMessage().startsWith("Fake IOException")) {
exceptionStream.println("\nTEST: got expected fake exc:" + e.getMessage());
@ -97,9 +102,19 @@ public class TestIndexWriterExceptions2 extends LuceneTestCase {
}
}
if (random().nextInt(10) == 0) {
// trigger flush: TODO: sometimes reopen
// trigger flush:
try {
iw.commit();
if (random().nextBoolean()) {
DirectoryReader ir = null;
try {
ir = DirectoryReader.open(iw, random().nextBoolean());
TestUtil.checkReader(ir);
} finally {
IOUtils.closeWhileHandlingException(ir);
}
} else {
iw.commit();
}
if (DirectoryReader.indexExists(dir)) {
TestUtil.checkIndex(dir);
}
@ -118,7 +133,7 @@ public class TestIndexWriterExceptions2 extends LuceneTestCase {
iw.shutdown();
} catch (Exception e) {
if (e.getMessage() != null && e.getMessage().startsWith("Fake IOException")) {
System.out.println("\nTEST: got expected fake exc:" + e.getMessage());
exceptionStream.println("\nTEST: got expected fake exc:" + e.getMessage());
e.printStackTrace(exceptionStream);
try {
iw.rollback();