diff --git a/lucene/core/src/test/org/apache/lucene/index/TestNRTThreads.java b/lucene/core/src/test/org/apache/lucene/index/TestNRTThreads.java index 9490bfe8325..ab6ffa1101e 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestNRTThreads.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestNRTThreads.java @@ -54,7 +54,7 @@ public class TestNRTThreads extends ThreadedIndexingAndSearchingTestCase { } r.close(); writer.commit(); - final Set openDeletedFiles = ((MockDirectoryWrapper) dir).getOpenDeletedFiles(); + final Set openDeletedFiles = dir.getOpenDeletedFiles(); if (openDeletedFiles.size() > 0) { System.out.println("OBD files: " + openDeletedFiles); } @@ -80,7 +80,7 @@ public class TestNRTThreads extends ThreadedIndexingAndSearchingTestCase { r.close(); //System.out.println("numDocs=" + r.numDocs() + " openDelFileCount=" + dir.openDeleteFileCount()); - final Set openDeletedFiles = ((MockDirectoryWrapper) dir).getOpenDeletedFiles(); + final Set openDeletedFiles = dir.getOpenDeletedFiles(); if (openDeletedFiles.size() > 0) { System.out.println("OBD files: " + openDeletedFiles); } diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java index e8d7dcaa1da..370d0b4384b 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/index/ThreadedIndexingAndSearchingTestCase.java @@ -37,8 +37,8 @@ import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; import org.apache.lucene.search.TermQuery; import org.apache.lucene.search.TopDocs; -import org.apache.lucene.store.BaseDirectoryWrapper; import org.apache.lucene.store.Directory; +import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.util.Bits; import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.FailOnNonBulkMergesInfoStream; @@ -60,7 +60,7 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas protected final AtomicInteger delCount = new AtomicInteger(); protected final AtomicInteger packCount = new AtomicInteger(); - protected Directory dir; + protected MockDirectoryWrapper dir; protected IndexWriter writer; private static class SubDocs { @@ -432,8 +432,8 @@ public abstract class ThreadedIndexingAndSearchingTestCase extends LuceneTestCas Random random = new Random(random().nextLong()); final LineFileDocs docs = new LineFileDocs(random, true); final File tempDir = _TestUtil.getTempDir(testName); - dir = newFSDirectory(tempDir); - ((BaseDirectoryWrapper) dir).setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves. + dir = newMockFSDirectory(tempDir); // some subclasses rely on this being MDW + dir.setCheckIndexOnClose(false); // don't double-checkIndex, we do it ourselves. final IndexWriterConfig conf = newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())).setInfoStream(new FailOnNonBulkMergesInfoStream()); diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java index a656dafd74f..d26b9d47457 100644 --- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java +++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java @@ -806,6 +806,10 @@ public abstract class LuceneTestCase extends Assert { return (MockDirectoryWrapper) wrapDirectory(r, newDirectoryImpl(r, TEST_DIRECTORY), false); } + public static MockDirectoryWrapper newMockFSDirectory(File f) { + return (MockDirectoryWrapper) newFSDirectory(f, null, false); + } + /** * Returns a new Directory instance, with contents copied from the * provided directory. See {@link #newDirectory()} for more @@ -822,6 +826,10 @@ public abstract class LuceneTestCase extends Assert { /** Returns a new FSDirectory instance over the given file, which must be a folder. */ public static BaseDirectoryWrapper newFSDirectory(File f, LockFactory lf) { + return newFSDirectory(f, lf, rarely()); + } + + private static BaseDirectoryWrapper newFSDirectory(File f, LockFactory lf, boolean bare) { String fsdirClass = TEST_DIRECTORY; if (fsdirClass.equals("random")) { fsdirClass = RandomPicks.randomFrom(random(), FS_DIRECTORIES); @@ -838,7 +846,7 @@ public abstract class LuceneTestCase extends Assert { } Directory fsdir = newFSDirectoryImpl(clazz, f); - BaseDirectoryWrapper wrapped = wrapDirectory(random(), fsdir, rarely()); + BaseDirectoryWrapper wrapped = wrapDirectory(random(), fsdir, bare); if (lf != null) { wrapped.setLockFactory(lf); }