hhkkxxx133 commented on a change in pull request #16513: URL: https://github.com/apache/flink/pull/16513#discussion_r695443537
########## File path: flink-end-to-end-tests/flink-glue-schema-registry-avro-test/src/test/java/org/apache/flink/glue/schema/registry/test/GlueSchemaRegistryAvroKinesisITCase.java ########## @@ -0,0 +1,228 @@ +/* + * 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.glue.schema.registry.test; + +import org.apache.flink.api.common.time.Deadline; +import org.apache.flink.formats.avro.glue.schema.registry.GlueSchemaRegistryAvroDeserializationSchema; +import org.apache.flink.formats.avro.glue.schema.registry.GlueSchemaRegistryAvroSerializationSchema; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.connectors.kinesis.FlinkKinesisConsumer; +import org.apache.flink.streaming.connectors.kinesis.FlinkKinesisProducer; +import org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants; +import org.apache.flink.streaming.connectors.kinesis.testutils.KinesaliteContainer; +import org.apache.flink.tests.util.categories.TravisGroup1; +import org.apache.flink.util.StringUtils; +import org.apache.flink.util.TestLogger; + +import com.amazonaws.services.schemaregistry.utils.AWSSchemaRegistryConstants; +import com.amazonaws.services.schemaregistry.utils.AvroRecordType; +import org.apache.avro.Schema; +import org.apache.avro.generic.GenericData; +import org.apache.avro.generic.GenericRecord; +import org.junit.Assert; +import org.junit.Assume; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.Timeout; +import org.testcontainers.containers.Network; +import org.testcontainers.utility.DockerImageName; + +import java.io.IOException; +import java.net.URL; +import java.time.Duration; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.TimeUnit; + +import static org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants.STREAM_INITIAL_POSITION; + +/** End-to-end test for Glue Schema Registry AVRO format using Kinesalite. */ +@Category(value = {TravisGroup1.class}) +public class GlueSchemaRegistryAvroKinesisITCase extends TestLogger { + private static final String INPUT_STREAM = "gsr_avro_input_stream"; + private static final String OUTPUT_STREAM = "gsr_avro_output_stream"; + private static final String INTER_CONTAINER_KINESALITE_ALIAS = "kinesalite"; + private static final String ACCESS_KEY = System.getenv("IT_CASE_GLUE_SCHEMA_ACCESS_KEY"); + private static final String SECRET_KEY = System.getenv("IT_CASE_GLUE_SCHEMA_SECRET_KEY"); + + private static final Network network = Network.newNetwork(); + + @ClassRule public static final Timeout TIMEOUT = new Timeout(10, TimeUnit.MINUTES); + + @ClassRule + public static final KinesaliteContainer KINESALITE = + new KinesaliteContainer( + DockerImageName.parse("instructure/kinesalite").withTag("latest")) + .withNetwork(network) + .withNetworkAliases(INTER_CONTAINER_KINESALITE_ALIAS); + + private GSRKinesisPubsubClient kinesisClient; + + @Before + public void setUp() throws Exception { + Assume.assumeTrue( + "Access key not configured, skipping test...", + !StringUtils.isNullOrWhitespaceOnly(ACCESS_KEY)); + Assume.assumeTrue( + "Secret key not configured, skipping test...", + !StringUtils.isNullOrWhitespaceOnly(SECRET_KEY)); + + Properties properties = KINESALITE.getContainerProperties(); + + kinesisClient = new GSRKinesisPubsubClient(properties); + kinesisClient.createStream(INPUT_STREAM, 2, properties); + kinesisClient.createStream(OUTPUT_STREAM, 2, properties); + } + + @Test + public void testGSRAvroSpecificFormatWithFlink() throws Exception { + List<GenericRecord> messages = getRecords(); + for (GenericRecord msg : messages) { + kinesisClient.sendMessage(getSchema().toString(), INPUT_STREAM, msg); + } + log.info("generated records"); + + executeFlinkForAvroSpecificFormat(); + + Deadline deadline = Deadline.fromNow(Duration.ofSeconds(60)); + List<Object> results = kinesisClient.readAllMessages(OUTPUT_STREAM); + while (deadline.hasTimeLeft() && results.size() < messages.size()) { + log.info("waiting for results.."); + Thread.sleep(1000); + results = kinesisClient.readAllMessages(OUTPUT_STREAM); + } + log.info("results: {}", results); + + Assert.assertEquals( + "Results received from '" + OUTPUT_STREAM + "': " + results, + messages.size(), + results.size()); + + List<GenericRecord> expectedResults = getRecords(); + for (Object expectedResult : expectedResults) { + Assert.assertTrue(results.contains(expectedResult)); + } + } + + private void executeFlinkForAvroSpecificFormat() throws Exception { + StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setParallelism(1); + + Properties properties = KINESALITE.getContainerProperties(); + properties.setProperty( + STREAM_INITIAL_POSITION, + ConsumerConfigConstants.InitialPosition.TRIM_HORIZON.name()); + FlinkKinesisConsumer<GenericRecord> consumer = + new FlinkKinesisConsumer<>( + INPUT_STREAM, + GlueSchemaRegistryAvroDeserializationSchema.forGeneric( + getSchema(), getConfigs()), + properties); + + Properties producerProperties = new Properties(properties); + // producer needs region even when URL is specified + producerProperties.put(ConsumerConfigConstants.AWS_REGION, "ca-central-1"); + // test driver does not deaggregate + producerProperties.put("AggregationEnabled", String.valueOf(false)); + Review comment: Thanks for the suggestion! Updated in the latest commit. ########## File path: flink-end-to-end-tests/test-scripts/test_glue_schema_registry_avro.sh ########## @@ -25,7 +25,7 @@ ################################################################################ Review comment: Deleted in the latest commit. -- 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]
