You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "divijvaidya (via GitHub)" <gi...@apache.org> on 2023/07/03 15:47:36 UTC

[GitHub] [kafka] divijvaidya commented on a diff in pull request #13941: KAFKA-15123: Add tests for ChunkedBytesStream

divijvaidya commented on code in PR #13941:
URL: https://github.com/apache/kafka/pull/13941#discussion_r1251040882


##########
clients/src/test/java/org/apache/kafka/common/utils/ChunkedBytesStreamTest.java:
##########
@@ -149,6 +160,38 @@ public void testCorrectnessForMethodSkip(int bytesToPreRead, ByteBuffer inputBuf
         }
     }
 
+    @Test
+    public void testEdgeCaseInputForMethodSkip() throws IOException {
+        int bufferLength = 16;
+        ByteBuffer inputBuf = ByteBuffer.allocate(bufferLength);
+        RANDOM.nextBytes(inputBuf.array());
+        inputBuf.position(inputBuf.capacity());
+        inputBuf.flip();
+
+        try (InputStream is = new ChunkedBytesStream(new ByteBufferInputStream(inputBuf.duplicate()), supplier, 10, true)) {
+            // larger than int input
+            assertEquals(bufferLength, is.skip(Integer.MAX_VALUE + 1000L));
+            // negative input
+            assertEquals(0, is.skip(-1));
+        }
+    }
+
+    private static Stream<Arguments> provideEdgeCaseInputsForMethodRead() {

Review Comment:
   perhaps rename to provideCasesWithInvalidInputsForMethodRead



##########
clients/src/test/java/org/apache/kafka/common/utils/ChunkedBytesStreamTest.java:
##########
@@ -36,6 +31,12 @@
 import java.util.Random;
 import java.util.stream.Stream;
 
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.mockito.Mockito.spy;
+

Review Comment:
   Please avoid changing the order of imports. It adds to unnecessary code review visual clutter.



##########
clients/src/test/java/org/apache/kafka/common/utils/ChunkedBytesStreamTest.java:
##########
@@ -149,6 +160,38 @@ public void testCorrectnessForMethodSkip(int bytesToPreRead, ByteBuffer inputBuf
         }
     }
 
+    @Test
+    public void testEdgeCaseInputForMethodSkip() throws IOException {
+        int bufferLength = 16;
+        ByteBuffer inputBuf = ByteBuffer.allocate(bufferLength);
+        RANDOM.nextBytes(inputBuf.array());
+        inputBuf.position(inputBuf.capacity());
+        inputBuf.flip();

Review Comment:
   you can also just do a rewind() here. When bytebuffer is initialized, limit pointer is already at capacity



##########
clients/src/test/java/org/apache/kafka/common/utils/ChunkedBytesStreamTest.java:
##########
@@ -149,6 +160,38 @@ public void testCorrectnessForMethodSkip(int bytesToPreRead, ByteBuffer inputBuf
         }
     }
 
+    @Test
+    public void testEdgeCaseInputForMethodSkip() throws IOException {
+        int bufferLength = 16;
+        ByteBuffer inputBuf = ByteBuffer.allocate(bufferLength);
+        RANDOM.nextBytes(inputBuf.array());
+        inputBuf.position(inputBuf.capacity());
+        inputBuf.flip();
+
+        try (InputStream is = new ChunkedBytesStream(new ByteBufferInputStream(inputBuf.duplicate()), supplier, 10, true)) {

Review Comment:
   we want to test this for both cases when skip is pushed down vs not, i.e. last argument is true and when last argument is false.



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org