You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@lucene.apache.org by GitBox <gi...@apache.org> on 2022/12/08 20:00:02 UTC

[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes

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


##########
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:
   Yeah, going back to your other comment, you said that we should only override abstract methods, so I changed this test to just check that all methods overridden are not abstract (the compiler would force all abstract methods to be overridden so there is no point in testing that).



-- 
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-unsubscribe@lucene.apache.org

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


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