Search in sources :

Example 11 with ListShardsResult

use of com.amazonaws.services.kinesis.model.ListShardsResult in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForLatest.

@Test
public void shouldListAllShardsForLatest() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withShardFilter(new ShardFilter().withType(ShardFilterType.AT_LATEST)).withMaxResults(1_000))).thenReturn(new ListShardsResult().withShards(shard1, shard2, shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(InitialPositionInStream.LATEST));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Shard(com.amazonaws.services.kinesis.model.Shard) Test(org.junit.Test)

Example 12 with ListShardsResult

use of com.amazonaws.services.kinesis.model.ListShardsResult in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampWithinStreamRetentionAfterStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampWithinStreamRetentionAfterStreamCreationTimestamp() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    int hoursDifference = 1;
    int retentionPeriodHours = hoursDifference * 3;
    Instant streamCreationTimestamp = CURRENT_TIMESTAMP.minus(Duration.standardHours(retentionPeriodHours));
    Instant startingPointTimestamp = streamCreationTimestamp.plus(Duration.standardHours(hoursDifference));
    when(currentInstantSupplier.get()).thenReturn(CURRENT_TIMESTAMP);
    when(kinesis.describeStreamSummary(new DescribeStreamSummaryRequest().withStreamName(STREAM))).thenReturn(new DescribeStreamSummaryResult().withStreamDescriptionSummary(new StreamDescriptionSummary().withRetentionPeriodHours(retentionPeriodHours).withStreamCreationTimestamp(streamCreationTimestamp.toDate())));
    ShardFilter shardFilter = new ShardFilter().withType(ShardFilterType.AT_TIMESTAMP).withTimestamp(startingPointTimestamp.toDate());
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withShardFilter(shardFilter).withMaxResults(1_000))).thenReturn(new ListShardsResult().withShards(shard1, shard2, shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(startingPointTimestamp));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : StreamDescriptionSummary(com.amazonaws.services.kinesis.model.StreamDescriptionSummary) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) Instant(org.joda.time.Instant) DescribeStreamSummaryResult(com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult) DescribeStreamSummaryRequest(com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Shard(com.amazonaws.services.kinesis.model.Shard) Datapoint(com.amazonaws.services.cloudwatch.model.Datapoint) Test(org.junit.Test)

Example 13 with ListShardsResult

use of com.amazonaws.services.kinesis.model.ListShardsResult in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForTrimHorizon.

@Test
public void shouldListAllShardsForTrimHorizon() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    ShardFilter shardFilter = new ShardFilter().withType(ShardFilterType.AT_TRIM_HORIZON);
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withShardFilter(shardFilter).withMaxResults(1_000))).thenReturn(new ListShardsResult().withShards(shard1, shard2, shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(InitialPositionInStream.TRIM_HORIZON));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Shard(com.amazonaws.services.kinesis.model.Shard) Test(org.junit.Test)

Example 14 with ListShardsResult

use of com.amazonaws.services.kinesis.model.ListShardsResult in project flink by apache.

the class KinesisProxyTest method testGetShardWithNoNewShards.

@Test
public void testGetShardWithNoNewShards() throws Exception {
    // given
    String fakeStreamName = "fake-stream";
    AmazonKinesis mockClient = mock(AmazonKinesis.class);
    KinesisProxy kinesisProxy = getProxy(mockClient);
    Mockito.when(mockClient.listShards(new ListShardsRequest().withStreamName(fakeStreamName).withExclusiveStartShardId(KinesisShardIdGenerator.generateFromShardOrder(1)))).thenReturn(new ListShardsResult().withShards(Collections.emptyList()));
    HashMap<String, String> streamHashMap = new HashMap<>();
    streamHashMap.put(fakeStreamName, KinesisShardIdGenerator.generateFromShardOrder(1));
    // when
    GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);
    // then
    Assert.assertFalse(shardListResult.hasRetrievedShards());
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) HashMap(java.util.HashMap) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) Test(org.junit.Test)

Example 15 with ListShardsResult

use of com.amazonaws.services.kinesis.model.ListShardsResult in project flink by apache.

the class KinesisProxyTest method testGetShardList.

