From 04f870c1723c191f5fb5d2354f4125dd3697d16a Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Sat, 18 Apr 2015 19:27:57 +0000 Subject: [PATCH] LUCENE-6436: add SuppressFsync annotation and reduce the number of fsyncs in tests git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1674570 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/lucene/util/LuceneTestCase.java | 12 ++++++++++++ .../lucene/util/TestRuleTemporaryFilesCleanup.java | 11 +++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) 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.java index 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. + *

+ * 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 cleaned diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleTemporaryFilesCleanup.java index 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); }