Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] implement mark() in class FilterStreamInput #13145

Merged
merged 3 commits into from
Apr 10, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Fixed
- Fix bulk API ignores ingest pipeline for upsert ([#12883](https://github.com/opensearch-project/OpenSearch/pull/12883))
- Fix issue with feature flags where default value may not be honored ([#12849](https://github.com/opensearch-project/OpenSearch/pull/12849))
- Fix implement mark() and markSupported() in class FilterStreamInput ([#13098](https://github.com/opensearch-project/OpenSearch/pull/13098))

### Security

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ public void reset() throws IOException {
delegate.reset();
}

@Override
public void mark(int readlimit) {
delegate.mark(readlimit);
}

@Override
public boolean markSupported() {
return delegate.markSupported();
}

@Override
public int read() throws IOException {
return delegate.read();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import org.opensearch.core.common.bytes.BytesReference;

import java.io.IOException;
import java.nio.ByteBuffer;

import static org.hamcrest.Matchers.is;

/** test the FilterStreamInput using the same BaseStreamTests */
public class FilterStreamInputTests extends BaseStreamTests {
Expand All @@ -21,4 +24,24 @@ protected StreamInput getStreamInput(BytesReference bytesReference) throws IOExc
return new FilterStreamInput(StreamInput.wrap(br.bytes, br.offset, br.length)) {
};
}

public void testMarkAndReset() throws IOException {
FilterStreamInputTests filterStreamInputTests = new FilterStreamInputTests();

ByteBuffer buffer = ByteBuffer.wrap(new byte[20]);
for (int i = 0; i < buffer.limit(); i++) {
buffer.put((byte) i);
}
buffer.rewind();
BytesReference bytesReference = BytesReference.fromByteBuffer(buffer);
StreamInput streamInput = filterStreamInputTests.getStreamInput(bytesReference);
streamInput.read();
assertThat(streamInput.markSupported(), is(true));
streamInput.mark(-1);
int int1 = streamInput.read();
int int2 = streamInput.read();
streamInput.reset();
assertEquals(int1, streamInput.read());
assertEquals(int2, streamInput.read());
}
}
Loading