mjsax commented on code in PR #23157:
URL: https://github.com/apache/kafka/pull/23157#discussion_r3808756047
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/ChangedSerdeTest.java:
##########
@@ -216,4 +217,74 @@ public void shouldPassHeadersToUnderlyingDeserializer() {
verify(mockDeserializer).deserialize(TOPIC, HEADERS, value.getBytes());
verify(mockDeserializer, never()).deserialize(TOPIC, value.getBytes());
}
+
+ @Test
+ public void shouldThrowOnNewDataLengthLargerThanRemainingBytesForFlag2() {
+ final byte[] newData = STRING_SERIALIZER.serialize(TOPIC, HEADERS,
nonNullNewValue);
+ final byte[] oldData = STRING_SERIALIZER.serialize(TOPIC, HEADERS,
nonNullOldValue);
+ final int fakeNewDataLength = newData.length + oldData.length + 1; //
one past what the buffer can actually back
+
+ final int capacity = MAX_VARINT_LENGTH + newData.length +
oldData.length + ENCODING_FLAG_SIZE;
+ final ByteBuffer buf = ByteBuffer.allocate(capacity);
+ ByteUtils.writeVarint(fakeNewDataLength, buf);
+ buf.put(newData).put(oldData).put((byte) 2);
+ final byte[] serialized = new byte[buf.position()];
+ buf.position(0);
+ buf.get(serialized);
+
+ assertThrows(
+ BufferUnderflowException.class,
+ () -> CHANGED_STRING_DESERIALIZER.deserialize(TOPIC, HEADERS,
serialized));
Review Comment:
```suggestion
assertThrows(
BufferUnderflowException.class,
() -> CHANGED_STRING_DESERIALIZER.deserialize(TOPIC, HEADERS,
serialized)
);
```
##########
streams/src/test/java/org/apache/kafka/streams/kstream/internals/ChangedSerdeTest.java:
##########
@@ -216,4 +217,74 @@ public void shouldPassHeadersToUnderlyingDeserializer() {
verify(mockDeserializer).deserialize(TOPIC, HEADERS, value.getBytes());
verify(mockDeserializer, never()).deserialize(TOPIC, value.getBytes());
}
+
+ @Test
+ public void shouldThrowOnNewDataLengthLargerThanRemainingBytesForFlag2() {
+ final byte[] newData = STRING_SERIALIZER.serialize(TOPIC, HEADERS,
nonNullNewValue);
+ final byte[] oldData = STRING_SERIALIZER.serialize(TOPIC, HEADERS,
nonNullOldValue);
+ final int fakeNewDataLength = newData.length + oldData.length + 1; //
one past what the buffer can actually back
+
+ final int capacity = MAX_VARINT_LENGTH + newData.length +
oldData.length + ENCODING_FLAG_SIZE;
+ final ByteBuffer buf = ByteBuffer.allocate(capacity);
+ ByteUtils.writeVarint(fakeNewDataLength, buf);
+ buf.put(newData).put(oldData).put((byte) 2);
+ final byte[] serialized = new byte[buf.position()];
+ buf.position(0);
+ buf.get(serialized);
+
+ assertThrows(
+ BufferUnderflowException.class,
+ () -> CHANGED_STRING_DESERIALIZER.deserialize(TOPIC, HEADERS,
serialized));
Review Comment:
Similar below
--
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]