mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
19e25c78b6
commit
04f870c172
|
@ -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 cleaned
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue