Search in sources :

Example 1 with DescribeStreamSummaryRequest

use of software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest in project flink by apache.

the class KinesisProxyV2Test method testDescribeStreamSummary.

@Test
public void testDescribeStreamSummary() throws Exception {
    KinesisAsyncClient client = mock(KinesisAsyncClient.class);
    KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), mock(FullJitterBackoff.class));
    DescribeStreamSummaryResponse expected = DescribeStreamSummaryResponse.builder().build();
    ArgumentCaptor<DescribeStreamSummaryRequest> requestCaptor = ArgumentCaptor.forClass(DescribeStreamSummaryRequest.class);
    when(client.describeStreamSummary(requestCaptor.capture())).thenReturn(CompletableFuture.completedFuture(expected));
    DescribeStreamSummaryResponse actual = proxy.describeStreamSummary("stream");
    assertEquals(expected, actual);
    DescribeStreamSummaryRequest request = requestCaptor.getValue();
    assertEquals("stream", request.streamName());
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) DescribeStreamSummaryRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) DescribeStreamSummaryResponse(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse) Test(org.junit.Test)

Example 2 with DescribeStreamSummaryRequest

use of software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampOutsideStreamRetentionAfterStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampOutsideStreamRetentionAfterStreamCreationTimestamp() throws Exception {
    Shard shard1 = Shard.builder().shardId(SHARD_1).build();
    Shard shard2 = Shard.builder().shardId(SHARD_2).build();
    Shard shard3 = Shard.builder().shardId(SHARD_3).build();
    int retentionPeriodHours = 3;
    int startingPointHours = 5;
    int hoursSinceStreamCreation = 6;
    Instant streamCreationTimestamp = CURRENT_TIMESTAMP.minus(Duration.standardHours(hoursSinceStreamCreation));
    Instant startingPointTimestampAfterStreamRetentionTimestamp = CURRENT_TIMESTAMP.minus(Duration.standardHours(startingPointHours));
    when(currentInstantSupplier.get()).thenReturn(CURRENT_TIMESTAMP);
    DescribeStreamSummaryRequest describeStreamRequest = DescribeStreamSummaryRequest.builder().streamName(STREAM).build();
    when(kinesis.describeStreamSummary(describeStreamRequest)).thenReturn(DescribeStreamSummaryResponse.builder().streamDescriptionSummary(StreamDescriptionSummary.builder().retentionPeriodHours(retentionPeriodHours).streamCreationTimestamp(TimeUtil.toJava(streamCreationTimestamp)).build()).build());
    ShardFilter shardFilter = ShardFilter.builder().type(ShardFilterType.AT_TRIM_HORIZON).build();
    when(kinesis.listShards(ListShardsRequest.builder().streamName(STREAM).shardFilter(shardFilter).maxResults(1_000).build())).thenReturn(ListShardsResponse.builder().shards(shard1, shard2, shard3).nextToken(null).build());
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(startingPointTimestampAfterStreamRetentionTimestamp));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : Instant(org.joda.time.Instant) DescribeStreamSummaryRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest) ShardFilter(software.amazon.awssdk.services.kinesis.model.ShardFilter) Shard(software.amazon.awssdk.services.kinesis.model.Shard) Datapoint(software.amazon.awssdk.services.cloudwatch.model.Datapoint) Test(org.junit.Test)

Example 3 with DescribeStreamSummaryRequest

