You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by dw...@apache.org on 2026/02/20 20:35:27 UTC
(lucene) branch main updated: Fix flaky testIsLoaded (#15735)
This is an automated email from the ASF dual-hosted git repository.
dweiss pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/lucene.git
The following commit(s) were added to refs/heads/main by this push:
new 338a79181f0 Fix flaky testIsLoaded (#15735)
338a79181f0 is described below
commit 338a79181f0347ce7ba39e0210341c38afbfdbe9
Author: Ben Chaplin <be...@protonmail.com>
AuthorDate: Fri Feb 20 15:35:22 2026 -0500
Fix flaky testIsLoaded (#15735)
* Handle MMapDirectory in FileSwitchDirectory
* Tidy.
---------
Co-authored-by: Dawid Weiss <da...@carrotsearch.com>
---
.../apache/lucene/tests/store/BaseDirectoryTestCase.java | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java
index e65c15eb3a5..9165104f3b0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/store/BaseDirectoryTestCase.java
@@ -55,6 +55,7 @@ import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.ChecksumIndexInput;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.FileSwitchDirectory;
import org.apache.lucene.store.FilterDirectory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
@@ -1628,8 +1629,15 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
private void testIsLoaded(int startOffset) throws IOException {
try (Directory dir = getDirectory(createTempDir())) {
- if (FilterDirectory.unwrap(dir) instanceof MMapDirectory mMapDirectory) {
- mMapDirectory.setPreload(MMapDirectory.ALL_FILES);
+ Directory inner = FilterDirectory.unwrap(dir);
+ if (inner instanceof FileSwitchDirectory fsd) {
+ // We check the secondary directory based on the assumption that the file in this test will
+ // always route there.
+ inner = FilterDirectory.unwrap(fsd.getSecondaryDir());
+ }
+ MMapDirectory mMapDir = inner instanceof MMapDirectory mmap ? mmap : null;
+ if (mMapDir != null) {
+ mMapDir.setPreload(MMapDirectory.ALL_FILES);
}
final int totalLength = startOffset + TestUtil.nextInt(random(), 16384, 65536);
byte[] arr = new byte[totalLength];
@@ -1649,7 +1657,7 @@ public abstract class BaseDirectoryTestCase extends LuceneTestCase {
if (Constants.WINDOWS) {
// On Windows, we temporarily don't care until this is fixed: #14050
- } else if (FilterDirectory.unwrap(dir) instanceof MMapDirectory
+ } else if (mMapDir != null
// direct IO wraps MMap but does not support isLoaded
&& !(dir.getClass().getName().contains("DirectIO"))) {
assertTrue(loaded.isPresent());