Apache Lucene open-source search software
LUCENE-6436: add SuppressFsync annotation and reduce the number of fsyncs in tests
Robert Muir04f870c1723c
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.javaindex 3d9b00827a3..452b7b66b5c 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/LuceneTestCase.java@@ -312,6 +312,18 @@ public abstract class LuceneTestCase extends Assert {String[] value();}+ /**+ * Annotation for test classes that should avoid always omit+ * actual fsync calls from reaching the filesystem.+ * <p>+ * This can be useful, e.g. if they make many lucene commits.+ */+ @Documented+ @Inherited+ @Retention(RetentionPolicy.RUNTIME)+ @Target(ElementType.TYPE)+ public @interface SuppressFsync {}+/*** Marks any suites which are known not to close all the temporary* files. This may prevent temp. files and folders from being cleaneddiff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.javaindex bef143fdec6..f0b3bce492f 100644--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.java+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.java@@ -23,6 +23,7 @@ import org.apache.lucene.mockfile.LeakFS;import org.apache.lucene.mockfile.VerboseFS;import org.apache.lucene.mockfile.WindowsFS;import org.apache.lucene.util.LuceneTestCase.SuppressFileSystems;+import org.apache.lucene.util.LuceneTestCase.SuppressFsync;import org.apache.lucene.util.LuceneTestCase.SuppressTempFileChecks;import com.carrotsearch.randomizedtesting.RandomizedContext;@@ -138,11 +139,17 @@ final class TestRuleTemporaryFilesCleanup extends TestRuleAdapter {}Random random = RandomizedContext.current().getRandom();- // sometimes just use a bare filesystem- if (random.nextInt(10) > 0) {++ // 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);}+ }++ // otherwise, wrap with mockfilesystems for additional checks. some+ // 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);}