Index: lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java =================================================================== --- lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (revision 1480527) +++ lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java (working copy) @@ -60,7 +60,6 @@ * refusing to write/delete to open files. * */ - public class MockDirectoryWrapper extends BaseDirectoryWrapper { long maxSize; @@ -166,12 +165,19 @@ if (crashed) { throw new IOException("cannot sync after crash"); } - unSyncedFiles.removeAll(names); - // TODO: need to improve hack to be OK w/ - // RateLimitingDirWrapper in between... - if (true || LuceneTestCase.rarely(randomState) || delegate instanceof NRTCachingDirectory) { - // don't wear out our hardware so much in tests. - delegate.sync(names); + // don't wear out our hardware so much in tests. + if (LuceneTestCase.rarely(randomState) + || delegate instanceof NRTCachingDirectory + || (delegate instanceof RateLimitedDirectoryWrapper && ((RateLimitedDirectoryWrapper) delegate).getDelegate() instanceof NRTCachingDirectory) + || (delegate instanceof TrackingDirectoryWrapper && ((TrackingDirectoryWrapper) delegate).getDelegate() instanceof NRTCachingDirectory)) { + for (String name : names) { + // randomly fail with IOE on any file + maybeThrowIOException(name); + delegate.sync(Collections.singleton(name)); + unSyncedFiles.remove(name); + } + } else { + unSyncedFiles.removeAll(names); } } @@ -343,10 +349,6 @@ return randomIOExceptionRateOnOpen; } - void maybeThrowIOException() throws IOException { - maybeThrowIOException(null); - } - void maybeThrowIOException(String message) throws IOException { if (randomState.nextDouble() < randomIOExceptionRate) { if (LuceneTestCase.VERBOSE) { @@ -357,10 +359,10 @@ } } - void maybeThrowIOExceptionOnOpen() throws IOException { + void maybeThrowIOExceptionOnOpen(String name) throws IOException { if (randomState.nextDouble() < randomIOExceptionRateOnOpen) { if (LuceneTestCase.VERBOSE) { - System.out.println(Thread.currentThread().getName() + ": MockDirectoryWrapper: now throw random exception during open"); + System.out.println(Thread.currentThread().getName() + ": MockDirectoryWrapper: now throw random exception during open file=" + name); new Throwable().printStackTrace(System.out); } if (randomState.nextBoolean()) { @@ -432,7 +434,7 @@ @Override public synchronized IndexOutput createOutput(String name, IOContext context) throws IOException { maybeThrowDeterministicException(); - maybeThrowIOExceptionOnOpen(); + maybeThrowIOExceptionOnOpen(name); maybeYield(); if (failOnCreateOutput) { maybeThrowDeterministicException(); @@ -519,7 +521,7 @@ @Override public synchronized IndexInput openInput(String name, IOContext context) throws IOException { maybeThrowDeterministicException(); - maybeThrowIOExceptionOnOpen(); + maybeThrowIOExceptionOnOpen(name); maybeYield(); if (failOnOpenInput) { maybeThrowDeterministicException(); @@ -632,7 +634,7 @@ if (LuceneTestCase.VERBOSE) { System.out.println("\nNOTE: MockDirectoryWrapper: now crash"); } - crash(); // corrumpt any unsynced-files + crash(); // corrupt any unsynced-files if (LuceneTestCase.VERBOSE) { System.out.println("\nNOTE: MockDirectoryWrapper: now run CheckIndex"); }