Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • If the old behavior is correct, then the new behavior is also correct.

Test Plan

Perform serialization tests with HeapByteBuffer/ DirectByteBuffer of suitable and larger capacity:
Code Block
languagejava
    @Test
    public void testByteBufferSerializer() {
        final byte[] bytes = "Hello".getBytes(UTF_8);
        final ByteBuffer heapBuffer0 = ByteBuffer.allocate(bytes.length + 1).put(bytes);
        final ByteBuffer heapBuffer1 = ByteBuffer.allocate(bytes.length).put(bytes);
        final ByteBuffer heapBuffer2 = ByteBuffer.wrap(bytes);
        final ByteBuffer directBuffer0 = ByteBuffer.allocateDirect(bytes.length + 1).put(bytes);
        final ByteBuffer directBuffer1 = ByteBuffer.allocateDirect(bytes.length).put(bytes);
        try (final ByteBufferSerializer serializer = new ByteBufferSerializer()) {
            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer0));
            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer1));
            assertArrayEquals(bytes, serializer.serialize(topic, heapBuffer2));
            assertArrayEquals(bytes, serializer.serialize(topic, directBuffer0));
            assertArrayEquals(bytes, serializer.serialize(topic, directBuffer1));
        }
    }

...