mirror of https://github.com/apache/lucene.git
LUCENE-10088: allow per-class override in HandleLimitFS. Bump the limit a bit for nightlies in TestIndexWriterMergePolicy. (#424)
This commit is contained in:
parent
1ae6b2a6b9
commit
adec73dd28
|
@ -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;
|
||||
|
||||
@HandleLimitFS.MaxOpenHandles(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)
|
||||
|
|
|
@ -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}
|
||||
*
|
||||
|
|
|
@ -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 slow
|
||||
if (random.nextInt(10) == 0) {
|
||||
|
|
Loading…
Reference in New Issue