gaborgsomogyi commented on code in PR #28112:
URL: https://github.com/apache/flink/pull/28112#discussion_r3201573763


##########
flink-filesystems/flink-s3-fs-native/src/test/java/org/apache/flink/fs/s3native/NativeS3InputStreamTest.java:
##########
@@ -333,15 +468,116 @@ void skipToEofWithOpenStreamReleasesStream() throws 
Exception {
 
             assertThat(in.skip(DATA.length)).isEqualTo(DATA.length - 1);
             assertThat(in.getPos()).isEqualTo(DATA.length);
+            assertThat(first.wasAborted()).isFalse();
 
-            assertThat(first.wasAborted()).isTrue();
-            assertThat(first.wasClosed()).isTrue();
-            assertThat(first.wasAbortedBeforeClose()).isTrue();
+            assertThat(in.read()).isEqualTo(-1);
+        }
+    }
+
+    @Test
+    void skipZeroAndNegativeAreNoOps() throws Exception {
+        StubS3Client client = new StubS3Client(DATA);
+        try (NativeS3InputStream in = new NativeS3InputStream(client, BUCKET, 
KEY, DATA.length)) {
+            in.read();
+            assertThat(in.skip(0)).isZero();
+            assertThat(in.skip(-5)).isZero();
             assertThat(client.getObjectCalls()).isEqualTo(1);
+        }
+    }
+
+    // --- read + seek integration ---
+
+    @Test
+    void readAndSeekReturnCorrectData() throws Exception {
+        StubS3Client client = new StubS3Client(DATA);
+        try (NativeS3InputStream in = new NativeS3InputStream(client, BUCKET, 
KEY, DATA.length)) {
+            assertThat(in.read()).isEqualTo(0);
+            assertThat(in.getPos()).isEqualTo(1);
+            byte[] buf = new byte[10];
+            assertThat(in.read(buf, 0, 10)).isEqualTo(10);
+            assertThat(in.getPos()).isEqualTo(11);
+            for (int i = 0; i < 10; i++) {
+                assertThat(buf[i]).isEqualTo(DATA[i + 1]);
+            }
+            assertThat(in.available()).isEqualTo(DATA.length - 11);
+            in.seek(200);
+            assertThat(in.read()).isEqualTo(200);
+            assertThat(in.getPos()).isEqualTo(201);
+            in.seek(250);
+            byte[] tail = new byte[20];
+            assertThat(in.read(tail, 0, 20)).isEqualTo(6);
+            assertThat(in.getPos()).isEqualTo(256);
             assertThat(in.read()).isEqualTo(-1);
+            assertThat(in.read(new byte[1], 0, 1)).isEqualTo(-1);
+        }
+    }
+
+    // --- buffer-efficiency: skip stays in local buffer vs. underlying stream 
---
+
+    @Test
+    void seekWithinBuffer_afterSmallRead_doesNotTouchUnderlyingStream() throws 
Exception {
+        int smallBuffer = 32;
+        StubS3Client client = new StubS3Client(DATA);
+        try (NativeS3InputStream in =
+                new NativeS3InputStream(client, BUCKET, KEY, DATA.length, 
smallBuffer)) {
+            // single-byte read fills the local buffer (up to smallBuffer 
bytes buffered)
+            in.read();
+            TrackingInputStream underlying = client.lastStream();
+
+            // forward seek of 9 bytes — fits in the local buffer, no 
underlying access needed
+            in.seek(10);
+            in.read();
+
+            assertThat(client.getObjectCalls()).isEqualTo(1);
+            assertThat(underlying.bytesSkippedFromUnderlying()).isEqualTo(0);

Review Comment:
   I mean `bytesReadFromUnderlying` is the key part here. Cool that we checked 
skip but another aspect that we've read exactly the expected amount of data 
from wrapper stream



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to