use of software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest in project beam by apache.

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampBeforeStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampBeforeStreamCreationTimestamp() throws Exception {
    Shard shard1 = Shard.builder().shardId(SHARD_1).build();
    Shard shard2 = Shard.builder().shardId(SHARD_2).build();
    Shard shard3 = Shard.builder().shardId(SHARD_3).build();
    Instant startingPointTimestamp = Instant.parse("2000-01-01T15:00:00.000Z");
    Instant streamCreationTimestamp = startingPointTimestamp.plus(Duration.standardHours(1));
    DescribeStreamSummaryRequest describeStreamRequest = DescribeStreamSummaryRequest.builder().streamName(STREAM).build();
    when(kinesis.describeStreamSummary(describeStreamRequest)).thenReturn(DescribeStreamSummaryResponse.builder().streamDescriptionSummary(StreamDescriptionSummary.builder().streamCreationTimestamp(TimeUtil.toJava(streamCreationTimestamp)).build()).build());
    ShardFilter shardFilter = ShardFilter.builder().type(ShardFilterType.AT_TRIM_HORIZON).build();
    when(kinesis.listShards(ListShardsRequest.builder().streamName(STREAM).shardFilter(shardFilter).maxResults(1_000).build())).thenReturn(ListShardsResponse.builder().shards(shard1, shard2, shard3).nextToken(null).build());
    List<Shard> shards = underTest.listShardsAtPoint(STREAM, new StartingPoint(startingPointTimestamp));
    assertThat(shards).containsOnly(shard1, shard2, shard3);
}
Also used : Instant(org.joda.time.Instant) DescribeStreamSummaryRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest) ShardFilter(software.amazon.awssdk.services.kinesis.model.ShardFilter) Shard(software.amazon.awssdk.services.kinesis.model.Shard) Test(org.junit.Test)

Example 4 with DescribeStreamSummaryRequest

use of software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest in project beam by apache.

the class SimplifiedKinesisClient method describeStreamSummary.

private StreamDescriptionSummary describeStreamSummary(final String streamName) throws IOException, InterruptedException {
    // DescribeStreamSummary has limits that can be hit fairly easily if we are attempting
    // to configure multiple KinesisIO inputs in the same account. Retry up to
    // DESCRIBE_STREAM_SUMMARY_MAX_ATTEMPTS times if we end up hitting that limit.
    // 
    // Only pass the wrapped exception up once that limit is reached. Use FluentBackoff
    // to implement the retry policy.
    FluentBackoff retryBackoff = FluentBackoff.DEFAULT.withMaxRetries(DESCRIBE_STREAM_SUMMARY_MAX_ATTEMPTS).withInitialBackoff(DESCRIBE_STREAM_SUMMARY_INITIAL_BACKOFF);
    BackOff backoff = retryBackoff.backoff();
    Sleeper sleeper = Sleeper.DEFAULT;
    DescribeStreamSummaryRequest request = DescribeStreamSummaryRequest.builder().streamName(streamName).build();
    while (true) {
        try {
            return kinesis.describeStreamSummary(request).streamDescriptionSummary();
        } catch (LimitExceededException exc) {
            if (!BackOffUtils.next(sleeper, backoff)) {
                throw exc;
            }
        }
    }
}
Also used : FluentBackoff(org.apache.beam.sdk.util.FluentBackoff) DescribeStreamSummaryRequest(software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest) LimitExceededException(software.amazon.awssdk.services.kinesis.model.LimitExceededException) Sleeper(org.apache.beam.sdk.util.Sleeper) BackOff(org.apache.beam.sdk.util.BackOff)

Aggregations

DescribeStreamSummaryRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest)4 Test (org.junit.Test)3 Instant (org.joda.time.Instant)2 Shard (software.amazon.awssdk.services.kinesis.model.Shard)2 ShardFilter (software.amazon.awssdk.services.kinesis.model.ShardFilter)2 BackOff (org.apache.beam.sdk.util.BackOff)1 FluentBackoff (org.apache.beam.sdk.util.FluentBackoff)1 Sleeper (org.apache.beam.sdk.util.Sleeper)1 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)1 Datapoint (software.amazon.awssdk.services.cloudwatch.model.Datapoint)1 KinesisAsyncClient (software.amazon.awssdk.services.kinesis.KinesisAsyncClient)1 DescribeStreamSummaryResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse)1 LimitExceededException (software.amazon.awssdk.services.kinesis.model.LimitExceededException)1