Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static String extractThreadId(final String fullThreadName) {

public static long producerRecordSizeInBytes(final ProducerRecord<byte[], byte[]> record) {
return recordSizeInBytes(
record.key().length,
record.key() == null ? 0 : record.key().length,
record.value() == null ? 0 : record.value().length,
record.topic(),
record.headers()
Expand All @@ -190,10 +190,10 @@ public static long consumerRecordSizeInBytes(final ConsumerRecord<byte[], byte[]
);
}

public static long recordSizeInBytes(final long keyBytes,
final long valueBytes,
final String topic,
final Headers headers) {
private static long recordSizeInBytes(final long keyBytes,
final long valueBytes,
final String topic,
final Headers headers) {
long headerSizeInBytes = 0L;

if (headers != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ public class ClientUtilsTest {

private static final Headers HEADERS = new RecordHeaders(asList(
new RecordHeader("h1", "headerVal1".getBytes()), // 2 + 10 --> 12 bytes
new RecordHeader("h2", "headerVal2".getBytes())
)); // 2 + 10 --> 12 bytes
new RecordHeader("h2", "headerVal2".getBytes()) // 2 + 10 --> 12 bytes
));
private static final int HEADERS_BYTES = 24;

// 20 bytes
private static final int RECORD_METADATA_BYTES =
8 + // timestamp
8 + // offset
Expand All @@ -86,6 +87,14 @@ public class ClientUtilsTest {
HEADERS_BYTES +
RECORD_METADATA_BYTES;

// 54 bytes
private static final long NULL_KEY_SIZE_IN_BYTES =
VALUE_BYTES +
TOPIC_BYTES +
HEADERS_BYTES +
RECORD_METADATA_BYTES;

// 52 bytes
private static final long TOMBSTONE_SIZE_IN_BYTES =
KEY_BYTES +
TOPIC_BYTES +
Expand Down Expand Up @@ -202,6 +211,37 @@ public void shouldComputeSizeInBytesForProducerRecord() {
assertThat(producerRecordSizeInBytes(record), equalTo(SIZE_IN_BYTES));
}

@Test
public void shouldComputeSizeInBytesForConsumerRecordWithNullKey() {
final ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>(
TOPIC,
1,
0,
0L,
TimestampType.CREATE_TIME,
0,
5,
null,
VALUE,
HEADERS,
Optional.empty()
);
assertThat(consumerRecordSizeInBytes(record), equalTo(NULL_KEY_SIZE_IN_BYTES));
}

@Test
public void shouldComputeSizeInBytesForProducerRecordWithNullKey() {
final ProducerRecord<byte[], byte[]> record = new ProducerRecord<>(
TOPIC,
1,
0L,
null,
VALUE,
HEADERS
);
assertThat(producerRecordSizeInBytes(record), equalTo(NULL_KEY_SIZE_IN_BYTES));
}

@Test
public void shouldComputeSizeInBytesForConsumerRecordWithNullValue() {
final ConsumerRecord<byte[], byte[]> record = new ConsumerRecord<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.Duration;
import java.time.Instant;
Expand All @@ -55,8 +53,6 @@
import static org.junit.jupiter.api.Assertions.assertThrows;

public class TestTopicsTest {
private static final Logger log = LoggerFactory.getLogger(TestTopicsTest.class);

private final static String INPUT_TOPIC = "input";
private final static String OUTPUT_TOPIC = "output1";
private final static String INPUT_TOPIC_MAP = OUTPUT_TOPIC;
Expand Down Expand Up @@ -171,15 +167,13 @@ public void testKeyValuesToMap() {
}

@Test
public void testPipeInputWithNullKey() {
public void testKeyValuesToMapWithNull() {
final TestInputTopic<Long, String> inputTopic =
testDriver.createInputTopic(INPUT_TOPIC, longSerde.serializer(), stringSerde.serializer());
final TestOutputTopic<Long, String> outputTopic =
testDriver.createOutputTopic(OUTPUT_TOPIC, longSerde.deserializer(), stringSerde.deserializer());
final StreamsException exception = assertThrows(StreamsException.class, () -> inputTopic.pipeInput("value"));
assertThat(exception.getCause() instanceof NullPointerException, is(true));
assertThat(outputTopic.readKeyValuesToMap().isEmpty(), is(true));

inputTopic.pipeInput("value");
assertThrows(IllegalStateException.class, outputTopic::readKeyValuesToMap);
}

@Test
Expand Down