Search in sources :

Example 6 with WindowsFS

use of org.apache.lucene.mockfile.WindowsFS in project lucene-solr by apache.

the class TestRuleTemporaryFilesCleanup method initializeFileSystem.

private FileSystem initializeFileSystem() {
    Class<?> targetClass = RandomizedContext.current().getTargetClass();
    Set<String> avoid = new HashSet<>();
    if (targetClass.isAnnotationPresent(SuppressFileSystems.class)) {
        SuppressFileSystems a = targetClass.getAnnotation(SuppressFileSystems.class);
        avoid.addAll(Arrays.asList(a.value()));
    }
    FileSystem fs = FileSystems.getDefault();
    if (LuceneTestCase.VERBOSE && allowed(avoid, VerboseFS.class)) {
        fs = new VerboseFS(fs, new TestRuleSetupAndRestoreClassEnv.ThreadNameFixingPrintStreamInfoStream(System.out)).getFileSystem(null);
    }
    Random random = RandomizedContext.current().getRandom();
    // speed up tests by omitting actual fsync calls to the hardware most of the time.
    if (targetClass.isAnnotationPresent(SuppressFsync.class) || random.nextInt(100) > 0) {
        if (allowed(avoid, DisableFsyncFS.class)) {
            fs = new DisableFsyncFS(fs).getFileSystem(null);
        }
    }
    // impacts test reproducibility across platforms.
    if (random.nextInt(100) > 0) {
        if (allowed(avoid, ShuffleFS.class)) {
            fs = new ShuffleFS(fs, random.nextLong()).getFileSystem(null);
        }
    }
    // of these have side effects (e.g. concurrency) so it doesn't always happen.
    if (random.nextInt(10) > 0) {
        if (allowed(avoid, LeakFS.class)) {
            fs = new LeakFS(fs).getFileSystem(null);
        }
        if (allowed(avoid, HandleLimitFS.class)) {
            fs = new HandleLimitFS(fs, MAX_OPEN_FILES).getFileSystem(null);
        }
        // windows is currently slow
        if (random.nextInt(10) == 0) {
            // don't try to emulate windows on windows: they don't get along
            if (!Constants.WINDOWS && allowed(avoid, WindowsFS.class)) {
                fs = new WindowsFS(fs).getFileSystem(null);
            }
        }
        if (allowed(avoid, ExtrasFS.class)) {
            fs = new ExtrasFS(fs, random.nextInt(4) == 0, random.nextBoolean()).getFileSystem(null);
        }
    }
    if (LuceneTestCase.VERBOSE) {
        System.out.println("filesystem: " + fs.provider());
    }
    return fs.provider().getFileSystem(URI.create("file:///"));
}
Also used : SuppressFileSystems(org.apache.lucene.util.LuceneTestCase.SuppressFileSystems) ShuffleFS(org.apache.lucene.mockfile.ShuffleFS) VerboseFS(org.apache.lucene.mockfile.VerboseFS) SuppressFsync(org.apache.lucene.util.LuceneTestCase.SuppressFsync) HandleLimitFS(org.apache.lucene.mockfile.HandleLimitFS) WindowsFS(org.apache.lucene.mockfile.WindowsFS) ExtrasFS(org.apache.lucene.mockfile.ExtrasFS) Random(java.util.Random) FileSystem(java.nio.file.FileSystem) DisableFsyncFS(org.apache.lucene.mockfile.DisableFsyncFS) LeakFS(org.apache.lucene.mockfile.LeakFS) HashSet(java.util.HashSet)

Aggregations

WindowsFS (org.apache.lucene.mockfile.WindowsFS)6 FileSystem (java.nio.file.FileSystem)5 Path (java.nio.file.Path)4 FilterPath (org.apache.lucene.mockfile.FilterPath)3 FSDirectory (org.apache.lucene.store.FSDirectory)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 Document (org.apache.lucene.document.Document)2 FilterFileSystem (org.apache.lucene.mockfile.FilterFileSystem)2 NIOFSDirectory (org.apache.lucene.store.NIOFSDirectory)2 SimpleFSDirectory (org.apache.lucene.store.SimpleFSDirectory)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Exception (java.lang.Exception)1 RuntimeException (java.lang.RuntimeException)1 NoSuchFileException (java.nio.file.NoSuchFileException)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 CyclicBarrier (java.util.concurrent.CyclicBarrier)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1