This is an automated email from the ASF dual-hosted git repository.
adoroszlai pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git
The following commit(s) were added to refs/heads/master by this push:
new 9ac5d00fff2 HDDS-15595. Add test for seek in StreamBlockInputStream
(#12121)
9ac5d00fff2 is described below
commit 9ac5d00fff22b3bfdc6521917d2664e44a4fe6d1
Author: Sergey Soldatov <[email protected]>
AuthorDate: Sat Nov 21 10:43:21 2026 -0800
HDDS-15595. Add test for seek in StreamBlockInputStream (#12121)
---
.../scm/storage/TestStreamBlockInputStream.java | 32 ++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
index 298343ae8f1..a183525672d 100644
---
a/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
+++
b/hadoop-hdds/client/src/test/java/org/apache/hadoop/hdds/scm/storage/TestStreamBlockInputStream.java
@@ -889,6 +889,38 @@ public void
testSeekReadsCorrectBytesWhenFirstResponseIsFullyBeforePosition() th
}
}
+ /**
+ * A seek that reuses the buffered response must not rewind the requested
length: once the buffer is drained,
+ * the next request must continue from the current position instead of
re-requesting the buffered data.
+ */
+ @Test
+ public void testSeekReuseDoesNotRefetchBufferedData() throws Exception {
+ final int chunkSize = 16;
+ final byte[] data = new byte[2 * chunkSize];
+ for (int i = 0; i < data.length; i++) {
+ data[i] = (byte) i;
+ }
+ XceiverClientGrpc client = mockOffsetAwareStreamingReadClient(data,
mock(ClientCallStreamObserver.class));
+
+ try (StreamBlockInputStream sbis = newStreamForBlock(
+ newBlockInfo(new BlockID(1L, 15595L), data.length),
mockStandalonePipeline(), client)) {
+ assertEquals(chunkSize, sbis.read(ByteBuffer.allocate(chunkSize)));
+
+ // Seek back into the buffered response and drain it: no new request is
needed.
+ sbis.seek(4);
+ assertEquals(chunkSize - 4, sbis.read(ByteBuffer.allocate(chunkSize -
4)));
+ assertEquals(chunkSize, sbis.getPos());
+
+ // The first byte past the buffered response triggers the next request.
+ assertEquals(data[chunkSize], sbis.read());
+ }
+
+ ArgumentCaptor<ContainerCommandRequestProto> requests =
ArgumentCaptor.forClass(ContainerCommandRequestProto.class);
+ verify(client, times(2)).streamRead(requests.capture(),
any(StreamingReadResponse.class));
+ assertEquals(0, requests.getAllValues().get(0).getReadBlock().getOffset());
+ assertEquals(chunkSize,
requests.getAllValues().get(1).getReadBlock().getOffset());
+ }
+
/** A single-byte read returns the byte as 0 to 255: 0xFF must not look like
the end of the stream. */
@Test
public void testReadReturnsUnsignedByte() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]