[ 
https://issues.apache.org/jira/browse/BEAM-7310?focusedWorklogId=380967&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-380967
 ]

ASF GitHub Bot logged work on BEAM-7310:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 03/Feb/20 13:53
            Start Date: 03/Feb/20 13:53
    Worklog Time Spent: 10m 
      Work Description: iemejia commented on pull request #10563: [BEAM-7310] 
Add support of Confluent Schema Registry for KafkaIO
URL: https://github.com/apache/beam/pull/10563#discussion_r374106551
 
 

 ##########
 File path: 
sdks/java/io/kafka/src/test/java/org/apache/beam/sdk/io/kafka/KafkaIOTest.java
 ##########
 @@ -391,6 +427,152 @@ public static void addCountingAsserts(
     PAssert.thatSingleton(input.apply("Max", Max.globally())).isEqualTo(max);
   }
 
+  @Test
+  public void testReadAvroKeysAsGenericRecords() {
+    int numElements = 100;
+    String topic = "my_topic";
+    String keySchemaSubject = topic + "-key";
+    String schemaRegistryUrl = "mock://my-scope-name";
+
+    List<KV<GenericRecord, Long>> inputs = new ArrayList<>();
+    for (int i = 0; i < numElements; i++) {
+      inputs.add(KV.of(new AvroGeneratedUser("KeyName" + i, i, "color" + i), 
(long) i));
+    }
+
+    KafkaIO.Read<GenericRecord, Long> reader =
+        KafkaIO.<GenericRecord, Long>read()
+            .withBootstrapServers("localhost:9092")
+            .withTopic(topic)
+            .withValueDeserializer(LongDeserializer.class)
+            .withConsumerFactoryFn(
+                new ConsumerFactoryFn(
+                    ImmutableList.of(topic),
+                    1,
+                    numElements,
+                    OffsetResetStrategy.EARLIEST,
+                    new KeyAvroSerializableFunction(topic, schemaRegistryUrl, 
true),
+                    i -> ByteBuffer.wrap(new byte[8]).putLong(i).array()))
+            .withMaxNumRecords(numElements)
+            .withCSRClientProvider(
+                new TestCSRClientProvider(schemaRegistryUrl, keySchemaSubject, 
null));
+
+    PCollection<KV<GenericRecord, Long>> input = 
p.apply(reader.withoutMetadata());
+
+    PAssert.that(input).containsInAnyOrder(inputs);
+    p.run();
+  }
+
+  @Test
+  public void testReadAvroValuesAsGenericRecords() {
+    int numElements = 100;
+    String topic = "my_topic";
+    String valueSchemaSubject = topic + "-value";
+    String schemaRegistryUrl = "mock://my-scope-name";
+
+    List<KV<Integer, GenericRecord>> inputs = new ArrayList<>();
+    for (int i = 0; i < numElements; i++) {
+      inputs.add(KV.of(i, new AvroGeneratedUser("ValueName" + i, i, "color" + 
i)));
+    }
+
+    KafkaIO.Read<Integer, GenericRecord> reader =
+        KafkaIO.<Integer, GenericRecord>read()
+            .withBootstrapServers("localhost:9092")
+            .withTopic(topic)
+            .withKeyDeserializer(IntegerDeserializer.class)
+            .withConsumerFactoryFn(
+                new ConsumerFactoryFn(
+                    ImmutableList.of(topic),
+                    1,
+                    numElements,
+                    OffsetResetStrategy.EARLIEST,
+                    i -> ByteBuffer.wrap(new byte[4]).putInt(i).array(),
+                    new ValueAvroSerializableFunction(topic, 
schemaRegistryUrl, false)))
+            .withMaxNumRecords(numElements)
+            .withCSRClientProvider(
+                new TestCSRClientProvider(schemaRegistryUrl, null, 
valueSchemaSubject));
+
+    PCollection<KV<Integer, GenericRecord>> input = 
p.apply(reader.withoutMetadata());
+
+    PAssert.that(input).containsInAnyOrder(inputs);
+    p.run();
+  }
+
+  @Test
+  public void testReadAvroKeysValuesAsGenericRecords() {
+    int numElements = 100;
+    String topic = "my_topic";
+    String keySchemaSubject = topic + "-key";
+    String valueSchemaSubject = topic + "-value";
+    String schemaRegistryUrl = "mock://my-scope-name";
+
+    List<KV<GenericRecord, GenericRecord>> inputs = new ArrayList<>();
+    for (int i = 0; i < numElements; i++) {
+      inputs.add(
+          KV.of(
+              new AvroGeneratedUser("KeyName" + i, i, "color" + i),
+              new AvroGeneratedUser("ValueName" + i, i, "color" + i)));
+    }
+
+    KafkaIO.Read<GenericRecord, GenericRecord> reader =
+        KafkaIO.<GenericRecord, GenericRecord>read()
+            .withBootstrapServers("localhost:9092")
+            .withTopic(topic)
+            .withConsumerFactoryFn(
+                new ConsumerFactoryFn(
+                    ImmutableList.of(topic),
+                    1,
+                    numElements,
+                    OffsetResetStrategy.EARLIEST,
+                    new KeyAvroSerializableFunction(topic, schemaRegistryUrl, 
true),
+                    new ValueAvroSerializableFunction(topic, 
schemaRegistryUrl, false)))
+            .withMaxNumRecords(numElements)
+            .withCSRClientProvider(
+                new TestCSRClientProvider(schemaRegistryUrl, keySchemaSubject, 
valueSchemaSubject));
+
+    PCollection<KV<GenericRecord, GenericRecord>> input = 
p.apply(reader.withoutMetadata());
+
+    PAssert.that(input).containsInAnyOrder(inputs);
+    p.run();
+  }
+
+  @Test
+  public void testReadAvroValuesAsPojoRecords() {
 
 Review comment:
   `s/PojoRecord/SpecificRecords` by Avro common parlance
 
----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 380967)

> Confluent Schema Registry support in KafkaIO
> --------------------------------------------
>
>                 Key: BEAM-7310
>                 URL: https://issues.apache.org/jira/browse/BEAM-7310
>             Project: Beam
>          Issue Type: Improvement
>          Components: io-java-kafka
>    Affects Versions: 2.12.0
>            Reporter: Yohei Shimomae
>            Assignee: Alexey Romanenko
>            Priority: Minor
>          Time Spent: 11.5h
>  Remaining Estimate: 0h
>
> Confluent Schema Registry is useful when we manage Avro Schema but  KafkaIO 
> does not support Confluent Schema Registry as discussed here.
> https://stackoverflow.com/questions/56035121/unable-to-connect-from-dataflow-job-to-schema-registry-when-schema-registry-requ
> https://lists.apache.org/thread.html/7695fccddebd08733b80ae1e43b79b636b63cd5fe583a2bdeecda6c4@%3Cuser.beam.apache.org%3E



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to