squah-confluent commented on code in PR #24069:
URL: https://github.com/apache/kafka/pull/24069#discussion_r4456108078


##########
clients/src/test/java/org/apache/kafka/common/protocol/ByteBufferAccessorTest.java:
##########
@@ -40,6 +40,27 @@ public void testReadArray() {
         assertEquals("Error reading byte array of 3 byte(s): only 0 byte(s) 
available",
             assertThrows(RuntimeException.class,
                 () -> accessor.readArray(3)).getMessage());

Review Comment:
   Could you add the equivalent of this assert to `testReadByteBuffer`? I'm 
expecting it to throw an `IllegalArgumentException` from `Buffer.limit`



##########
clients/src/test/java/org/apache/kafka/common/protocol/ByteBufferAccessorTest.java:
##########
@@ -40,6 +40,27 @@ public void testReadArray() {
         assertEquals("Error reading byte array of 3 byte(s): only 0 byte(s) 
available",
             assertThrows(RuntimeException.class,
                 () -> accessor.readArray(3)).getMessage());
+        assertEquals("Error reading byte array of -1 byte(s): only 0 byte(s) 
available",
+            assertThrows(RuntimeException.class,
+                () -> accessor.readArray(-1)).getMessage());
+    }
+
+    @Test
+    public void testReadByteBuffer() {
+        ByteBuffer buf = ByteBuffer.allocate(1024);
+        ByteBufferAccessor accessor = new ByteBufferAccessor(buf);
+        final byte[] testArray = new byte[] {0x4b, 0x61, 0x46};
+        accessor.writeByteArray(testArray);
+        accessor.writeInt(12345);
+        accessor.flip();
+        final ByteBuffer res = accessor.readByteBuffer(3);

Review Comment:
   nit: `testBuffer` maybe? 



##########
clients/src/test/java/org/apache/kafka/common/protocol/ByteBufferAccessorTest.java:
##########
@@ -40,6 +40,27 @@ public void testReadArray() {
         assertEquals("Error reading byte array of 3 byte(s): only 0 byte(s) 
available",
             assertThrows(RuntimeException.class,
                 () -> accessor.readArray(3)).getMessage());
+        assertEquals("Error reading byte array of -1 byte(s): only 0 byte(s) 
available",
+            assertThrows(RuntimeException.class,
+                () -> accessor.readArray(-1)).getMessage());
+    }
+
+    @Test
+    public void testReadByteBuffer() {
+        ByteBuffer buf = ByteBuffer.allocate(1024);
+        ByteBufferAccessor accessor = new ByteBufferAccessor(buf);
+        final byte[] testArray = new byte[] {0x4b, 0x61, 0x46};
+        accessor.writeByteArray(testArray);
+        accessor.writeInt(12345);
+        accessor.flip();
+        final ByteBuffer res = accessor.readByteBuffer(3);
+        final byte[] resArray = new byte[3];
+        res.get(resArray);
+        assertArrayEquals(testArray, resArray);

Review Comment:
   nit: I'd keep the `testArray2` naming.
   ```suggestion
           final byte[] testArray2 = new byte[3];
           res.get(testArray2);
           assertArrayEquals(testArray, testArray2);
   ```



-- 
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