From 01aa8ab36387c5f1d66d098e71488bfb0eb5f39c Mon Sep 17 00:00:00 2001 From: AkashDeep <57340046+AkashDeepSinghJassal@users.noreply.github.com> Date: Mon, 18 Nov 2024 00:03:01 +0530 Subject: [PATCH] BE: Support sending null headers (#651) Co-authored-by: Roman Zabaluev --- .../ui/serdes/ProducerRecordCreator.java | 2 +- .../kafbat/ui/service/SendAndReadTests.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java b/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java index 359c871d6..e7abbad90 100644 --- a/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java +++ b/api/src/main/java/io/kafbat/ui/serdes/ProducerRecordCreator.java @@ -31,7 +31,7 @@ public ProducerRecord create(String topic, private Iterable
createHeaders(Map 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; } diff --git a/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java b/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java index cdf304509..fac5a5f59 100644 --- a/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java +++ b/api/src/test/java/io/kafbat/ui/service/SendAndReadTests.java @@ -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; @@ -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()