use of org.apache.lucene.mockfile.HandleLimitFS 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:///"));
}
Aggregations