Skip to content

Apache Lucene open-source search software

LUCENE-6989: Fix some tests that hardcode MMapDirectory (and also the FSDirectory randomizer), to only use MMapDirectory on Windows, if it supports unmapping. Otherwise tests will fail.

Uwe Schindlerd5e87898b184
diff --git a/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java b/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
index 7e173c84522..2242a1e856d 100644
--- a/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
+++ b/lucene/core/src/test/org/apache/lucene/index/Test4GBStoredFields.java
@@ -41,6 +41,8 @@ public class Test4GBStoredFields extends LuceneTestCase {
@Nightly
public void test() throws Exception {
+ assumeWorkingMMapOnWindows();
+
MockDirectoryWrapper dir = new MockDirectoryWrapper(random(), new MMapDirectory(createTempDir("4GBStoredFields")));
dir.setThrottling(MockDirectoryWrapper.Throttling.NEVER);
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 a99576305a1..e4f0ab0d55d 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -1251,8 +1251,9 @@ public class TestIndexWriter extends LuceneTestCase {
public void testDeleteUnusedFiles() throws Exception {
-
assumeFalse("test relies on exact filenames", Codec.getDefault() instanceof SimpleTextCodec);
+ assumeWorkingMMapOnWindows();
+
for(int iter=0;iter<2;iter++) {
// relies on windows semantics
Path path = createTempDir();
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
index 88f304b74fa..5e4a5934d34 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestDirectory.java
@@ -20,6 +20,7 @@ package org.apache.lucene.store;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -37,11 +38,13 @@ public class TestDirectory extends LuceneTestCase {
largeBuffer[i] = (byte) i; // automatically loops with modulo
}
- final FSDirectory[] dirs = new FSDirectory[] {
- new SimpleFSDirectory(path),
- new NIOFSDirectory(path),
- new MMapDirectory(path)
- };
+ final List<FSDirectory> dirs0 = new ArrayList<>();
+ dirs0.add(new SimpleFSDirectory(path));
+ dirs0.add(new NIOFSDirectory(path));
+ if (hasWorkingMMapOnWindows()) {
+ dirs0.add(new MMapDirectory(path));
+ }
+ final FSDirectory[] dirs = dirs0.stream().toArray(FSDirectory[]::new);
for (int i=0; i<dirs.length; i++) {
FSDirectory dir = dirs[i];
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
index 098fd44519b..77b4ab46920 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMmapDirectory.java
@@ -39,8 +39,7 @@ public class TestMmapDirectory extends BaseDirectoryTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
- assumeTrue("test requires a jre that supports unmapping: " + MMapDirectory.UNMAP_NOT_SUPPORTED_REASON,
- MMapDirectory.UNMAP_SUPPORTED);
+ assumeTrue(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, MMapDirectory.UNMAP_SUPPORTED);
}
@Ignore("This test is for JVM testing purposes. There are no guarantees that it may not fail with SIGSEGV!")
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
index 76632cbbaf7..3a03ea93ad2 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestMultiMMap.java
@@ -46,8 +46,7 @@ public class TestMultiMMap extends BaseDirectoryTestCase {
@Override
public void setUp() throws Exception {
super.setUp();
- assumeTrue("test requires a jre that supports unmapping: " + MMapDirectory.UNMAP_NOT_SUPPORTED_REASON,
- MMapDirectory.UNMAP_SUPPORTED);
+ assumeTrue(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, MMapDirectory.UNMAP_SUPPORTED);
}
public void testCloneSafety() throws Exception {
diff --git a/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java b/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
index a02bf8afafe..828dcbe43f6 100644
--- a/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
+++ b/lucene/core/src/test/org/apache/lucene/util/fst/Test2BFST.java
@@ -40,6 +40,8 @@ public class Test2BFST extends LuceneTestCase {
private static long LIMIT = 3L*1024*1024*1024;
public void test() throws Exception {
+ assumeWorkingMMapOnWindows();
+
int[] ints = new int[7];
IntsRef input = new IntsRef(ints, 0, ints.length);
long seed = random().nextLong();
diff --git a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
index a4d59dec4c3..554d9085d56 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/index/BaseStoredFieldsFormatTestCase.java
@@ -663,6 +663,8 @@ public abstract class BaseStoredFieldsFormatTestCase extends BaseIndexFileFormat
@Nightly
public void testBigDocuments() throws IOException {
+ assumeWorkingMMapOnWindows();
+
// "big" as "much bigger than the chunk size"
// for this test we force a FS dir
// we can't just use newFSDirectory, because this test doesn't really index anything.
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 e9dc5ab16e2..1848c4e7964 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
@@ -94,6 +94,7 @@ import org.apache.lucene.store.FSLockFactory;
import org.apache.lucene.store.FlushInfo;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.LockFactory;
+import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.store.MergeInfo;
import org.apache.lucene.store.MockDirectoryWrapper.Throttling;
import org.apache.lucene.store.MockDirectoryWrapper;
@@ -456,11 +457,24 @@ public abstract class LuceneTestCase extends Assert {
LEAVE_TEMPORARY = defaultValue;
}
+ /** Returns true, if MMapDirectory supports unmapping on this platform (required for Windows), or if we are not on Windows. */
+ public static boolean hasWorkingMMapOnWindows() {
+ return !Constants.WINDOWS || MMapDirectory.UNMAP_SUPPORTED;
+ }
+
+ /** Assumes that the current MMapDirectory implementation supports unmapping, so the test will not fail on Windows.
+ * @see #hasWorkingMMapOnWindows()
+ * */
+ public static void assumeWorkingMMapOnWindows() {
+ assumeTrue(MMapDirectory.UNMAP_NOT_SUPPORTED_REASON, hasWorkingMMapOnWindows());
+ }
+
/** Filesystem-based {@link Directory} implementations. */
private static final List<String> FS_DIRECTORIES = Arrays.asList(
"SimpleFSDirectory",
"NIOFSDirectory",
- "MMapDirectory"
+ // SimpleFSDirectory as replacement for MMapDirectory if unmapping is not supported on Windows (to make randomization stable):
+ hasWorkingMMapOnWindows() ? "MMapDirectory" : "SimpleFSDirectory"
);
/** All {@link Directory} implementations. */
@@ -469,7 +483,7 @@ public abstract class LuceneTestCase extends Assert {
CORE_DIRECTORIES = new ArrayList<>(FS_DIRECTORIES);
CORE_DIRECTORIES.add("RAMDirectory");
}
-
+
/** A {@link org.apache.lucene.search.QueryCachingPolicy} that randomly caches. */
public static final QueryCachingPolicy MAYBE_CACHE_POLICY = new QueryCachingPolicy() {
@@ -853,7 +867,7 @@ public abstract class LuceneTestCase extends Assert {
public static void assumeNoException(String msg, Exception e) {
RandomizedTest.assumeNoException(msg, e);
}
-
+
/**
* Return <code>args</code> as a {@link Set} instance. The order of elements is not
* preserved in iterators.