Skip to content

Commit

Permalink
BE: Support sending null headers (#651)
Browse files Browse the repository at this point in the history
Co-authored-by: Roman Zabaluev <[email protected]>
  • Loading branch information
AkashDeepSinghJassal and Haarolean authored Nov 17, 2024
1 parent 8f9c634 commit 01aa8ab
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ProducerRecord<byte[], byte[]> create(String topic,

private Iterable<Header> createHeaders(Map<String, String> clientHeaders) {
RecordHeaders headers = new RecordHeaders();
clientHeaders.forEach((k, v) -> headers.add(new RecordHeader(k, v.getBytes())));
clientHeaders.forEach((k, v) -> headers.add(new RecordHeader(k, v == null ? null : v.getBytes())));
return headers;
}

Expand Down
20 changes: 20 additions & 0 deletions api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.kafbat.ui.serdes.builtin.StringSerde;
import io.kafbat.ui.serdes.builtin.sr.SchemaRegistrySerde;
import java.time.Duration;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -425,6 +426,25 @@ void topicMessageMetadataJson() {
});
}

@Test
void headerValueNullPresentTest() {
new SendAndReadSpec()
.withKeySchema(JSON_SCHEMA)
.withValueSchema(JSON_SCHEMA)
.withMsgToSend(
new CreateTopicMessageDTO()
.key(JSON_SCHEMA_RECORD)
.keySerde(SchemaRegistrySerde.name())
.content(JSON_SCHEMA_RECORD)
.valueSerde(SchemaRegistrySerde.name())
.headers(Collections.singletonMap("header123", null))
)
.doAssert(polled -> {
assertThat(polled.getHeaders().get("header123")).isNull();
});
}


@Test
void noKeyAndNoContentPresentTest() {
new SendAndReadSpec()
Expand Down

0 comments on commit 01aa8ab

Please sign in to comment.