hlteoh37 commented on code in PR #94: URL: https://github.com/apache/flink-connector-aws/pull/94#discussion_r1334871504
########## flink-connector-aws-e2e-tests/flink-connector-aws-kinesis-streams-e2e-tests/src/test/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkITCase.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.connector.kinesis.sink; + +import org.apache.flink.api.common.serialization.SerializationSchema; +import org.apache.flink.api.common.serialization.SimpleStringSchema; +import org.apache.flink.connector.aws.testutils.AWSServicesTestUtils; +import org.apache.flink.connector.aws.util.AWSGeneralUtil; +import org.apache.flink.connector.kinesis.testutils.AWSEndToEndTestUtils; +import org.apache.flink.connector.kinesis.testutils.AWSKinesisResourceManager; +import org.apache.flink.runtime.client.JobExecutionException; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource; +import org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.testcontainers.junit.jupiter.Testcontainers; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.services.kinesis.KinesisClient; +import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest; +import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest; +import software.amazon.awssdk.services.kinesis.model.ShardIteratorType; + +import java.util.Properties; + +import static org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT; + +/** End-to-end tests for Kinesis Data Streams Sink. */ +@Testcontainers +@ExtendWith(MiniClusterExtension.class) +@Execution(ExecutionMode.CONCURRENT) +class KinesisStreamsSinkITCase { + + private static final String DEFAULT_FIRST_SHARD_NAME = "shardId-000000000000"; + + private final SerializationSchema<String> serializationSchema = new SimpleStringSchema(); + private final PartitionKeyGenerator<String> partitionKeyGenerator = + element -> String.valueOf(element.hashCode()); + private final PartitionKeyGenerator<String> longPartitionKeyGenerator = element -> element; + + private StreamExecutionEnvironment env; + private SdkHttpClient httpClient; + private KinesisClient kinesisClient; + private AWSKinesisResourceManager kinesisResourceManager; + + @BeforeEach + void setUp() { + // TODO: Check if this is needed. + // System.setProperty(SdkSystemSetting.CBOR_ENABLED.property(), "false"); + + // Configure test environment + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setParallelism(1); + + httpClient = AWSServicesTestUtils.createHttpClient(); + kinesisClient = + AWSEndToEndTestUtils.createAwsSyncClient(httpClient, KinesisClient.builder()); + kinesisResourceManager = new AWSKinesisResourceManager(kinesisClient); + } + + @AfterEach + void teardown() { + // System.clearProperty(SdkSystemSetting.CBOR_ENABLED.property()); Review Comment: Yep - removed ########## flink-connector-aws-e2e-tests/flink-connector-aws-kinesis-streams-e2e-tests/src/test/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkITCase.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.connector.kinesis.sink; + +import org.apache.flink.api.common.serialization.SerializationSchema; +import org.apache.flink.api.common.serialization.SimpleStringSchema; +import org.apache.flink.connector.aws.testutils.AWSServicesTestUtils; +import org.apache.flink.connector.aws.util.AWSGeneralUtil; +import org.apache.flink.connector.kinesis.testutils.AWSEndToEndTestUtils; +import org.apache.flink.connector.kinesis.testutils.AWSKinesisResourceManager; +import org.apache.flink.runtime.client.JobExecutionException; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource; +import org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.testcontainers.junit.jupiter.Testcontainers; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.services.kinesis.KinesisClient; +import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest; +import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest; +import software.amazon.awssdk.services.kinesis.model.ShardIteratorType; + +import java.util.Properties; + +import static org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT; + +/** End-to-end tests for Kinesis Data Streams Sink. */ +@Testcontainers +@ExtendWith(MiniClusterExtension.class) +@Execution(ExecutionMode.CONCURRENT) +class KinesisStreamsSinkITCase { + + private static final String DEFAULT_FIRST_SHARD_NAME = "shardId-000000000000"; + + private final SerializationSchema<String> serializationSchema = new SimpleStringSchema(); + private final PartitionKeyGenerator<String> partitionKeyGenerator = + element -> String.valueOf(element.hashCode()); + private final PartitionKeyGenerator<String> longPartitionKeyGenerator = element -> element; + + private StreamExecutionEnvironment env; + private SdkHttpClient httpClient; + private KinesisClient kinesisClient; + private AWSKinesisResourceManager kinesisResourceManager; + + @BeforeEach + void setUp() { + // TODO: Check if this is needed. + // System.setProperty(SdkSystemSetting.CBOR_ENABLED.property(), "false"); + + // Configure test environment Review Comment: Done ########## flink-connector-aws-e2e-tests/flink-connector-aws-kinesis-streams-e2e-tests/src/test/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkITCase.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.connector.kinesis.sink; + +import org.apache.flink.api.common.serialization.SerializationSchema; +import org.apache.flink.api.common.serialization.SimpleStringSchema; +import org.apache.flink.connector.aws.testutils.AWSServicesTestUtils; +import org.apache.flink.connector.aws.util.AWSGeneralUtil; +import org.apache.flink.connector.kinesis.testutils.AWSEndToEndTestUtils; +import org.apache.flink.connector.kinesis.testutils.AWSKinesisResourceManager; +import org.apache.flink.runtime.client.JobExecutionException; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource; +import org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.testcontainers.junit.jupiter.Testcontainers; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.services.kinesis.KinesisClient; +import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest; +import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest; +import software.amazon.awssdk.services.kinesis.model.ShardIteratorType; + +import java.util.Properties; + +import static org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT; + +/** End-to-end tests for Kinesis Data Streams Sink. */ +@Testcontainers +@ExtendWith(MiniClusterExtension.class) +@Execution(ExecutionMode.CONCURRENT) +class KinesisStreamsSinkITCase { + + private static final String DEFAULT_FIRST_SHARD_NAME = "shardId-000000000000"; + + private final SerializationSchema<String> serializationSchema = new SimpleStringSchema(); + private final PartitionKeyGenerator<String> partitionKeyGenerator = + element -> String.valueOf(element.hashCode()); + private final PartitionKeyGenerator<String> longPartitionKeyGenerator = element -> element; + + private StreamExecutionEnvironment env; + private SdkHttpClient httpClient; + private KinesisClient kinesisClient; + private AWSKinesisResourceManager kinesisResourceManager; + + @BeforeEach + void setUp() { + // TODO: Check if this is needed. + // System.setProperty(SdkSystemSetting.CBOR_ENABLED.property(), "false"); + + // Configure test environment + env = StreamExecutionEnvironment.getExecutionEnvironment(); + env.setParallelism(1); + + httpClient = AWSServicesTestUtils.createHttpClient(); + kinesisClient = + AWSEndToEndTestUtils.createAwsSyncClient(httpClient, KinesisClient.builder()); + kinesisResourceManager = new AWSKinesisResourceManager(kinesisClient); + } + + @AfterEach + void teardown() { + // System.clearProperty(SdkSystemSetting.CBOR_ENABLED.property()); + kinesisResourceManager.close(); + AWSGeneralUtil.closeResources(httpClient, kinesisClient); + } + + @Test + void elementsMaybeWrittenSuccessfullyToLocalInstanceWhenBatchSizeIsReached() throws Exception { + new Scenario().runScenario(); + } + + @Test + void elementsBufferedAndTriggeredByTimeBasedFlushShouldBeFlushedIfSourcedIsKeptAlive() + throws Exception { + new Scenario() + .withNumberOfElementsToSend(10) + .withMaxBatchSize(100) + .withExpectedElements(10) + .runScenario(); + } + + @Test + void veryLargeMessagesSucceedInBeingPersisted() throws Exception { + new Scenario() + .withNumberOfElementsToSend(5) + .withSizeOfMessageBytes(2500) + .withMaxBatchSize(10) + .withExpectedElements(5) + .runScenario(); + } + + @Test + void multipleInFlightRequestsResultsInCorrectNumberOfElementsPersisted() throws Exception { + new Scenario() + .withNumberOfElementsToSend(150) + .withSizeOfMessageBytes(2500) + .withBufferMaxTimeMS(2000) + .withMaxInflightReqs(10) + .withMaxBatchSize(20) + .withExpectedElements(150) + .runScenario(); + } + + @Test + void nonExistentStreamNameShouldResultInFailureInFailOnErrorIsOn() { + testJobFatalFailureTerminatesCorrectlyWithFailOnErrorFlagSetTo(true); + } + + @Test + void nonExistentStreamNameShouldResultInFailureInFailOnErrorIsOff() { + testJobFatalFailureTerminatesCorrectlyWithFailOnErrorFlagSetTo(false); + } + + private void testJobFatalFailureTerminatesCorrectlyWithFailOnErrorFlagSetTo( + boolean failOnError) { + Assertions.assertThatExceptionOfType(JobExecutionException.class) + .isThrownBy( + () -> + new Scenario() + .withSinkConnectionStreamName( + "flink-test-stream-not-exists") + .withFailOnError(failOnError) + .runScenario()) + .havingCause() + .havingCause() + .havingCause() + .withMessageContaining("Stream flink-test-stream-not-exists under account"); + } + + @Test + void veryLargeMessagesFailGracefullyWithBrokenElementConverter() { + Assertions.assertThatExceptionOfType(JobExecutionException.class) + .isThrownBy( + () -> + new Scenario() + .withNumberOfElementsToSend(5) + .withSizeOfMessageBytes(2500) + .withExpectedElements(5) + .withSerializationSchema(serializationSchema) + .withPartitionKeyGenerator(longPartitionKeyGenerator) + .runScenario()) + .havingCause() + .havingCause() + .withMessageContaining( + "Encountered an exception while persisting records, not retrying due to {failOnError} being set."); + } + + @Test + void badEndpointShouldResultInFailureWhenInFailOnErrorIsOn() { + badEndpointShouldResultInFailureWhenInFailOnErrorIs(true); + } + + @Test + void badEndpointShouldResultInFailureWhenInFailOnErrorIsOff() { + badEndpointShouldResultInFailureWhenInFailOnErrorIs(false); + } + + private void badEndpointShouldResultInFailureWhenInFailOnErrorIs(boolean failOnError) { + Properties properties = getDefaultProperties(); Review Comment: Yep - modified the activation profiles to be disabled by default. ########## flink-connector-aws-e2e-tests/flink-connector-aws-kinesis-streams-e2e-tests/src/test/java/org/apache/flink/connector/kinesis/sink/KinesisStreamsSinkITCase.java: ########## @@ -0,0 +1,365 @@ +/* + * 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.connector.kinesis.sink; + +import org.apache.flink.api.common.serialization.SerializationSchema; +import org.apache.flink.api.common.serialization.SimpleStringSchema; +import org.apache.flink.connector.aws.testutils.AWSServicesTestUtils; +import org.apache.flink.connector.aws.util.AWSGeneralUtil; +import org.apache.flink.connector.kinesis.testutils.AWSEndToEndTestUtils; +import org.apache.flink.connector.kinesis.testutils.AWSKinesisResourceManager; +import org.apache.flink.runtime.client.JobExecutionException; +import org.apache.flink.streaming.api.datastream.DataStream; +import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment; +import org.apache.flink.streaming.api.functions.source.datagen.DataGeneratorSource; +import org.apache.flink.streaming.api.functions.source.datagen.RandomGenerator; +import org.apache.flink.test.junit5.MiniClusterExtension; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.parallel.Execution; +import org.junit.jupiter.api.parallel.ExecutionMode; +import org.testcontainers.junit.jupiter.Testcontainers; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.services.kinesis.KinesisClient; +import software.amazon.awssdk.services.kinesis.model.GetRecordsRequest; +import software.amazon.awssdk.services.kinesis.model.GetShardIteratorRequest; +import software.amazon.awssdk.services.kinesis.model.ShardIteratorType; + +import java.util.Properties; + +import static org.apache.flink.connector.aws.config.AWSConfigConstants.AWS_ENDPOINT; + +/** End-to-end tests for Kinesis Data Streams Sink. */ +@Testcontainers +@ExtendWith(MiniClusterExtension.class) +@Execution(ExecutionMode.CONCURRENT) +class KinesisStreamsSinkITCase { + + private static final String DEFAULT_FIRST_SHARD_NAME = "shardId-000000000000"; + + private final SerializationSchema<String> serializationSchema = new SimpleStringSchema(); + private final PartitionKeyGenerator<String> partitionKeyGenerator = + element -> String.valueOf(element.hashCode()); + private final PartitionKeyGenerator<String> longPartitionKeyGenerator = element -> element; + + private StreamExecutionEnvironment env; + private SdkHttpClient httpClient; + private KinesisClient kinesisClient; + private AWSKinesisResourceManager kinesisResourceManager; + + @BeforeEach + void setUp() { + // TODO: Check if this is needed. + // System.setProperty(SdkSystemSetting.CBOR_ENABLED.property(), "false"); Review Comment: Nope. Not needed. Removed -- 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: issues-unsubscr...@flink.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org