jpountz commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1041440269


##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java:
##########
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.store;
+
+import java.io.IOException;
+
+/**
+ * IndexInput implementation that delegates calls to another directory. This 
class can be used to
+ * add limitations on top of an existing {@link IndexInput} implementation or 
to add additional
+ * sanity checks for tests. However, if you plan to write your own {@link 
IndexInput}
+ * implementation, you should consider extending directly {@link IndexInput} 
or {@link DataInput}
+ * rather than try to reuse functionality of existing {@link IndexInput}s by 
extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexInput extends IndexInput {
+
+  public static IndexInput unwrap(IndexInput in) {

Review Comment:
   why are we adding these unwrap methods, they don't seem used anywhere? I 
know we have them on some other `Filter` classes but it's a bug IMO.



##########
lucene/core/src/test/org/apache/lucene/index/TestFilterIndexInput.java:
##########
@@ -0,0 +1,119 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.lucene.index;
+
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Random;
+import java.util.Set;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.store.FSDirectory;
+import org.apache.lucene.store.FilterIndexInput;
+import org.apache.lucene.store.IOContext;
+import org.apache.lucene.store.IndexInput;
+import org.apache.lucene.store.IndexOutput;
+import org.junit.Test;
+
+public class TestFilterIndexInput extends TestIndexInput {
+
+  @Override
+  public IndexInput getIndexInput(long len) {
+    return new FilterIndexInput("wrapped foo", new 
InterceptingIndexInput("foo", len));
+  }
+
+  public void testRawFilterIndexInputRead() throws IOException {
+    for (int i = 0; i < 10; i++) {
+      Random random = random();
+      final Directory dir = newDirectory();
+      IndexOutput os = dir.createOutput("foo", newIOContext(random));
+      os.writeBytes(READ_TEST_BYTES, READ_TEST_BYTES.length);
+      os.close();
+      IndexInput is =
+          new FilterIndexInput("wrapped foo", dir.openInput("foo", 
newIOContext(random)));
+      checkReads(is, IOException.class);
+      checkSeeksAndSkips(is, random);
+      is.close();
+
+      os = dir.createOutput("bar", newIOContext(random));
+      os.writeBytes(RANDOM_TEST_BYTES, RANDOM_TEST_BYTES.length);
+      os.close();
+      is = new FilterIndexInput("wrapped bar", dir.openInput("bar", 
newIOContext(random)));
+      checkRandomReads(is);
+      checkSeeksAndSkips(is, random);
+      is.close();
+      dir.close();
+    }
+  }
+
+  @Test
+  public void testOverrides() throws Exception {
+    // verify that all abstract methods of IndexInput/DataInput are overridden 
by FilterDirectory,
+    // except those under the 'exclude' list
+    Set<Method> exclude = new HashSet<>();
+
+    exclude.add(IndexInput.class.getMethod("toString"));
+    exclude.add(IndexInput.class.getMethod("skipBytes", long.class));
+    exclude.add(IndexInput.class.getDeclaredMethod("getFullSliceDescription", 
String.class));
+    exclude.add(IndexInput.class.getMethod("randomAccessSlice", long.class, 
long.class));
+
+    exclude.add(
+        DataInput.class.getMethod("readBytes", byte[].class, int.class, 
int.class, boolean.class));
+    exclude.add(DataInput.class.getMethod("readShort"));
+    exclude.add(DataInput.class.getMethod("readInt"));
+    exclude.add(DataInput.class.getMethod("readVInt"));
+    exclude.add(DataInput.class.getMethod("readZInt"));
+    exclude.add(DataInput.class.getMethod("readLong"));
+    exclude.add(DataInput.class.getMethod("readLongs", long[].class, 
int.class, int.class));
+    exclude.add(DataInput.class.getMethod("readInts", int[].class, int.class, 
int.class));
+    exclude.add(DataInput.class.getMethod("readFloats", float[].class, 
int.class, int.class));
+    exclude.add(DataInput.class.getMethod("readVLong"));
+    exclude.add(DataInput.class.getMethod("readZLong"));
+    exclude.add(DataInput.class.getMethod("readString"));
+    exclude.add(DataInput.class.getMethod("readMapOfStrings"));
+    exclude.add(DataInput.class.getMethod("readSetOfStrings"));

Review Comment:
   The comment says we're checking abstract methods, so should we check it 
below and remove these methods that have default impls from the exclude list?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org
For additional commands, e-mail: issues-h...@lucene.apache.org

Reply via email to