dawidwys commented on a change in pull request #12919:
URL: https://github.com/apache/flink/pull/12919#discussion_r460021794



##########
File path: 
flink-formats/flink-avro-confluent-registry/src/test/java/org/apache/flink/formats/avro/registry/confluent/RegistryAvroRowDataSeDeSchemaTest.java
##########
@@ -0,0 +1,199 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.formats.avro.registry.confluent;
+
+import org.apache.flink.formats.avro.AvroRowDataDeserializationSchema;
+import org.apache.flink.formats.avro.AvroRowDataSerializationSchema;
+import org.apache.flink.formats.avro.AvroToRowDataConverters;
+import org.apache.flink.formats.avro.RegistryAvroDeserializationSchema;
+import org.apache.flink.formats.avro.RegistryAvroSerializationSchema;
+import org.apache.flink.formats.avro.RowDataToAvroConverters;
+import org.apache.flink.formats.avro.generated.Address;
+import org.apache.flink.formats.avro.typeutils.AvroSchemaConverter;
+import org.apache.flink.formats.avro.utils.TestDataGenerator;
+import org.apache.flink.table.data.GenericRowData;
+import org.apache.flink.table.data.RowData;
+import org.apache.flink.table.data.binary.BinaryStringData;
+import org.apache.flink.table.runtime.typeutils.InternalTypeInfo;
+import org.apache.flink.table.types.DataType;
+import org.apache.flink.table.types.logical.RowType;
+
+import io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient;
+import io.confluent.kafka.schemaregistry.client.SchemaRegistryClient;
+import 
io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException;
+import org.apache.avro.Schema;
+import org.apache.avro.generic.GenericRecord;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+
+import java.io.IOException;
+import java.util.Random;
+
+import static org.apache.flink.core.testutils.FlinkMatchers.containsCause;
+import static org.apache.flink.formats.avro.utils.AvroTestUtils.writeRecord;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+
+/**
+ * Tests for {@link AvroRowDataDeserializationSchema} and
+ * {@link AvroRowDataSerializationSchema} for schema registry avro.
+ */
+public class RegistryAvroRowDataSeDeSchemaTest {
+       private static final Schema ADDRESS_SCHEMA = Address.getClassSchema();
+
+       private static final Schema ADDRESS_SCHEMA_COMPATIBLE = new 
Schema.Parser().parse(
+                       "" +
+                                       "{\"namespace\": 
\"org.apache.flink.formats.avro.generated\",\n" +
+                                       " \"type\": \"record\",\n" +
+                                       " \"name\": \"Address\",\n" +
+                                       " \"fields\": [\n" +
+                                       "     {\"name\": \"num\", \"type\": 
\"int\"},\n" +
+                                       "     {\"name\": \"street\", \"type\": 
\"string\"}\n" +
+                                       "  ]\n" +
+                                       "}");
+
+       private static final String SUBJECT = "address-value";
+
+       private static SchemaRegistryClient client;
+
+       private Address address;
+
+       @Rule
+       public ExpectedException expectedEx = ExpectedException.none();
+
+       @BeforeClass
+       public static void beforeClass() {
+               client = new MockSchemaRegistryClient();
+       }
+
+       @Before
+       public void before() {
+               this.address = TestDataGenerator.generateRandomAddress(new 
Random());
+       }
+
+       @After
+       public void after() throws IOException, RestClientException {
+               client.deleteSubject(SUBJECT);
+       }
+
+       @Test
+       public void testRowDataWriteReadWithFullSchema() throws Exception {
+               testRowDataWriteReadWithSchema(ADDRESS_SCHEMA);
+       }
+
+       @Test
+       public void testRowDataWriteReadWithCompatibleSchema() throws Exception 
{
+               testRowDataWriteReadWithSchema(ADDRESS_SCHEMA_COMPATIBLE);
+               // Validates new schema has been registered.
+               assertThat(client.getAllVersions("address-value").size(), 
is(1));

Review comment:
       nit: use `SUBJECT`

##########
File path: 
flink-formats/flink-avro/src/main/java/org/apache/flink/formats/avro/RegistryAvroDeserializationSchema.java
##########
@@ -52,13 +53,22 @@
         * @param schemaCoderProvider schema provider that allows instantiation 
of {@link SchemaCoder} that will be used for
         *                            schema reading
         */
-       protected RegistryAvroDeserializationSchema(Class<T> recordClazz, 
@Nullable Schema reader,
+       public RegistryAvroDeserializationSchema(Class<T> recordClazz, 
@Nullable Schema reader,
                        SchemaCoder.SchemaCoderProvider schemaCoderProvider) {
                super(recordClazz, reader);
                this.schemaCoderProvider = schemaCoderProvider;
                this.schemaCoder = schemaCoderProvider.get();
        }
 
+       public static RegistryAvroDeserializationSchema<GenericRecord> 
forGeneric(

Review comment:
       Remove this method? If you prefer to keep it add missing javadoc.




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


Reply via email to