Apache Lucene open-source search software
FilterDirectory should delegate copyFrom() to wrapped directory (#16173)
Prithvi Sd0ba760f5f08
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex c0bd5d61da5..131f6c71431 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -458,6 +458,8 @@ Bug FixesGlobalOrdinalsWithScoreCollector, fixing an intermittent failure caused bynon-associative float addition that #16378 missed. (Luca Cavanna)+* GITHUB#16173: FilterDirectory now delegates copyFrom() to the wrapped directory. (Prithvi S)+Other---------------------* GITHUB#16266: Remove deprecated search(Query, Collector) calls in QueryUtils by replacingdiff --git a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.javaindex 5d8d13528f3..3d5c1a5f51b 100644--- a/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java+++ b/lucene/core/src/java/org/apache/lucene/store/FilterDirectory.java@@ -116,6 +116,12 @@ public abstract class FilterDirectory extends Directory {return getClass().getSimpleName() + "(" + in.toString() + ")";}+ @Override+ public void copyFrom(Directory from, String src, String dest, IOContext context)+ throws IOException {+ in.copyFrom(from, src, dest, context);+ }+@Overridepublic Set<String> getPendingDeletions() throws IOException {return in.getPendingDeletions();diff --git a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.javaindex bec89bb5cd2..9eb987fb729 100644--- a/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java+++ b/lucene/core/src/test/org/apache/lucene/store/TestFilterDirectory.java@@ -34,9 +34,6 @@ public class TestFilterDirectory extends BaseDirectoryTestCase {// verify that all methods of Directory are overridden by FilterDirectory,// except those under the 'exclude' listSet<Method> exclude = new HashSet<>();- exclude.add(- Directory.class.getMethod(- "copyFrom", Directory.class, String.class, String.class, IOContext.class));exclude.add(Directory.class.getMethod("openChecksumInput", String.class));for (Method m : FilterDirectory.class.getMethods()) {if (m.getDeclaringClass() == Directory.class) {@@ -45,6 +42,32 @@ public class TestFilterDirectory extends BaseDirectoryTestCase {}}+ public void testCopyFromDelegates() throws IOException {+ try (Directory srcDir = new ByteBuffersDirectory();+ Directory destDir = new ByteBuffersDirectory()) {+ try (IndexOutput out = srcDir.createOutput("test.txt", IOContext.DEFAULT)) {+ out.writeString("hello");+ }+ boolean[] delegated = {false};+ FilterDirectory wrappedDestDir =+ new FilterDirectory(destDir) {+ @Override+ public void copyFrom(Directory from, String src, String dest, IOContext context)+ throws IOException {+ delegated[0] = true;+ in.copyFrom(from, src, dest, context);+ }+ };+ FilterDirectory filterDestDir = new FilterDirectory(wrappedDestDir) {};+ filterDestDir.copyFrom(srcDir, "test.txt", "copied.txt", IOContext.DEFAULT);+ assertTrue("copyFrom should delegate to wrapped directory", delegated[0]);+ assertTrue(slowFileExists(destDir, "copied.txt"));+ try (IndexInput in = destDir.openInput("copied.txt", IOContext.DEFAULT)) {+ assertEquals("hello", in.readString());+ }+ }+ }+public void testUnwrap() throws IOException {Directory dir = FSDirectory.open(createTempDir());FilterDirectory dir2 = new FilterDirectory(dir) {};