From 53597e8f8e3fe97ce06cfcb98ab313ee7c9ae45f Mon Sep 17 00:00:00 2001 From: Mike McCandless Date: Sun, 7 Feb 2016 07:04:10 -0500 Subject: [PATCH] try to fix test bug, so that on Windows instead of relying on WindowsFS to prevent deletion of open files, we rely on the OS itself --- .../test/org/apache/lucene/index/TestIndexWriter.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java index 4f6ef89814f..b9dd899ab76 100644 --- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java +++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java @@ -78,6 +78,7 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.store.LockObtainFailedException; +import org.apache.lucene.store.MMapDirectory; import org.apache.lucene.store.MockDirectoryWrapper; import org.apache.lucene.store.NIOFSDirectory; import org.apache.lucene.store.NoLockFactory; @@ -1268,8 +1269,14 @@ public class TestIndexWriter extends LuceneTestCase { FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///")); Path indexPath = new FilterPath(path, fs); - // NOTE: cannot use MMapDir, because WindowsFS doesn't see/think it keeps file handles open? - FSDirectory dir = new NIOFSDirectory(indexPath); + // NOTE: on Unix, we cannot use MMapDir, because WindowsFS doesn't see/think it keeps file handles open. Yet, on Windows, we MUST use + // MMapDir because the windows OS will in fact prevent file deletion for us, and fails otherwise: + FSDirectory dir; + if (Constants.WINDOWS) { + dir = new MMapDirectory(indexPath); + } else { + dir = new NIOFSDirectory(indexPath); + } MergePolicy mergePolicy = newLogMergePolicy(true);