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/11/20 21:42:21 UTC
[GitHub] [lucene] mdmarshmallow opened a new pull request, #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
mdmarshmallow opened a new pull request, #11958:
URL: https://github.com/apache/lucene/pull/11958
### Description
Added a new `FilterIndexInput` and `FilterIndexOutput` class to handle delegate `IndexOutput` and `IndexInput` classes.
I also changed some of the current subclasses that use these delegate patterns to extend `FilterIndexInput` and `FilterIndexOutput`. Here is a list of the subclasses I changed/didn't change:
* IndexOutput changed:
* EndiannessReverserIndexOutput
* RateLimitedIndexOutput
* SlowIndexOutput
* CorruptingIndexOutput
* MockIndexOutputWrapper
* ThrottledIndexOutput
* IndexOutput unchanged:
* ByteBuffersIndexOutput
* OutputStreamIndexOutput
* DirectIOIndexOutput
* IndexInput changed:
* EndiannessReverserIndexInput
* SeekCountingStream
* CountingStream
* SlowIndexInput
* ReadBytesIndexInputWrapper
* MockIndexWrapper
* IndexInput unchanged:
* BufferedIndexInput
* ByteBufferIndexInput
* ByteBuffersIndexInput
* ChecksumIndexInput
* MemorySegmentIndexInput
* InterceptingIndexInput
* DirectIOIndexInput
--
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
[GitHub] [lucene] jpountz merged pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by "jpountz (via GitHub)" <gi...@apache.org>.
jpountz merged PR #11958:
URL: https://github.com/apache/lucene/pull/11958
--
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
[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
mdmarshmallow commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1028358333
##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IndexOutput implementation that delegates calls to another directory. This class can be used to
+ * add limitations on top of an existing {@link IndexOutput} implementation such as {@link
+ * ByteBuffersIndexOutput} or to add additional sanity checks for tests. However, if you plan to
+ * write your own {@link IndexOutput} implementation, you should consider extending directly {@link
+ * IndexOutput} or {@link DataOutput} rather than try to reuse functionality of existing {@link
+ * IndexOutput}s by extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexOutput extends IndexOutput {
+
+ public static IndexOutput unwrap(IndexOutput out) {
+ while (out instanceof FilterIndexOutput) {
+ out = ((FilterIndexOutput) out).out;
+ }
+ return out;
+ }
+
+ protected final IndexOutput out;
+
+ protected FilterIndexOutput(String resourceDescription, String name, IndexOutput out) {
+ super(resourceDescription, name);
+ this.out = out;
+ }
+
+ public final IndexOutput getDelegate() {
+ return out;
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return out.getFilePointer();
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return out.getChecksum();
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
Review Comment:
Not sure if we want to call `out.writeBytes` here or `this.writeBytes` since this really is just a method overload for convenience and should share any overridden behavior with the other `writeBytes` function if it is overridden.
--
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
[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
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
[GitHub] [lucene] mdmarshmallow commented on pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by "mdmarshmallow (via GitHub)" <gi...@apache.org>.
mdmarshmallow commented on PR #11958:
URL: https://github.com/apache/lucene/pull/11958#issuecomment-1411221077
Hi, I was wondering if this could be merged. I think I addressed all the feedback given here and it has been approved for quite a while now. Thanks!
--
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
[GitHub] [lucene] jpountz commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
jpountz commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1029188569
##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IndexOutput implementation that delegates calls to another directory. This class can be used to
+ * add limitations on top of an existing {@link IndexOutput} implementation such as {@link
+ * ByteBuffersIndexOutput} or to add additional sanity checks for tests. However, if you plan to
+ * write your own {@link IndexOutput} implementation, you should consider extending directly {@link
+ * IndexOutput} or {@link DataOutput} rather than try to reuse functionality of existing {@link
+ * IndexOutput}s by extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexOutput extends IndexOutput {
+
+ public static IndexOutput unwrap(IndexOutput out) {
+ while (out instanceof FilterIndexOutput) {
+ out = ((FilterIndexOutput) out).out;
+ }
+ return out;
+ }
+
+ protected final IndexOutput out;
+
+ protected FilterIndexOutput(String resourceDescription, String name, IndexOutput out) {
+ super(resourceDescription, name);
+ this.out = out;
+ }
+
+ public final IndexOutput getDelegate() {
+ return out;
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return out.getFilePointer();
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return out.getChecksum();
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
Review Comment:
My recollection from past discussions is that we prefer `FilterXXX` classes to only delegate abstract methods, not methods that have a default implementation.
--
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
[GitHub] [lucene] jpountz commented on pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by "jpountz (via GitHub)" <gi...@apache.org>.
jpountz commented on PR #11958:
URL: https://github.com/apache/lucene/pull/11958#issuecomment-1412035640
Sorry for the lag, I had lost track of this PR. It's merged now!
--
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
[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
mdmarshmallow commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1029879211
##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IndexOutput implementation that delegates calls to another directory. This class can be used to
+ * add limitations on top of an existing {@link IndexOutput} implementation such as {@link
+ * ByteBuffersIndexOutput} or to add additional sanity checks for tests. However, if you plan to
+ * write your own {@link IndexOutput} implementation, you should consider extending directly {@link
+ * IndexOutput} or {@link DataOutput} rather than try to reuse functionality of existing {@link
+ * IndexOutput}s by extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexOutput extends IndexOutput {
+
+ public static IndexOutput unwrap(IndexOutput out) {
+ while (out instanceof FilterIndexOutput) {
+ out = ((FilterIndexOutput) out).out;
+ }
+ return out;
+ }
+
+ protected final IndexOutput out;
+
+ protected FilterIndexOutput(String resourceDescription, String name, IndexOutput out) {
+ super(resourceDescription, name);
+ this.out = out;
+ }
+
+ public final IndexOutput getDelegate() {
+ return out;
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return out.getFilePointer();
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return out.getChecksum();
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
Review Comment:
That makes sense to me but I wasn't sure which approach to take when initially writing this. I will fix it and make a new revision.
--
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
[GitHub] [lucene] mdmarshmallow commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
mdmarshmallow commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1043768983
##########
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:
Speaking as a user, I have seen some uses of the `unwrap` method in our own code base. I think it makes sense to keep them as other users might use it at one point or another?
--
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
[GitHub] [lucene] dweiss commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
dweiss commented on code in PR #11958:
URL: https://github.com/apache/lucene/pull/11958#discussion_r1028411698
##########
lucene/core/src/java/org/apache/lucene/store/FilterIndexOutput.java:
##########
@@ -0,0 +1,113 @@
+/*
+ * 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;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * IndexOutput implementation that delegates calls to another directory. This class can be used to
+ * add limitations on top of an existing {@link IndexOutput} implementation such as {@link
+ * ByteBuffersIndexOutput} or to add additional sanity checks for tests. However, if you plan to
+ * write your own {@link IndexOutput} implementation, you should consider extending directly {@link
+ * IndexOutput} or {@link DataOutput} rather than try to reuse functionality of existing {@link
+ * IndexOutput}s by extending this class.
+ *
+ * @lucene.internal
+ */
+public class FilterIndexOutput extends IndexOutput {
+
+ public static IndexOutput unwrap(IndexOutput out) {
+ while (out instanceof FilterIndexOutput) {
+ out = ((FilterIndexOutput) out).out;
+ }
+ return out;
+ }
+
+ protected final IndexOutput out;
+
+ protected FilterIndexOutput(String resourceDescription, String name, IndexOutput out) {
+ super(resourceDescription, name);
+ this.out = out;
+ }
+
+ public final IndexOutput getDelegate() {
+ return out;
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ @Override
+ public long getFilePointer() {
+ return out.getFilePointer();
+ }
+
+ @Override
+ public long getChecksum() throws IOException {
+ return out.getChecksum();
+ }
+
+ @Override
+ public void writeByte(byte b) throws IOException {
+ out.writeByte(b);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int offset, int length) throws IOException {
+ out.writeBytes(b, offset, length);
+ }
+
+ @Override
+ public void writeBytes(byte[] b, int length) throws IOException {
Review Comment:
This is the major problem I have with filter/delegate wrapper classes. I've been stung by this more than one time (including with JDK filter classes).
--
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
[GitHub] [lucene] jpountz commented on a diff in pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
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-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
[GitHub] [lucene] mdmarshmallow commented on pull request #11958: GITHUB-11868: Add FilterIndexInput and FilterIndexOutput wrapper classes
Posted by GitBox <gi...@apache.org>.
mdmarshmallow commented on PR #11958:
URL: https://github.com/apache/lucene/pull/11958#issuecomment-1364622450
Added the java docs and the CHANGES.txt entry.
--
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