Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FilterIndexInput;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
import org.apache.lucene.store.IndexOutput;
Expand Down Expand Up @@ -267,17 +268,47 @@ public void testSkipBytes() throws Exception {
skipBytesExpected
);

IndexInput input = dir.openInput("test", IOContext.DEFAULT);
InputStreamIndexInput is = new InputStreamIndexInput(input, limit);
var countingInput = new CountingReadBytesIndexInput("test", dir.openInput("test", IOContext.DEFAULT));
InputStreamIndexInput is = new InputStreamIndexInput(countingInput, limit);
is.readNBytes(initialReadBytes);
assertThat(is.skip(skipBytes), equalTo((long) skipBytesExpected));
long expectedActualInitialBytesRead = Math.min(Math.min(initialReadBytes, limit), bytes);
assertThat(countingInput.getBytesRead(), equalTo(expectedActualInitialBytesRead));

int remainingBytes = Math.min(bytes, limit) - seekExpected;
for (int i = seekExpected; i < seekExpected + remainingBytes; i++) {
assertThat(is.read(), equalTo(i));
}
assertThat(countingInput.getBytesRead(), equalTo(expectedActualInitialBytesRead + remainingBytes));
}

protected static class CountingReadBytesIndexInput extends FilterIndexInput {
private long bytesRead = 0;

public CountingReadBytesIndexInput(String resourceDescription, IndexInput in) {
super(resourceDescription, in);
}

@Override
public byte readByte() throws IOException {
long filePointerBefore = getFilePointer();
byte b = super.readByte();
bytesRead += getFilePointer() - filePointerBefore;
return b;
}

@Override
public void readBytes(byte[] b, int offset, int len) throws IOException {
long filePointerBefore = getFilePointer();
super.readBytes(b, offset, len);
bytesRead += getFilePointer() - filePointerBefore;
}

public long getBytesRead() {
return bytesRead;
}
};

public void testReadZeroShouldReturnZero() throws IOException {
try (Directory dir = new ByteBuffersDirectory()) {
try (IndexOutput output = dir.createOutput("test", IOContext.DEFAULT)) {
Expand Down