Search in sources :

Example 1 with VerboseFS

use of org.apache.lucene.mockfile.VerboseFS 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

FileSystem (java.nio.file.FileSystem)1 HashSet (java.util.HashSet)1 Random (java.util.Random)1 DisableFsyncFS (org.apache.lucene.mockfile.DisableFsyncFS)1 ExtrasFS (org.apache.lucene.mockfile.ExtrasFS)1 HandleLimitFS (org.apache.lucene.mockfile.HandleLimitFS)1 LeakFS (org.apache.lucene.mockfile.LeakFS)1 ShuffleFS (org.apache.lucene.mockfile.ShuffleFS)1 VerboseFS (org.apache.lucene.mockfile.VerboseFS)1 WindowsFS (org.apache.lucene.mockfile.WindowsFS)1 SuppressFileSystems (org.apache.lucene.util.LuceneTestCase.SuppressFileSystems)1 SuppressFsync (org.apache.lucene.util.LuceneTestCase.SuppressFsync)1