From f18af4252a55718adb65ec7ec30fee3988fbffa8 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Sun, 23 Mar 2014 21:27:27 +0000 Subject: [PATCH] don't allow random FNFE/NSFE from MDW for this test git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1580615 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/lucene/index/TestIndexWriterDelete.java | 1 + .../apache/lucene/store/MockDirectoryWrapper.java | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) 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 dba31fc283d..caec565055b 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterDelete.java @@ -524,6 +524,7 @@ public class TestIndexWriterDelete extends LuceneTestCase { } MockDirectoryWrapper dir = new MockDirectoryWrapper(random(), new RAMDirectory(startDir, newIOContext(random()))); dir.setPreventDoubleWrite(false); + dir.setAllowRandomFileNotFoundException(false); IndexWriter modifier = new IndexWriter(dir, newIndexWriterConfig( TEST_VERSION_CURRENT, new MockAnalyzer(random(), MockTokenizer.WHITESPACE, false)) diff --git a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java index f369e71dbd2..d2c02f521a1 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java +++ b/lucene/test-framework/src/java/org/apache/lucene/store/MockDirectoryWrapper.java @@ -74,6 +74,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper { boolean preventDoubleWrite = true; boolean trackDiskUsage = false; boolean wrapLockFactory = true; + boolean allowRandomFileNotFoundException = true; private Set unSyncedFiles; private Set createdFiles; private Set openFilesForWrite = new HashSet<>(); @@ -137,7 +138,15 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper { public void setPreventDoubleWrite(boolean value) { preventDoubleWrite = value; } - + + /** If set to true (the default), when we throw random + * IOException on openInput or createOutput, we may + * sometimes throw FileNotFoundException or + * NoSuchFileException. */ + public void setAllowRandomFileNotFoundException(boolean value) { + allowRandomFileNotFoundException = value; + } + /** * Enum for controlling hard disk throttling. * Set via {@link MockDirectoryWrapper #setThrottling(Throttling)} @@ -379,7 +388,7 @@ public class MockDirectoryWrapper extends BaseDirectoryWrapper { System.out.println(Thread.currentThread().getName() + ": MockDirectoryWrapper: now throw random exception during open file=" + name); new Throwable().printStackTrace(System.out); } - if (randomState.nextBoolean()) { + if (allowRandomFileNotFoundException == false || randomState.nextBoolean()) { throw new IOException("a random IOException (" + name + ")"); } else { throw randomState.nextBoolean() ? new FileNotFoundException("a random IOException (" + name + ")") : new NoSuchFileException("a random IOException (" + name + ")");