Index: lucene/common-build.xml
===================================================================
--- lucene/common-build.xml (revision 988752)
+++ lucene/common-build.xml (working copy)
@@ -66,7 +66,7 @@
-
+
Index: lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java
===================================================================
--- lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java (revision 988752)
+++ lucene/src/test/org/apache/lucene/index/TestTermVectorsReader.java (working copy)
@@ -394,6 +394,8 @@
fail();
} catch (IOException e) {
// expected exception
+ } catch (IllegalArgumentException e) {
+ // mmapdir will give us this from java.nio.Buffer.position()
} finally {
reader.close();
}
@@ -404,6 +406,8 @@
fail();
} catch (IOException e) {
// expected exception
+ } catch (IllegalArgumentException e) {
+ // mmapdir will give us this from java.nio.Buffer.position()
} finally {
reader.close();
}
Index: lucene/src/test/org/apache/lucene/index/TestIndexWriter.java
===================================================================
--- lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (revision 988752)
+++ lucene/src/test/org/apache/lucene/index/TestIndexWriter.java (working copy)
@@ -4377,10 +4377,8 @@
@Override
public void run() {
- Directory dir;
- try {
- dir = newDirectory(random);
- } catch (IOException e) { throw new RuntimeException(e); }
+ // LUCENE-2239: won't work with NIOFS/MMAP
+ Directory dir = new MockDirectoryWrapper(new RAMDirectory());
IndexWriter w = null;
while(!finish) {
try {
Index: lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java
===================================================================
--- lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java (revision 988752)
+++ lucene/src/test/org/apache/lucene/index/TestTransactionRollback.java (working copy)
@@ -126,8 +126,8 @@
@Override
protected void setUp() throws Exception {
super.setUp();
+ random = newRandom();
dir = newDirectory(random);
- random = newRandom();
//Build index, of records 1 to 100, committing after each batch of 10
IndexDeletionPolicy sdp=new KeepAllDeletionPolicy();
IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(sdp));
Index: lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java
===================================================================
--- lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (revision 988752)
+++ lucene/src/test/org/apache/lucene/util/LuceneTestCaseJ4.java (working copy)
@@ -27,6 +27,7 @@
import org.apache.lucene.search.FieldCache;
import org.apache.lucene.search.FieldCache.CacheEntry;
import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.MMapDirectory;
import org.apache.lucene.store.MockDirectoryWrapper;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
@@ -72,6 +73,7 @@
import java.util.regex.Pattern;
import java.util.regex.Matcher;
import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import static org.junit.Assert.assertEquals;
@@ -152,7 +154,7 @@
/** Gets the timezone to run tests with */
static final String TEST_TIMEZONE = System.getProperty("tests.timezone", "random");
/** Gets the directory to run tests with */
- static final String TEST_DIRECTORY = System.getProperty("tests.directory", "RAMDirectory");
+ static final String TEST_DIRECTORY = System.getProperty("tests.directory", "random");
private static final Pattern codecWithParam = Pattern.compile("(.*)\\(\\s*(\\d+)\\s*\\)");
@@ -588,7 +590,7 @@
public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
StackTraceElement[] stack = new Exception().getStackTrace();
- Directory impl = newDirectoryImpl(TEST_DIRECTORY);
+ Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
stores.put(dir, stack);
return dir;
@@ -596,7 +598,7 @@
public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
StackTraceElement[] stack = new Exception().getStackTrace();
- Directory impl = newDirectoryImpl(TEST_DIRECTORY);
+ Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
for (String file : d.listAll()) {
d.copy(impl, file, file);
}
@@ -628,7 +630,24 @@
}
}
- static Directory newDirectoryImpl(String clazzName) {
+ private static String CORE_DIRECTORIES[] = {
+ "RAMDirectory",
+ "SimpleFSDirectory",
+ "NIOFSDirectory",
+ "MMapDirectory"
+ };
+
+ public static String randomDirectory(Random random) {
+ if (random.nextInt(10) == 0) {
+ return CORE_DIRECTORIES[random.nextInt(CORE_DIRECTORIES.length)];
+ } else {
+ return "RAMDirectory";
+ }
+ }
+
+ static Directory newDirectoryImpl(Random random, String clazzName) {
+ if (clazzName.equals("random"))
+ clazzName = randomDirectory(random);
if (clazzName.indexOf(".") == -1) // if not fully qualified, assume .store
clazzName = "org.apache.lucene.store." + clazzName;
try {
@@ -642,7 +661,11 @@
tmpFile.mkdir();
try {
Constructor extends Directory> ctor = clazz.getConstructor(File.class);
- return ctor.newInstance(tmpFile);
+ Directory d = ctor.newInstance(tmpFile);
+ // try not to enable this hack unless we must.
+ if (d instanceof MMapDirectory && Constants.WINDOWS && MMapDirectory.UNMAP_SUPPORTED)
+ ((MMapDirectory)d).setUseUnmap(true);
+ return d;
} catch (Exception e2) {
// try .open(File)
Method method = clazz.getMethod("open", new Class[] { File.class });
Index: lucene/src/test/org/apache/lucene/util/LuceneTestCase.java
===================================================================
--- lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (revision 988752)
+++ lucene/src/test/org/apache/lucene/util/LuceneTestCase.java (working copy)
@@ -335,7 +335,7 @@
public MockDirectoryWrapper newDirectory(Random r) throws IOException {
StackTraceElement[] stack = new Exception().getStackTrace();
- Directory impl = LuceneTestCaseJ4.newDirectoryImpl(TEST_DIRECTORY);
+ Directory impl = LuceneTestCaseJ4.newDirectoryImpl(r, TEST_DIRECTORY);
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
stores.put(dir, stack);
return dir;
@@ -343,7 +343,7 @@
public MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
StackTraceElement[] stack = new Exception().getStackTrace();
- Directory impl = LuceneTestCaseJ4.newDirectoryImpl(TEST_DIRECTORY);
+ Directory impl = LuceneTestCaseJ4.newDirectoryImpl(r, TEST_DIRECTORY);
for (String file : d.listAll()) {
d.copy(impl, file, file);
}