gguptp commented on code in PR #146: URL: https://github.com/apache/flink-connector-aws/pull/146#discussion_r1670507298
########## flink-connector-aws/flink-connector-dynamodb/src/test/java/org/apache/flink/connector/dynamodb/source/proxy/DynamoDbStreamsProxyTest.java: ########## @@ -0,0 +1,253 @@ +/* + * 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.dynamodb.source.proxy; + +import org.apache.flink.connector.dynamodb.source.split.StartingPosition; +import org.apache.flink.connector.dynamodb.source.util.DynamoDbStreamsClientProvider.DescribeStreamItem; +import org.apache.flink.connector.dynamodb.source.util.DynamoDbStreamsClientProvider.TestingDynamoDbStreamsClient; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.NullAndEmptySource; +import org.junit.jupiter.params.provider.ValueSource; +import software.amazon.awssdk.http.SdkHttpClient; +import software.amazon.awssdk.http.apache.ApacheHttpClient; +import software.amazon.awssdk.services.dynamodb.model.DescribeStreamRequest; +import software.amazon.awssdk.services.dynamodb.model.DynamoDbStreamsRequest; +import software.amazon.awssdk.services.dynamodb.model.ExpiredIteratorException; +import software.amazon.awssdk.services.dynamodb.model.GetRecordsRequest; +import software.amazon.awssdk.services.dynamodb.model.GetRecordsResponse; +import software.amazon.awssdk.services.dynamodb.model.GetShardIteratorRequest; +import software.amazon.awssdk.services.dynamodb.model.Record; +import software.amazon.awssdk.services.dynamodb.model.Shard; +import software.amazon.awssdk.services.dynamodb.model.ShardIteratorType; +import software.amazon.awssdk.services.dynamodb.model.StreamStatus; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Consumer; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import static org.apache.flink.connector.dynamodb.source.util.TestUtil.generateShardId; +import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatNoException; + +/** Tests to validate {@link DynamoDbStreamsProxy}. */ +public class DynamoDbStreamsProxyTest { + private static final SdkHttpClient HTTP_CLIENT = ApacheHttpClient.builder().build(); + + @ParameterizedTest + @NullAndEmptySource + @ValueSource(strings = {"shardId-000000000002"}) + void testListShards(String lastSeenShardId) { + final String streamArn = + "arn:aws:dynamodb:us-east-1:1231231230:table/test/stream/2024-01-01T00:00:00.826"; + final List<Shard> expectedShards = getTestShards(0, 3); + List<DescribeStreamItem> describeStreamItems = + Stream.of( + DescribeStreamItem.builder() + .validation( + getDescribeStreamRequestValidation( + streamArn, lastSeenShardId)) + .nextToken(null) + .shards(expectedShards) + .streamStatus(StreamStatus.ENABLED) + .streamArn(streamArn) + .build(), + DescribeStreamItem.builder() + .validation( + getDescribeStreamRequestValidation( + streamArn, + expectedShards + .get(expectedShards.size() - 1) + .shardId())) + .shards(Collections.EMPTY_LIST) + .streamStatus(StreamStatus.ENABLED) + .streamArn(streamArn) + .build()) + .collect(Collectors.toList()); + TestingDynamoDbStreamsClient testingDynamoDbStreamsClient = + new TestingDynamoDbStreamsClient(); + testingDynamoDbStreamsClient.setDescribeStreamResponse(describeStreamItems); + + DynamoDbStreamsProxy dynamoDbStreamsProxy = + new DynamoDbStreamsProxy(testingDynamoDbStreamsClient, HTTP_CLIENT); + + assertThat(dynamoDbStreamsProxy.listShards(streamArn, lastSeenShardId)) + .isEqualTo(expectedShards); + } + + @Test + void testGetRecordsInitialReadFromTrimHorizon() { Review Comment: yes -- 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]
