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

This commit is contained in:
Mike McCandless 2016-02-07 07:04:10 -05:00
parent 2a7687641e
commit 53597e8f8e
1 changed files with 9 additions and 2 deletions

View File

@ -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);