@Test
public void testGetShardList() throws Exception {
    List<String> shardIds = Arrays.asList("shardId-000000000000", "shardId-000000000001", "shardId-000000000002", "shardId-000000000003");
    String nextToken = "NextToken";
    String fakeStreamName = "fake-stream";
    List<Shard> shards = shardIds.stream().map(shardId -> new Shard().withShardId(shardId)).collect(Collectors.toList());
    AmazonKinesis mockClient = mock(AmazonKinesis.class);
    KinesisProxy kinesisProxy = getProxy(mockClient);
    ListShardsResult responseWithMoreData = new ListShardsResult().withShards(shards.subList(0, 2)).withNextToken(nextToken);
    ListShardsResult responseFinal = new ListShardsResult().withShards(shards.subList(2, shards.size())).withNextToken(null);
    doReturn(responseWithMoreData).when(mockClient).listShards(argThat(initialListShardsRequestMatcher()));
    doReturn(responseFinal).when(mockClient).listShards(argThat(listShardsNextToken(nextToken)));
    HashMap<String, String> streamHashMap = createInitialSubscribedStreamsToLastDiscoveredShardsState(Arrays.asList(fakeStreamName));
    GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);
    Assert.assertEquals(shardListResult.hasRetrievedShards(), true);
    Set<String> expectedStreams = new HashSet<>();
    expectedStreams.add(fakeStreamName);
    Assert.assertEquals(shardListResult.getStreamsWithRetrievedShards(), expectedStreams);
    List<StreamShardHandle> actualShardList = shardListResult.getRetrievedShardListOfStream(fakeStreamName);
    List<StreamShardHandle> expectedStreamShard = new ArrayList<>();
    assertThat(actualShardList, hasSize(4));
    for (int i = 0; i < 4; i++) {
        StreamShardHandle shardHandle = new StreamShardHandle(fakeStreamName, new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(i)));
        expectedStreamShard.add(shardHandle);
    }
    Assert.assertThat(actualShardList, containsInAnyOrder(expectedStreamShard.toArray(new StreamShardHandle[actualShardList.size()])));
}
Also used : Shard(com.amazonaws.services.kinesis.model.Shard) Arrays(java.util.Arrays) MutableInt(org.apache.commons.lang3.mutable.MutableInt) ConsumerConfigConstants(org.apache.flink.streaming.connectors.kinesis.config.ConsumerConfigConstants) IsIterableContainingInAnyOrder.containsInAnyOrder(org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder) ClientConfigurationFactory(com.amazonaws.ClientConfigurationFactory) InetAddress(java.net.InetAddress) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) KinesisShardIdGenerator(org.apache.flink.streaming.connectors.kinesis.testutils.KinesisShardIdGenerator) Mockito.doReturn(org.mockito.Mockito.doReturn) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) StreamShardHandle(org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle) Set(java.util.Set) Collectors(java.util.stream.Collectors) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) Matchers.any(org.mockito.Matchers.any) AWSConfigConstants(org.apache.flink.streaming.connectors.kinesis.config.AWSConfigConstants) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Mockito.mock(org.mockito.Mockito.mock) IntStream(java.util.stream.IntStream) Whitebox(org.powermock.reflect.Whitebox) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ProvisionedThroughputExceededException(com.amazonaws.services.kinesis.model.ProvisionedThroughputExceededException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConnectTimeoutException(org.apache.http.conn.ConnectTimeoutException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Description(org.hamcrest.Description) Properties(java.util.Properties) Assert.assertTrue(org.junit.Assert.assertTrue) ErrorType(com.amazonaws.AmazonServiceException.ErrorType) Test(org.junit.Test) UnknownHostException(java.net.UnknownHostException) Mockito(org.mockito.Mockito) SdkClientException(com.amazonaws.SdkClientException) ClientConfiguration(com.amazonaws.ClientConfiguration) AmazonKinesisClient(com.amazonaws.services.kinesis.AmazonKinesisClient) AWSUtil(org.apache.flink.streaming.connectors.kinesis.util.AWSUtil) AmazonKinesisException(com.amazonaws.services.kinesis.model.AmazonKinesisException) Assert(org.junit.Assert) ExpiredIteratorException(com.amazonaws.services.kinesis.model.ExpiredIteratorException) HttpHost(org.apache.http.HttpHost) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ArrayList(java.util.ArrayList) StreamShardHandle(org.apache.flink.streaming.connectors.kinesis.model.StreamShardHandle) Shard(com.amazonaws.services.kinesis.model.Shard) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)21 Shard (com.amazonaws.services.kinesis.model.Shard)19 ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)18 Test (org.junit.Test)12 ShardFilter (com.amazonaws.services.kinesis.model.ShardFilter)9 SdkClientException (com.amazonaws.SdkClientException)6 DescribeStreamSummaryRequest (com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest)5 DescribeStreamSummaryResult (com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult)5 Instant (org.joda.time.Instant)5 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)4 StreamDescriptionSummary (com.amazonaws.services.kinesis.model.StreamDescriptionSummary)4 Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)3 AmazonKinesisClient (com.amazonaws.services.kinesis.AmazonKinesisClient)3 AmazonKinesisException (com.amazonaws.services.kinesis.model.AmazonKinesisException)3 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 AmazonServiceException (com.amazonaws.AmazonServiceException)2