Search in sources :

Example 1 with FSLockFactory

use of org.apache.lucene.store.FSLockFactory in project lucene-solr by apache.

the class LuceneTestCase method newDirectoryImpl.

static Directory newDirectoryImpl(Random random, String clazzName, LockFactory lf) {
    if (clazzName.equals("random")) {
        if (rarely(random)) {
            clazzName = RandomPicks.randomFrom(random, CORE_DIRECTORIES);
        } else {
            clazzName = "RAMDirectory";
        }
    }
    try {
        final Class<? extends Directory> clazz = CommandLineUtil.loadDirectoryClass(clazzName);
        // If it is a FSDirectory type, try its ctor(Path)
        if (FSDirectory.class.isAssignableFrom(clazz)) {
            final Path dir = createTempDir("index-" + clazzName);
            return newFSDirectoryImpl(clazz.asSubclass(FSDirectory.class), dir, lf);
        }
        // FSDir subclass:
        try {
            Constructor<? extends Directory> pathCtor = clazz.getConstructor(Path.class, LockFactory.class);
            final Path dir = createTempDir("index");
            return pathCtor.newInstance(dir, lf);
        } catch (NoSuchMethodException nsme) {
        // Ignore
        }
        // the remaining dirs are no longer filesystem based, so we must check that the passedLockFactory is not file based:
        if (!(lf instanceof FSLockFactory)) {
            // try ctor with only LockFactory (e.g. RAMDirectory)
            try {
                return clazz.getConstructor(LockFactory.class).newInstance(lf);
            } catch (NoSuchMethodException nsme) {
            // Ignore
            }
        }
        // try empty ctor
        return clazz.newInstance();
    } catch (Exception e) {
        Rethrow.rethrow(e);
        // dummy to prevent compiler failure
        throw null;
    }
}
Also used : FilterPath(org.apache.lucene.mockfile.FilterPath) Path(java.nio.file.Path) FSLockFactory(org.apache.lucene.store.FSLockFactory) FSDirectory(org.apache.lucene.store.FSDirectory) FSLockFactory(org.apache.lucene.store.FSLockFactory) LockFactory(org.apache.lucene.store.LockFactory) PrivilegedActionException(java.security.PrivilegedActionException) IOException(java.io.IOException) NoSuchFileException(java.nio.file.NoSuchFileException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 Path (java.nio.file.Path)1 PrivilegedActionException (java.security.PrivilegedActionException)1 FilterPath (org.apache.lucene.mockfile.FilterPath)1 FSDirectory (org.apache.lucene.store.FSDirectory)1 FSLockFactory (org.apache.lucene.store.FSLockFactory)1 LockFactory (org.apache.lucene.store.LockFactory)1