johnjcasey commented on code in PR #17742:
URL: https://github.com/apache/beam/pull/17742#discussion_r880905014


##########
sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOIT.java:
##########
@@ -203,6 +210,47 @@ public void testKafkaIOReadsAndWritesCorrectlyInBatch() 
throws IOException {
     }
   }
 
+  // This test roundtrips a single KV<Null,Null> to verify that 
externalWithMetadata
+  // can handle null keys and values correctly.
+  @Test
+  public void testKafkaIOExternalRoundtripWithMetadataAndNullKeysAndValues() {
+
+    List<byte[]> nullList = new ArrayList<>();
+    nullList.add(null);
+    writePipeline
+        .apply(Create.of(nullList))
+        .apply(
+            ParDo.of(
+                new DoFn<byte[], KV<byte[], byte[]>>() {
+                  @ProcessElement
+                  public void processElement(
+                      @Element byte[] element, OutputReceiver<KV<byte[], 
byte[]>> receiver) {
+                    receiver.output(KV.of(element, element));
+                  }
+                }))
+        .apply(
+            KafkaIO.<byte[], byte[]>write()
+                
.withBootstrapServers(options.getKafkaBootstrapServerAddresses())
+                .withTopic(options.getKafkaTopic())
+                .withKeySerializer(ByteArraySerializer.class)
+                .withValueSerializer(ByteArraySerializer.class));
+
+    PipelineResult writeResult = writePipeline.run();
+    writeResult.waitUntilFinish();
+
+    readPipeline.apply(
+        KafkaIO.<byte[], byte[]>read()
+            .withBootstrapServers(options.getKafkaBootstrapServerAddresses())
+            .withTopic(options.getKafkaTopic())
+            .withKeyDeserializerAndCoder(
+                ByteArrayDeserializer.class, 
NullableCoder.of(ByteArrayCoder.of()))
+            .withValueDeserializerAndCoder(
+                ByteArrayDeserializer.class, 
NullableCoder.of(ByteArrayCoder.of()))
+            .externalWithMetadata());
+    PipelineResult readResult = readPipeline.run();
+    readResult.waitUntilFinish();

Review Comment:
   Yep, ty



-- 
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]

Reply via email to