@@ -153,3 +153,46 @@ TEST(MessageTest, testGetTopicNameOnProducerMessage) {
153153 auto msg = MessageBuilder ().setContent (" test" ).build ();
154154 ASSERT_TRUE (msg.getTopicName ().empty ());
155155}
156+
157+ TEST (MessageTest, testNullValueMessage) {
158+ {
159+ auto msg = MessageBuilder ().setContent (" test" ).build ();
160+ ASSERT_FALSE (msg.hasNullValue ());
161+ }
162+
163+ {
164+ auto msg = MessageBuilder ().setNullValue ().setPartitionKey (" key1" ).build ();
165+ ASSERT_TRUE (msg.hasNullValue ());
166+ ASSERT_EQ (msg.getLength (), 0 );
167+ ASSERT_EQ (msg.getPartitionKey (), " key1" );
168+ }
169+
170+ {
171+ auto msg = MessageBuilder ().setPartitionKey (" key2" ).setNullValue ().build ();
172+ ASSERT_TRUE (msg.hasNullValue ());
173+ ASSERT_EQ (msg.getPartitionKey (), " key2" );
174+ }
175+ }
176+
177+ TEST (MessageTest, testEmptyMessage) {
178+ auto msg = MessageBuilder ().build ();
179+ ASSERT_FALSE (msg.hasNullValue ());
180+ ASSERT_EQ (msg.getLength (), 0 );
181+ }
182+
183+ TEST (MessageTest, testEmptyStringNotNullValue) {
184+ // Empty string message - has content set to ""
185+ auto emptyStringMsg = MessageBuilder ().setContent (" " ).build ();
186+ ASSERT_FALSE (emptyStringMsg.hasNullValue ());
187+ ASSERT_EQ (emptyStringMsg.getLength (), 0 );
188+ ASSERT_EQ (emptyStringMsg.getDataAsString (), " " );
189+
190+ // Null value message - explicitly marked as null
191+ auto nullValueMsg = MessageBuilder ().setNullValue ().setPartitionKey (" key" ).build ();
192+ ASSERT_TRUE (nullValueMsg.hasNullValue ());
193+ ASSERT_EQ (nullValueMsg.getLength (), 0 );
194+
195+ // Both have length 0, but they are semantically different
196+ // Empty string: the value IS an empty string
197+ // Null value: the value does not exist (tombstone for compaction)
198+ }
0 commit comments