mirror of
https://github.com/apache/lucene.git
synced 2025-02-07 18:49:03 +00:00
LUCENE-2598: fixes for tests with NIOFS/MMap, add random option (but RAMDirectory is still the default)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@989030 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
5a62c7c81c
commit
fcfa3ef727
@ -4377,10 +4377,8 @@ public class TestIndexWriter extends LuceneTestCase {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
Directory dir;
|
// LUCENE-2239: won't work with NIOFS/MMAP
|
||||||
try {
|
Directory dir = new MockDirectoryWrapper(new RAMDirectory());
|
||||||
dir = newDirectory(random);
|
|
||||||
} catch (IOException e) { throw new RuntimeException(e); }
|
|
||||||
IndexWriter w = null;
|
IndexWriter w = null;
|
||||||
while(!finish) {
|
while(!finish) {
|
||||||
try {
|
try {
|
||||||
|
@ -394,6 +394,8 @@ public class TestTermVectorsReader extends LuceneTestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// expected exception
|
// expected exception
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// mmapdir will give us this from java.nio.Buffer.position()
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
@ -404,6 +406,8 @@ public class TestTermVectorsReader extends LuceneTestCase {
|
|||||||
fail();
|
fail();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// expected exception
|
// expected exception
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// mmapdir will give us this from java.nio.Buffer.position()
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
reader.close();
|
||||||
}
|
}
|
||||||
|
@ -126,8 +126,8 @@ public class TestTransactionRollback extends LuceneTestCase {
|
|||||||
@Override
|
@Override
|
||||||
protected void setUp() throws Exception {
|
protected void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
|
random = newRandom();
|
||||||
dir = newDirectory(random);
|
dir = newDirectory(random);
|
||||||
random = newRandom();
|
|
||||||
//Build index, of records 1 to 100, committing after each batch of 10
|
//Build index, of records 1 to 100, committing after each batch of 10
|
||||||
IndexDeletionPolicy sdp=new KeepAllDeletionPolicy();
|
IndexDeletionPolicy sdp=new KeepAllDeletionPolicy();
|
||||||
IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(sdp));
|
IndexWriter w=new IndexWriter(dir, newIndexWriterConfig(random, TEST_VERSION_CURRENT, new MockAnalyzer()).setIndexDeletionPolicy(sdp));
|
||||||
|
@ -335,7 +335,7 @@ public abstract class LuceneTestCase extends TestCase {
|
|||||||
|
|
||||||
public MockDirectoryWrapper newDirectory(Random r) throws IOException {
|
public MockDirectoryWrapper newDirectory(Random r) throws IOException {
|
||||||
StackTraceElement[] stack = new Exception().getStackTrace();
|
StackTraceElement[] stack = new Exception().getStackTrace();
|
||||||
Directory impl = LuceneTestCaseJ4.newDirectoryImpl(TEST_DIRECTORY);
|
Directory impl = LuceneTestCaseJ4.newDirectoryImpl(r, TEST_DIRECTORY);
|
||||||
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
|
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
|
||||||
stores.put(dir, stack);
|
stores.put(dir, stack);
|
||||||
return dir;
|
return dir;
|
||||||
@ -343,7 +343,7 @@ public abstract class LuceneTestCase extends TestCase {
|
|||||||
|
|
||||||
public MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
|
public MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
|
||||||
StackTraceElement[] stack = new Exception().getStackTrace();
|
StackTraceElement[] stack = new Exception().getStackTrace();
|
||||||
Directory impl = LuceneTestCaseJ4.newDirectoryImpl(TEST_DIRECTORY);
|
Directory impl = LuceneTestCaseJ4.newDirectoryImpl(r, TEST_DIRECTORY);
|
||||||
for (String file : d.listAll()) {
|
for (String file : d.listAll()) {
|
||||||
d.copy(impl, file, file);
|
d.copy(impl, file, file);
|
||||||
}
|
}
|
||||||
|
@ -27,6 +27,7 @@ import org.apache.lucene.search.BooleanQuery;
|
|||||||
import org.apache.lucene.search.FieldCache;
|
import org.apache.lucene.search.FieldCache;
|
||||||
import org.apache.lucene.search.FieldCache.CacheEntry;
|
import org.apache.lucene.search.FieldCache.CacheEntry;
|
||||||
import org.apache.lucene.store.Directory;
|
import org.apache.lucene.store.Directory;
|
||||||
|
import org.apache.lucene.store.MMapDirectory;
|
||||||
import org.apache.lucene.store.MockDirectoryWrapper;
|
import org.apache.lucene.store.MockDirectoryWrapper;
|
||||||
import org.apache.lucene.store.RAMDirectory;
|
import org.apache.lucene.store.RAMDirectory;
|
||||||
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
|
import org.apache.lucene.util.FieldCacheSanityChecker.Insanity;
|
||||||
@ -72,6 +73,7 @@ import java.util.Collections;
|
|||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
@ -588,7 +590,7 @@ public class LuceneTestCaseJ4 {
|
|||||||
|
|
||||||
public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
|
public static MockDirectoryWrapper newDirectory(Random r) throws IOException {
|
||||||
StackTraceElement[] stack = new Exception().getStackTrace();
|
StackTraceElement[] stack = new Exception().getStackTrace();
|
||||||
Directory impl = newDirectoryImpl(TEST_DIRECTORY);
|
Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
|
||||||
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
|
MockDirectoryWrapper dir = new MockDirectoryWrapper(impl);
|
||||||
stores.put(dir, stack);
|
stores.put(dir, stack);
|
||||||
return dir;
|
return dir;
|
||||||
@ -596,7 +598,7 @@ public class LuceneTestCaseJ4 {
|
|||||||
|
|
||||||
public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
|
public static MockDirectoryWrapper newDirectory(Random r, Directory d) throws IOException {
|
||||||
StackTraceElement[] stack = new Exception().getStackTrace();
|
StackTraceElement[] stack = new Exception().getStackTrace();
|
||||||
Directory impl = newDirectoryImpl(TEST_DIRECTORY);
|
Directory impl = newDirectoryImpl(r, TEST_DIRECTORY);
|
||||||
for (String file : d.listAll()) {
|
for (String file : d.listAll()) {
|
||||||
d.copy(impl, file, file);
|
d.copy(impl, file, file);
|
||||||
}
|
}
|
||||||
@ -628,7 +630,24 @@ public class LuceneTestCaseJ4 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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
|
if (clazzName.indexOf(".") == -1) // if not fully qualified, assume .store
|
||||||
clazzName = "org.apache.lucene.store." + clazzName;
|
clazzName = "org.apache.lucene.store." + clazzName;
|
||||||
try {
|
try {
|
||||||
@ -642,7 +661,11 @@ public class LuceneTestCaseJ4 {
|
|||||||
tmpFile.mkdir();
|
tmpFile.mkdir();
|
||||||
try {
|
try {
|
||||||
Constructor<? extends Directory> ctor = clazz.getConstructor(File.class);
|
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) {
|
} catch (Exception e2) {
|
||||||
// try .open(File)
|
// try .open(File)
|
||||||
Method method = clazz.getMethod("open", new Class[] { File.class });
|
Method method = clazz.getMethod("open", new Class[] { File.class });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user