Apache Lucene open-source search software
LUCENE-10088: allow per-class override in HandleLimitFS. Bump the limit a bit for nightlies in TestIndexWriterMergePolicy. (#424)
Dawid Weissadec73dd284e
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.javaindex 2578712bba5..6192e0ed3e4 100644--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriterMergePolicy.java@@ -28,12 +28,14 @@ import org.apache.lucene.document.Field;import org.apache.lucene.document.NumericDocValuesField;import org.apache.lucene.document.StringField;import org.apache.lucene.index.IndexWriterConfig.OpenMode;+import org.apache.lucene.mockfile.HandleLimitFS;import org.apache.lucene.search.IndexSearcher;import org.apache.lucene.search.MatchAllDocsQuery;import org.apache.lucene.search.TermQuery;import org.apache.lucene.store.Directory;import org.apache.lucene.util.LuceneTestCase;[email protected](limit = HandleLimitFS.MaxOpenHandles.MAX_OPEN_FILES * 2)public class TestIndexWriterMergePolicy extends LuceneTestCase {// Test the normal case@@ -772,9 +774,9 @@ public class TestIndexWriterMergePolicy extends LuceneTestCase {if (random().nextBoolean()) {writer.commit();}- try (DirectoryReader open =- new SoftDeletesDirectoryReaderWrapper(- DirectoryReader.open(directory), "___soft_deletes")) {+ try (DirectoryReader delegate = DirectoryReader.open(directory);+ DirectoryReader open =+ new SoftDeletesDirectoryReaderWrapper(delegate, "___soft_deletes")) {assertEquals(1,new IndexSearcher(open)diff --git a/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleLimitFS.java b/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleLimitFS.javaindex 393c1de94f9..ece3ba2c648 100644--- a/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleLimitFS.java+++ b/lucene/test-framework/src/java/org/apache/lucene/mockfile/HandleLimitFS.java@@ -17,16 +17,38 @@package org.apache.lucene.mockfile;import java.io.IOException;+import java.lang.annotation.Documented;+import java.lang.annotation.ElementType;+import java.lang.annotation.Inherited;+import java.lang.annotation.Retention;+import java.lang.annotation.RetentionPolicy;+import java.lang.annotation.Target;import java.nio.file.FileSystem;import java.nio.file.FileSystemException;import java.nio.file.Path;import java.util.concurrent.atomic.AtomicInteger;-/** FileSystem that throws exception if file handles in use exceeds a specified limit */+/**+ * FileSystem that throws exception if file handles in use exceeds a specified limit.+ *+ * @see MaxOpenHandles+ */public class HandleLimitFS extends HandleTrackingFS {final int limit;final AtomicInteger count = new AtomicInteger();+ /** An annotation */+ @Documented+ @Inherited+ @Retention(RetentionPolicy.RUNTIME)+ @Target(ElementType.TYPE)+ public static @interface MaxOpenHandles {+ // TODO: can we make the default even lower?+ public static final int MAX_OPEN_FILES = 2048;++ int limit();+ }+/*** Create a new instance, limiting the maximum number of open files to {@code limit}*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.javaindex 3b0b1530448..6c67efd2523 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@@ -100,10 +100,6 @@ final class TestRuleTemporaryFilesCleanup extends TestRuleAdapter {javaTempDir = initializeJavaTempDir();}- // os/config-independent limit for too many open files- // TODO: can we make this lower?- private static final int MAX_OPEN_FILES = 2048;-private boolean allowed(Set<String> avoid, Class<? extends FileSystemProvider> clazz) {if (avoid.contains("*") || avoid.contains(clazz.getSimpleName())) {return false;@@ -152,7 +148,11 @@ final class TestRuleTemporaryFilesCleanup extends TestRuleAdapter {fs = new LeakFS(fs).getFileSystem(null);}if (allowed(avoid, HandleLimitFS.class)) {- fs = new HandleLimitFS(fs, MAX_OPEN_FILES).getFileSystem(null);+ int limit = HandleLimitFS.MaxOpenHandles.MAX_OPEN_FILES;+ if (targetClass.isAnnotationPresent(HandleLimitFS.MaxOpenHandles.class)) {+ limit = targetClass.getAnnotation(HandleLimitFS.MaxOpenHandles.class).limit();+ }+ fs = new HandleLimitFS(fs, limit).getFileSystem(null);}// windows is currently slowif (random.nextInt(10) == 0) {