Skip to content

Apache Lucene open-source search software

LUCENE-10526: add single method to mockfile to wrap a Path (#822)

Robert Muir844bd8883980
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt
index fef1ec97da4..fdacfdb6687 100644
--- a/lucene/CHANGES.txt
+++ b/lucene/CHANGES.txt
@@ -147,7 +147,8 @@ Build
Other
---------------------
-(No changes)
+* LUCENE-10526: Test-framework: Add FilterFileSystemProvider.wrapPath(Path) method for mock filesystems
+ to override if they need to extend the Path implementation. (Gautam Worah, Robert Muir)
======================= Lucene 9.1.0 =======================
diff --git a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
index e1ae2b25899..1f242173059 100644
--- a/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
+++ b/lucene/core/src/test/org/apache/lucene/index/TestIndexWriter.java
@@ -27,8 +27,6 @@ import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
-import java.net.URI;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
@@ -100,7 +98,6 @@ import org.apache.lucene.tests.analysis.Token;
import org.apache.lucene.tests.index.RandomIndexWriter;
import org.apache.lucene.tests.index.SuppressingConcurrentMergeScheduler;
import org.apache.lucene.tests.mockfile.ExtrasFS;
-import org.apache.lucene.tests.mockfile.FilterPath;
import org.apache.lucene.tests.mockfile.WindowsFS;
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
import org.apache.lucene.tests.store.MockDirectoryWrapper;
@@ -1272,8 +1269,8 @@ public class TestIndexWriter extends LuceneTestCase {
for (int iter = 0; iter < 2; iter++) {
// relies on windows semantics
Path path = createTempDir();
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path indexPath = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path indexPath = provider.wrapPath(path);
// NOTE: on Unix, we cannot use MMapDir, because WindowsFS doesn't see/think it keeps file
// handles open. Yet, on Windows, we MUST use
@@ -2807,8 +2804,8 @@ public class TestIndexWriter extends LuceneTestCase {
Path path = createTempDir();
// Use WindowsFS to prevent open files from being deleted:
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path root = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path root = provider.wrapPath(path);
// MMapDirectory doesn't work because it closes its file handles after mapping!
List<Closeable> toClose = new ArrayList<>();
@@ -2879,8 +2876,8 @@ public class TestIndexWriter extends LuceneTestCase {
Path path = createTempDir();
// Use WindowsFS to prevent open files from being deleted:
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path root = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path root = provider.wrapPath(path);
try (FSDirectory _dir = new NIOFSDirectory(root)) {
Directory dir = new FilterDirectory(_dir) {};
@@ -2918,8 +2915,8 @@ public class TestIndexWriter extends LuceneTestCase {
Path path = createTempDir();
// Use WindowsFS to prevent open files from being deleted:
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path root = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path root = provider.wrapPath(path);
IndexCommit indexCommit;
DirectoryReader reader;
// MMapDirectory doesn't work because it closes its file handles after mapping!
@@ -2973,8 +2970,8 @@ public class TestIndexWriter extends LuceneTestCase {
assumeFalse("windows is not supported", Constants.WINDOWS);
// Use WindowsFS to prevent open files from being deleted:
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path root = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path root = provider.wrapPath(path);
// MMapDirectory doesn't work because it closes its file handles after mapping!
try (FSDirectory dir = new NIOFSDirectory(root)) {
IndexWriterConfig iwc = new IndexWriterConfig(new MockAnalyzer(random()));
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
index e09d71c3098..2298ef82ea3 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestFileSwitchDirectory.java
@@ -17,9 +17,7 @@
package org.apache.lucene.store;
import java.io.IOException;
-import java.net.URI;
import java.nio.file.AtomicMoveNotSupportedException;
-import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
@@ -34,7 +32,6 @@ import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.TestIndexWriterReader;
import org.apache.lucene.tests.analysis.MockAnalyzer;
-import org.apache.lucene.tests.mockfile.FilterPath;
import org.apache.lucene.tests.mockfile.WindowsFS;
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
import org.apache.lucene.tests.store.MockDirectoryWrapper;
@@ -180,8 +177,8 @@ public class TestFileSwitchDirectory extends BaseDirectoryTestCase {
// relies on windows semantics
Path path = createTempDir();
assumeFalse("Irony we seem to not emulate windows well enough", Constants.WINDOWS);
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Path indexPath = new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Path indexPath = provider.wrapPath(path);
try (final FileSwitchDirectory dir =
new FileSwitchDirectory(
Collections.singleton("tim"),
diff --git a/lucene/core/src/test/org/apache/lucene/store/TestNIOFSDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestNIOFSDirectory.java
index 01c79c1a4eb..768dac675f0 100644
--- a/lucene/core/src/test/org/apache/lucene/store/TestNIOFSDirectory.java
+++ b/lucene/core/src/test/org/apache/lucene/store/TestNIOFSDirectory.java
@@ -17,15 +17,12 @@
package org.apache.lucene.store;
import java.io.IOException;
-import java.net.URI;
import java.nio.channels.FileChannel;
-import java.nio.file.FileSystem;
import java.nio.file.OpenOption;
import java.nio.file.Path;
import java.nio.file.attribute.FileAttribute;
import java.util.Set;
import org.apache.lucene.tests.mockfile.FilterFileChannel;
-import org.apache.lucene.tests.mockfile.FilterPath;
import org.apache.lucene.tests.mockfile.LeakFS;
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
@@ -53,8 +50,7 @@ public class TestNIOFSDirectory extends BaseDirectoryTestCase {
};
}
};
- FileSystem fs = leakFS.getFileSystem(URI.create("file:///"));
- Path wrapped = new FilterPath(path, fs);
+ Path wrapped = leakFS.wrapPath(path);
try (Directory dir = new NIOFSDirectory(wrapped)) {
try (IndexOutput out = dir.createOutput("test.bin", IOContext.DEFAULT)) {
out.writeString("hello");
diff --git a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
index 288e25523f1..44c7b3add64 100644
--- a/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
+++ b/lucene/core/src/test/org/apache/lucene/util/TestIOUtils.java
@@ -18,7 +18,6 @@ package org.apache.lucene.util;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.channels.FileChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.AccessDeniedException;
@@ -125,10 +124,9 @@ public class TestIOUtils extends LuceneTestCase {
public void testFsyncAccessDeniedOpeningDirectory() throws Exception {
final Path path = createTempDir().toRealPath();
- final FileSystem fs =
- new AccessDeniedWhileOpeningDirectoryFileSystem(path.getFileSystem())
- .getFileSystem(URI.create("file:///"));
- final Path wrapped = new FilterPath(path, fs);
+ final FilterFileSystemProvider provider =
+ new AccessDeniedWhileOpeningDirectoryFileSystem(path.getFileSystem());
+ final Path wrapped = provider.wrapPath(path);
if (Constants.WINDOWS) {
// no exception, we early return and do not even try to open the directory
IOUtils.fsync(wrapped, true);
diff --git a/lucene/misc/src/test/org/apache/lucene/misc/store/TestHardLinkCopyDirectoryWrapper.java b/lucene/misc/src/test/org/apache/lucene/misc/store/TestHardLinkCopyDirectoryWrapper.java
index f58530f9fb4..4e83f23da41 100644
--- a/lucene/misc/src/test/org/apache/lucene/misc/store/TestHardLinkCopyDirectoryWrapper.java
+++ b/lucene/misc/src/test/org/apache/lucene/misc/store/TestHardLinkCopyDirectoryWrapper.java
@@ -18,8 +18,6 @@
package org.apache.lucene.misc.store;
import java.io.IOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;
@@ -33,7 +31,6 @@ import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.NIOFSDirectory;
-import org.apache.lucene.tests.mockfile.FilterPath;
import org.apache.lucene.tests.mockfile.WindowsFS;
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
import org.apache.lucene.util.Constants;
@@ -111,9 +108,9 @@ public class TestHardLinkCopyDirectoryWrapper extends BaseDirectoryTestCase {
// irony: currently we don't emulate windows well enough to work on windows!
assumeFalse("windows is not supported", Constants.WINDOWS);
Path path = createTempDir();
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- Directory dir1 = new NIOFSDirectory(new FilterPath(path, fs));
- Directory dir2 = new NIOFSDirectory(new FilterPath(path.resolve("link"), fs));
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ Directory dir1 = new NIOFSDirectory(provider.wrapPath(path));
+ Directory dir2 = new NIOFSDirectory(provider.wrapPath(path.resolve("link")));
IndexOutput target = dir1.createOutput("target.txt", IOContext.DEFAULT);
target.writeInt(1);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterDirectoryStream.java b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterDirectoryStream.java
index e05f7db9ad3..5fd2f630558 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterDirectoryStream.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterDirectoryStream.java
@@ -18,7 +18,6 @@ package org.apache.lucene.tests.mockfile;
import java.io.IOException;
import java.nio.file.DirectoryStream;
-import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.util.Iterator;
import java.util.Objects;
@@ -34,7 +33,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
protected final DirectoryStream<Path> delegate;
/** The underlying {@code FileSystem} instance. */
- protected final FileSystem fileSystem;
+ protected final FilterFileSystem fileSystem;
/**
* Construct a {@code FilterDirectoryStream} based on the specified base stream.
@@ -43,7 +42,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
*
* @param delegate specified base stream.
*/
- public FilterDirectoryStream(DirectoryStream<Path> delegate, FileSystem fileSystem) {
+ public FilterDirectoryStream(DirectoryStream<Path> delegate, FilterFileSystem fileSystem) {
this.delegate = Objects.requireNonNull(delegate);
this.fileSystem = Objects.requireNonNull(fileSystem);
}
@@ -64,7 +63,7 @@ public class FilterDirectoryStream implements DirectoryStream<Path> {
@Override
public Path next() {
- return new FilterPath(delegateIterator.next(), fileSystem);
+ return fileSystem.parent.wrapPath(delegateIterator.next());
}
@Override
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystem.java b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystem.java
index f9576f480d7..8702e801665 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystem.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystem.java
@@ -24,7 +24,6 @@ import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.WatchService;
import java.nio.file.attribute.UserPrincipalLookupService;
-import java.nio.file.spi.FileSystemProvider;
import java.util.Iterator;
import java.util.Objects;
import java.util.Set;
@@ -55,7 +54,7 @@ public class FilterFileSystem extends FileSystem {
}
@Override
- public FileSystemProvider provider() {
+ public FilterFileSystemProvider provider() {
return parent;
}
@@ -100,7 +99,7 @@ public class FilterFileSystem extends FileSystem {
@Override
public Path next() {
- return new FilterPath(iterator.next(), FilterFileSystem.this);
+ return parent.wrapPath(iterator.next());
}
@Override
@@ -142,7 +141,7 @@ public class FilterFileSystem extends FileSystem {
@Override
public Path getPath(String first, String... more) {
- return new FilterPath(delegate.getPath(first, more), this);
+ return parent.wrapPath(delegate.getPath(first, more));
}
@Override
@@ -170,9 +169,4 @@ public class FilterFileSystem extends FileSystem {
public FileSystem getDelegate() {
return delegate;
}
-
- /** Returns the {@code FilterFileSystemProvider} sent to this on init. */
- public FileSystemProvider getParent() {
- return parent;
- }
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystemProvider.java b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystemProvider.java
index 700d3d7a40f..9439a40de1c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystemProvider.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterFileSystemProvider.java
@@ -52,7 +52,7 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
/** The underlying {@code FileSystemProvider}. */
protected final FileSystemProvider delegate;
/** The underlying {@code FileSystem} instance. */
- protected FileSystem fileSystem;
+ protected FilterFileSystem fileSystem;
/** The URI scheme for this provider. */
protected final String scheme;
@@ -116,7 +116,11 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
if (fileSystem == null) {
throw new IllegalStateException("subclass did not initialize singleton filesystem");
}
- Path path = delegate.getPath(uri);
+ return wrapPath(delegate.getPath(uri));
+ }
+
+ /** wraps a Path with provider-specific behavior */
+ public FilterPath wrapPath(Path path) {
return new FilterPath(path, fileSystem);
}
@@ -223,7 +227,7 @@ public abstract class FilterFileSystemProvider extends FileSystemProvider {
new Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
- return filter.accept(new FilterPath(entry, fileSystem));
+ return filter.accept(wrapPath(entry));
}
};
return new FilterDirectoryStream(
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterPath.java b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterPath.java
index 8af517cf72e..99d5897690d 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterPath.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/FilterPath.java
@@ -41,7 +41,7 @@ public class FilterPath implements Path, Unwrappable<Path> {
protected final Path delegate;
/** The parent {@code FileSystem} for this path. */
- protected final FileSystem fileSystem;
+ protected final FilterFileSystem fileSystem;
/**
* Construct a {@code FilterPath} with parent {@code fileSystem}, based on the specified base
@@ -50,7 +50,7 @@ public class FilterPath implements Path, Unwrappable<Path> {
* @param delegate specified base path.
* @param fileSystem parent fileSystem.
*/
- public FilterPath(Path delegate, FileSystem fileSystem) {
+ public FilterPath(Path delegate, FilterFileSystem fileSystem) {
this.delegate = delegate;
this.fileSystem = fileSystem;
}
@@ -270,9 +270,8 @@ public class FilterPath implements Path, Unwrappable<Path> {
return Unwrappable.unwrapAll(path);
}
- /** Override this to customize the return wrapped path from various operations */
- protected Path wrap(Path other) {
- return new FilterPath(other, fileSystem);
+ private final Path wrap(Path other) {
+ return fileSystem.parent.wrapPath(other);
}
/** Override this to customize the unboxing of Path from various operations */
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/HandleTrackingFS.java b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/HandleTrackingFS.java
index 44c89b619dd..17b08fd96f0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/HandleTrackingFS.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/mockfile/HandleTrackingFS.java
@@ -293,7 +293,7 @@ public abstract class HandleTrackingFS extends FilterFileSystemProvider {
new Filter<Path>() {
@Override
public boolean accept(Path entry) throws IOException {
- return filter.accept(new FilterPath(entry, fileSystem));
+ return filter.accept(wrapPath(entry));
}
};
DirectoryStream<Path> stream = delegate.newDirectoryStream(toDelegate(dir), wrappedFilter);
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
index 446cd467d6d..eda94ead228 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/LuceneTestCase.java
@@ -61,10 +61,8 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
-import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.FileSystem;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -140,7 +138,6 @@ import org.apache.lucene.tests.index.MismatchedDirectoryReader;
import org.apache.lucene.tests.index.MismatchedLeafReader;
import org.apache.lucene.tests.index.MockIndexWriterEventListener;
import org.apache.lucene.tests.index.MockRandomMergePolicy;
-import org.apache.lucene.tests.mockfile.FilterPath;
import org.apache.lucene.tests.mockfile.VirusCheckingFS;
import org.apache.lucene.tests.search.AssertingIndexSearcher;
import org.apache.lucene.tests.store.BaseDirectoryWrapper;
@@ -1398,8 +1395,7 @@ public abstract class LuceneTestCase extends Assert {
public static Path addVirusChecker(Path path) {
if (TestUtil.hasVirusChecker(path) == false) {
VirusCheckingFS fs = new VirusCheckingFS(path.getFileSystem(), random().nextLong());
- FileSystem filesystem = fs.getFileSystem(URI.create("file:///"));
- path = new FilterPath(path, filesystem);
+ path = fs.wrapPath(path);
}
return path;
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestUtil.java b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestUtil.java
index 0d1c982e3cd..fb085125e8b 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestUtil.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/tests/util/TestUtil.java
@@ -1682,7 +1682,7 @@ public final class TestUtil {
FileSystem fs = path.getFileSystem();
while (fs instanceof FilterFileSystem) {
FilterFileSystem ffs = (FilterFileSystem) fs;
- if (ffs.getParent() instanceof WindowsFS) {
+ if (ffs.provider() instanceof WindowsFS) {
return true;
}
fs = ffs.getDelegate();
@@ -1696,7 +1696,7 @@ public final class TestUtil {
FileSystem fs = path.getFileSystem();
while (fs instanceof FilterFileSystem) {
FilterFileSystem ffs = (FilterFileSystem) fs;
- if (ffs.getParent() instanceof WindowsFS) {
+ if (ffs.provider() instanceof WindowsFS) {
return true;
}
fs = ffs.getDelegate();
@@ -1718,7 +1718,7 @@ public final class TestUtil {
FileSystem fs = path.getFileSystem();
while (fs instanceof FilterFileSystem) {
FilterFileSystem ffs = (FilterFileSystem) fs;
- if (ffs.getParent() instanceof VirusCheckingFS) {
+ if (ffs.provider() instanceof VirusCheckingFS) {
return true;
}
fs = ffs.getDelegate();
@@ -1735,8 +1735,8 @@ public final class TestUtil {
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
while (fs instanceof FilterFileSystem) {
FilterFileSystem ffs = (FilterFileSystem) fs;
- if (ffs.getParent() instanceof VirusCheckingFS) {
- VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
+ if (ffs.provider() instanceof VirusCheckingFS) {
+ VirusCheckingFS vfs = (VirusCheckingFS) ffs.provider();
boolean isEnabled = vfs.isEnabled();
vfs.disable();
return isEnabled;
@@ -1755,8 +1755,8 @@ public final class TestUtil {
FileSystem fs = ((FSDirectory) dir).getDirectory().getFileSystem();
while (fs instanceof FilterFileSystem) {
FilterFileSystem ffs = (FilterFileSystem) fs;
- if (ffs.getParent() instanceof VirusCheckingFS) {
- VirusCheckingFS vfs = (VirusCheckingFS) ffs.getParent();
+ if (ffs.provider() instanceof VirusCheckingFS) {
+ VirusCheckingFS vfs = (VirusCheckingFS) ffs.provider();
vfs.enable();
return;
}
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestDisableFsyncFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestDisableFsyncFS.java
index 4c925350ae6..1d8263b998f 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestDisableFsyncFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestDisableFsyncFS.java
@@ -16,10 +16,8 @@
*/
package org.apache.lucene.tests.mockfile;
-import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
-import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.StandardOpenOption;
@@ -28,8 +26,8 @@ public class TestDisableFsyncFS extends MockFileSystemTestCase {
@Override
protected Path wrap(Path path) {
- FileSystem fs = new DisableFsyncFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ DisableFsyncFS provider = new DisableFsyncFS(path.getFileSystem());
+ return provider.wrapPath(path);
}
/** Test that we don't corrumpt fsync: it just doesnt happen */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestExtrasFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestExtrasFS.java
index 4d65d61d727..17a26f5004b 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestExtrasFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestExtrasFS.java
@@ -16,9 +16,7 @@
*/
package org.apache.lucene.tests.mockfile;
-import java.net.URI;
import java.nio.file.DirectoryStream;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -34,10 +32,8 @@ public class TestExtrasFS extends MockFileSystemTestCase {
}
Path wrap(Path path, boolean active, boolean createDirectory) {
- FileSystem fs =
- new ExtrasFS(path.getFileSystem(), active, createDirectory)
- .getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ ExtrasFS provider = new ExtrasFS(path.getFileSystem(), active, createDirectory);
+ return provider.wrapPath(path);
}
/** test where extra file is created */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleLimitFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleLimitFS.java
index 85da76229a9..e184413bdae 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleLimitFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleLimitFS.java
@@ -18,8 +18,6 @@ package org.apache.lucene.tests.mockfile;
import java.io.Closeable;
import java.io.IOException;
-import java.net.URI;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -35,9 +33,8 @@ public class TestHandleLimitFS extends MockFileSystemTestCase {
}
Path wrap(Path path, int limit) {
- FileSystem fs =
- new HandleLimitFS(path.getFileSystem(), limit).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ HandleLimitFS provider = new HandleLimitFS(path.getFileSystem(), limit);
+ return provider.wrapPath(path);
}
/** set a limit at n files, then open more than that and ensure we hit exception */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleTrackingFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleTrackingFS.java
index 54d12ecbe19..76fb44cf833 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleTrackingFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestHandleTrackingFS.java
@@ -19,10 +19,8 @@ package org.apache.lucene.tests.mockfile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.channels.SeekableByteChannel;
import java.nio.file.DirectoryStream;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -31,8 +29,8 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
@Override
protected Path wrap(Path path) {
- FileSystem fs = new LeakFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ LeakFS provider = new LeakFS(path.getFileSystem());
+ return provider.wrapPath(path);
}
/** Test that the delegate gets closed on exception in HandleTrackingFS#onClose */
@@ -40,7 +38,7 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
Path path =
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
// fails
- FileSystem fs =
+ HandleTrackingFS provider =
new HandleTrackingFS("test://", path.getFileSystem()) {
@Override
protected void onClose(Path path, Object stream) throws IOException {
@@ -51,8 +49,8 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
protected void onOpen(Path path, Object stream) throws IOException {
//
}
- }.getFileSystem(URI.create("file:///"));
- Path dir = new FilterPath(path, fs);
+ };
+ Path dir = provider.wrapPath(path);
OutputStream file = Files.newOutputStream(dir.resolve("somefile"));
file.write(5);
@@ -63,7 +61,6 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
InputStream stream = Files.newInputStream(dir.resolve("somefile"));
expectThrows(IOException.class, stream::close);
- fs.close();
DirectoryStream<Path> dirStream = Files.newDirectoryStream(dir);
expectThrows(IOException.class, dirStream::close);
@@ -74,7 +71,7 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
Path path =
wrap(createTempDir()); // we are using LeakFS under the hood if we don't get closed the test
// fails
- FileSystem fs =
+ HandleTrackingFS provider =
new HandleTrackingFS("test://", path.getFileSystem()) {
@Override
protected void onClose(Path path, Object stream) throws IOException {}
@@ -83,17 +80,15 @@ public class TestHandleTrackingFS extends MockFileSystemTestCase {
protected void onOpen(Path path, Object stream) throws IOException {
throw new IOException("boom");
}
- }.getFileSystem(URI.create("file:///"));
- Path dir = new FilterPath(path, fs);
+ };
+ Path dir = provider.wrapPath(path);
expectThrows(IOException.class, () -> Files.newOutputStream(dir.resolve("somefile")));
expectThrows(IOException.class, () -> Files.newByteChannel(dir.resolve("somefile")));
expectThrows(IOException.class, () -> Files.newInputStream(dir.resolve("somefile")));
- fs.close();
expectThrows(IOException.class, () -> Files.newDirectoryStream(dir));
- fs.close();
}
}
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestLeakFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestLeakFS.java
index 44bb91a012a..521a75692d9 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestLeakFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestLeakFS.java
@@ -19,11 +19,9 @@ package org.apache.lucene.tests.mockfile;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Collections;
@@ -37,8 +35,8 @@ public class TestLeakFS extends MockFileSystemTestCase {
@Override
protected Path wrap(Path path) {
- FileSystem fs = new LeakFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ LeakFS provider = new LeakFS(path.getFileSystem());
+ return provider.wrapPath(path);
}
/** Test leaks via Files.newInputStream */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestShuffleFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestShuffleFS.java
index 28ed882d12e..53e00fc0a22 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestShuffleFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestShuffleFS.java
@@ -17,9 +17,7 @@
package org.apache.lucene.tests.mockfile;
import java.io.IOException;
-import java.net.URI;
import java.nio.file.DirectoryStream;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
@@ -35,8 +33,8 @@ public class TestShuffleFS extends MockFileSystemTestCase {
}
Path wrap(Path path, long seed) {
- FileSystem fs = new ShuffleFS(path.getFileSystem(), seed).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ ShuffleFS provider = new ShuffleFS(path.getFileSystem(), seed);
+ return provider.wrapPath(path);
}
/** test that we return directory listings correctly */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVerboseFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVerboseFS.java
index a335011b920..fd5da371499 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVerboseFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVerboseFS.java
@@ -18,11 +18,9 @@ package org.apache.lucene.tests.mockfile;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.channels.AsynchronousFileChannel;
import java.nio.channels.FileChannel;
import java.nio.channels.SeekableByteChannel;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
@@ -44,9 +42,8 @@ public class TestVerboseFS extends MockFileSystemTestCase {
}
Path wrap(Path path, InfoStream stream) {
- FileSystem fs =
- new VerboseFS(path.getFileSystem(), stream).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ VerboseFS provider = new VerboseFS(path.getFileSystem(), stream);
+ return provider.wrapPath(path);
}
/** InfoStream that looks for a substring and indicates if it saw it */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVirusCheckingFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVirusCheckingFS.java
index 3dea0de94d6..1f9005cd93e 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVirusCheckingFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestVirusCheckingFS.java
@@ -19,9 +19,7 @@ package org.apache.lucene.tests.mockfile;
import java.io.IOException;
import java.io.OutputStream;
-import java.net.URI;
import java.nio.file.AccessDeniedException;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -30,10 +28,8 @@ public class TestVirusCheckingFS extends MockFileSystemTestCase {
@Override
protected Path wrap(Path path) {
- FileSystem fs =
- new VirusCheckingFS(path.getFileSystem(), random().nextLong())
- .getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ VirusCheckingFS provider = new VirusCheckingFS(path.getFileSystem(), random().nextLong());
+ return provider.wrapPath(path);
}
/** Test Files.delete fails if a file has an open inputstream against it */
diff --git a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestWindowsFS.java b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestWindowsFS.java
index 6fb0285515a..a414470d471 100644
--- a/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestWindowsFS.java
+++ b/lucene/test-framework/src/test/org/apache/lucene/tests/mockfile/TestWindowsFS.java
@@ -20,8 +20,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.net.URI;
-import java.nio.file.FileSystem;
import java.nio.file.Files;
import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
@@ -42,8 +40,8 @@ public class TestWindowsFS extends MockFileSystemTestCase {
@Override
protected Path wrap(Path path) {
- FileSystem fs = new WindowsFS(path.getFileSystem()).getFileSystem(URI.create("file:///"));
- return new FilterPath(path, fs);
+ WindowsFS provider = new WindowsFS(path.getFileSystem());
+ return provider.wrapPath(path);
}
/** Test Files.delete fails if a file has an open inputstream against it */