Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 104 additions & 0 deletions lucene/core/src/java/org/apache/lucene/store/FilterIndexInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package org.apache.lucene.store;

import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import org.apache.lucene.internal.tests.TestSecrets;

Expand Down Expand Up @@ -106,4 +109,105 @@ public byte readByte() throws IOException {
public void readBytes(byte[] b, int offset, int len) throws IOException {
in.readBytes(b, offset, len);
}

@Override
public Set<String> readSetOfStrings() throws IOException {
return in.readSetOfStrings();
}

@Override
public Map<String, String> readMapOfStrings() throws IOException {
return in.readMapOfStrings();
}

@Override
public String readString() throws IOException {
return in.readString();
}

@Override
public long readZLong() throws IOException {
return in.readZLong();
}

@Override
public long readVLong() throws IOException {
return in.readVLong();
}

@Override
public void readFloats(float[] floats, int offset, int len) throws IOException {
in.readFloats(floats, offset, len);
}

@Override
public void readInts(int[] dst, int offset, int length) throws IOException {
in.readInts(dst, offset, length);
}

@Override
public void readLongs(long[] dst, int offset, int length) throws IOException {
in.readLongs(dst, offset, length);
}

@Override
public long readLong() throws IOException {
return in.readLong();
}

@Override
public int readZInt() throws IOException {
return in.readZInt();
}

@Override
public int readVInt() throws IOException {
return in.readVInt();
}

@Override
public int readInt() throws IOException {
return in.readInt();
}

@Override
public short readShort() throws IOException {
return in.readShort();
}

@Override
public void readBytes(byte[] b, int offset, int len, boolean useBuffer) throws IOException {
in.readBytes(b, offset, len, useBuffer);
}

@Override
public void prefetch(long offset, long length) throws IOException {
in.prefetch(offset, length);
}

@Override
public RandomAccessInput randomAccessSlice(long offset, long length) throws IOException {
return in.randomAccessSlice(offset, length);
}

@Override
public void updateIOContext(IOContext context) throws IOException {
in.updateIOContext(context);
}

@Override
public Optional<Boolean> isLoaded() {
return in.isLoaded();
}

@Override
public IndexInput slice(String sliceDescription, long offset, long length, IOContext context)
throws IOException {
return super.slice(sliceDescription, offset, length, context);
}

@Override
public void skipBytes(long numBytes) throws IOException {
in.skipBytes(numBytes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
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
Expand Down Expand Up @@ -81,4 +83,60 @@ public void writeByte(byte b) throws IOException {
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 {
out.writeBytes(b, length);
}

@Override
public void writeInt(int i) throws IOException {
out.writeInt(i);
}

@Override
public void writeShort(short i) throws IOException {
out.writeShort(i);
}

@Override
public void writeLong(long i) throws IOException {
out.writeLong(i);
}

@Override
public void writeString(String s) throws IOException {
out.writeString(s);
}

@Override
public void copyBytes(DataInput input, long numBytes) throws IOException {
out.copyBytes(input, numBytes);
}

@Override
public void writeMapOfStrings(Map<String, String> map) throws IOException {
out.writeMapOfStrings(map);
}

@Override
public void writeSetOfStrings(Set<String> set) throws IOException {
out.writeSetOfStrings(set);
}

@Override
public void writeGroupVInts(int[] values, int limit) throws IOException {
out.writeGroupVInts(values, limit);
}

@Override
@Deprecated
public void writeGroupVInts(long[] values, int limit) throws IOException {
out.writeGroupVInts(values, limit);
}

@Override
public String getName() {
return out.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public IndexInput clone() {
public IndexInput slice(String sliceDescription, long offset, long length) throws IOException {
return new CountingPrefetchIndexInput(in.slice(sliceDescription, offset, length), counter);
}

@Override
public IndexInput slice(String sliceDescription, long offset, long length, IOContext context)
throws IOException {
return new CountingPrefetchIndexInput(
in.slice(sliceDescription, offset, length, context), counter);
}
}

public void testSkipRedundantPrefetches() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.FilterDirectoryReader.SubReaderWrapper;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.apache.lucene.util.IOUtils;
import org.junit.Test;

public class TestFilterDirectoryReader extends LuceneTestCase {

Expand Down Expand Up @@ -197,4 +199,9 @@ public void testDelegatingCacheHelper() throws IOException {
w.close();
dir.close();
}

@Test
public void testOverrides() throws Exception {
assertDelegatorOverridesAllRequiredMethods(FilterDirectoryReader.class, Set.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

import java.io.IOException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.FilterIndexInput;
Expand Down Expand Up @@ -61,24 +62,14 @@ public void testRawFilterIndexInputRead() throws IOException {

@Test
public void testOverrides() {
// We want to exclude all the clone methods inherited from the hierarchy.
Set<Method> exclude = new HashSet<>();
for (Method m : FilterIndexInput.class.getMethods()) {
if (m.getName().contains("clone")) {
// special case
continue;
}
if (m.getDeclaringClass() == FilterIndexInput.class) {
// verify that only abstract methods are overridden
Method indexInputMethod;
try {
indexInputMethod = IndexInput.class.getMethod(m.getName(), m.getParameterTypes());
assertTrue(
"Non-abstract method " + m.getName() + " is overridden",
Modifier.isAbstract(indexInputMethod.getModifiers()));
} catch (Exception e) {
assertTrue(e instanceof NoSuchMethodException);
}
if (m.getName().equals("clone")) {
exclude.add(m);
}
}
assertDelegatorOverridesAllRequiredMethods(FilterIndexInput.class, exclude);
}

public void testUnwrap() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.util.Set;
import org.apache.lucene.store.FilterIndexOutput;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.junit.Test;

public class TestFilterIndexOutput extends LuceneTestCase {

@Test
public void testOverrides() {
assertDelegatorOverridesAllRequiredMethods(FilterIndexOutput.class, Set.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,12 @@
*/
package org.apache.lucene.index;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Set;
import org.apache.lucene.tests.util.LuceneTestCase;

public class TestFilterMergePolicy extends LuceneTestCase {

public void testMethodsOverridden() {
for (Method m : MergePolicy.class.getDeclaredMethods()) {
if (Modifier.isFinal(m.getModifiers()) || Modifier.isPrivate(m.getModifiers())) continue;
try {
FilterMergePolicy.class.getDeclaredMethod(m.getName(), m.getParameterTypes());
} catch (NoSuchMethodException _) {
fail("FilterMergePolicy needs to override '" + m + "'");
}
}
assertDelegatorOverridesAllRequiredMethods(FilterMergePolicy.class, Set.of());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.file.Path;
import java.util.HashSet;
import java.util.Set;
import org.apache.lucene.tests.store.BaseDirectoryTestCase;
import org.junit.Test;
Expand All @@ -35,16 +34,13 @@ protected Directory getDirectory(Path path) {
public void testOverrides() throws Exception {
// verify that all methods of Directory are overridden by FilterDirectory,
// except those under the 'exclude' list
Set<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) {
assertTrue("method " + m.getName() + " not overridden!", exclude.contains(m));
}
}
Set<Method> exclude =
Set.of(
Directory.class.getMethod(
"copyFrom", Directory.class, String.class, String.class, IOContext.class),
Directory.class.getMethod("openChecksumInput", String.class));

assertDelegatorOverridesAllRequiredMethods(FilterDirectory.class, exclude);
}

public void testUnwrap() throws IOException {
Expand Down
Loading
Loading