Index: lucene/src/test/org/apache/lucene/index/TestIndexReader.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestIndexReader.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/index/TestIndexReader.java (working copy) @@ -970,6 +970,9 @@ } } + // turn off random IOExceptions for the verification step + dir.setRandomIOExceptionRate(0.0D); + // Whether we succeeded or failed, check that all // un-referenced files were in fact deleted (ie, // we did not create garbage). Just create a Index: lucene/src/test/org/apache/lucene/index/TestTransactions.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestTransactions.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/index/TestTransactions.java (working copy) @@ -168,10 +168,18 @@ @Override public void doWork() throws Throwable { - IndexReader r1, r2; + IndexReader r1 = null, r2 = null; synchronized(lock) { - r1 = IndexReader.open(dir1, true); - r2 = IndexReader.open(dir2, true); + try { + r1 = IndexReader.open(dir1, true); + r2 = IndexReader.open(dir2, true); + } catch (IOException e) { + if (!e.getMessage().contains("on purpose")) + throw e; + if (r1 != null) r1.close(); + if (r2 != null) r2.close(); + return; + } } if (r1.numDocs() != r2.numDocs()) throw new RuntimeException("doc counts differ: r1=" + r1.numDocs() + " r2=" + r2.numDocs()); Index: lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java =================================================================== --- lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/index/TestIndexWriterDelete.java (working copy) @@ -539,6 +539,9 @@ TestIndexWriter.assertNoUnreferencedFiles(dir, "after writer.close"); } + // turn off random IOExceptions for the verification step + dir.setRandomIOExceptionRate(0.0D); + // Finally, verify index is not corrupt, and, if // we succeeded, we see all docs changed, and if // we failed, we see either all docs or no docs Index: lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java =================================================================== --- lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/store/MockDirectoryWrapper.java (working copy) @@ -209,6 +209,15 @@ // seed so we have deterministic behaviour: randomState = new Random(seed); } + + /** + * Do not use. Use setRandomIOExceptionRate(double, long). + * @lucene.internal + */ + public void setRandomIOExceptionRate(double rate) { + randomIOExceptionRate = rate; + } + public double getRandomIOExceptionRate() { return randomIOExceptionRate; } @@ -217,7 +226,7 @@ if (randomIOExceptionRate > 0.0) { int number = Math.abs(randomState.nextInt() % 1000); if (number < randomIOExceptionRate*1000) { - throw new IOException("a random IOException"); + throw new FakeIOException("a random IOException"); } } } @@ -246,6 +255,7 @@ @Override public synchronized IndexOutput createOutput(String name) throws IOException { + maybeThrowAnyException(); if (crashed) throw new IOException("cannot createOutput after crash"); init(); @@ -284,6 +294,7 @@ @Override public synchronized IndexInput openInput(String name) throws IOException { + maybeThrowAnyException(); if (!delegate.fileExists(name)) throw new FileNotFoundException(name); else { @@ -414,6 +425,16 @@ } } } + + /** + * might throw a deterministic exception, if any have been registered + * with failOn, and might throw an IOException, if random IO Exceptions + * are turned on with setRandomIOExceptionRate. + */ + synchronized void maybeThrowAnyException() throws IOException { + maybeThrowDeterministicException(); + maybeThrowIOException(); + } @Override public synchronized String[] listAll() throws IOException { @@ -469,4 +490,10 @@ public synchronized void copy(Directory to, String src, String dest) throws IOException { delegate.copy(to, src, dest); } + + public static class FakeIOException extends IOException { + public FakeIOException(String message) { + super(message); + } + } } Index: lucene/src/test/org/apache/lucene/util/_TestUtil.java =================================================================== --- lucene/src/test/org/apache/lucene/util/_TestUtil.java (revision 1026400) +++ lucene/src/test/org/apache/lucene/util/_TestUtil.java (working copy) @@ -27,6 +27,8 @@ import org.apache.lucene.index.codecs.Codec; import org.apache.lucene.index.SegmentWriteState; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MockDirectoryWrapper; + import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.Random; @@ -69,11 +71,24 @@ * issues are hit, a RuntimeException is thrown; else, * true is returned. */ public static CheckIndex.Status checkIndex(Directory dir) throws IOException { + // hack alert: turn off random IOExceptions temporarily + double randomExceptionRateSave = 0.0D; + if (dir instanceof MockDirectoryWrapper) { + MockDirectoryWrapper m = (MockDirectoryWrapper) dir; + randomExceptionRateSave = m.getRandomIOExceptionRate(); + m.setRandomIOExceptionRate(0.0D); + } + ByteArrayOutputStream bos = new ByteArrayOutputStream(1024); CheckIndex checker = new CheckIndex(dir); checker.setInfoStream(new PrintStream(bos)); CheckIndex.Status indexStatus = checker.checkIndex(); + + // restore the random IOException rate + if (randomExceptionRateSave > 0.0D) + ((MockDirectoryWrapper)dir).setRandomIOExceptionRate(randomExceptionRateSave); + if (indexStatus == null || indexStatus.clean == false) { System.out.println("CheckIndex failed"); System.out.println(bos.toString());