Search in sources :

Example 6 with ListShardsResult

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

the class AmazonKinesisMock method listShards.

@Override
public ListShardsResult listShards(ListShardsRequest listShardsRequest) {
    if (expectedListShardsLimitExceededException) {
        throw new LimitExceededException("ListShards rate limit exceeded");
    }
    ListShardsResult result = new ListShardsResult();
    List<Shard> shards = IntStream.range(0, shardedData.size()).boxed().map(i -> new Shard().withShardId(Integer.toString(i))).collect(Collectors.toList());
    result.setShards(shards);
    HttpResponse response = new HttpResponse(null, null);
    response.setStatusCode(200);
    result.setSdkHttpMetadata(SdkHttpMetadata.from(response));
    return result;
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) Shard(com.amazonaws.services.kinesis.model.Shard) AddTagsToStreamResult(com.amazonaws.services.kinesis.model.AddTagsToStreamResult) MergeShardsResult(com.amazonaws.services.kinesis.model.MergeShardsResult) PutRecordsRequest(com.amazonaws.services.kinesis.model.PutRecordsRequest) PutRecordRequest(com.amazonaws.services.kinesis.model.PutRecordRequest) ListTagsForStreamRequest(com.amazonaws.services.kinesis.model.ListTagsForStreamRequest) KinesisProducerConfiguration(com.amazonaws.services.kinesis.producer.KinesisProducerConfiguration) ByteBuffer(java.nio.ByteBuffer) SplitShardRequest(com.amazonaws.services.kinesis.model.SplitShardRequest) GetShardIteratorRequest(com.amazonaws.services.kinesis.model.GetShardIteratorRequest) UpdateShardCountResult(com.amazonaws.services.kinesis.model.UpdateShardCountResult) GetShardIteratorResult(com.amazonaws.services.kinesis.model.GetShardIteratorResult) PutRecordsResult(com.amazonaws.services.kinesis.model.PutRecordsResult) HashCodeBuilder.reflectionHashCode(org.apache.commons.lang.builder.HashCodeBuilder.reflectionHashCode) DescribeStreamResult(com.amazonaws.services.kinesis.model.DescribeStreamResult) ListStreamConsumersRequest(com.amazonaws.services.kinesis.model.ListStreamConsumersRequest) RemoveTagsFromStreamResult(com.amazonaws.services.kinesis.model.RemoveTagsFromStreamResult) UpdateStreamModeRequest(com.amazonaws.services.kinesis.model.UpdateStreamModeRequest) ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) GetRecordsResult(com.amazonaws.services.kinesis.model.GetRecordsResult) StartStreamEncryptionResult(com.amazonaws.services.kinesis.model.StartStreamEncryptionResult) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) ShardIteratorType(com.amazonaws.services.kinesis.model.ShardIteratorType) HttpResponse(com.amazonaws.http.HttpResponse) ListStreamsResult(com.amazonaws.services.kinesis.model.ListStreamsResult) AmazonKinesisWaiters(com.amazonaws.services.kinesis.waiters.AmazonKinesisWaiters) Math.min(java.lang.Math.min) SdkHttpMetadata(com.amazonaws.http.SdkHttpMetadata) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Serializable(java.io.Serializable) DescribeStreamConsumerResult(com.amazonaws.services.kinesis.model.DescribeStreamConsumerResult) DecreaseStreamRetentionPeriodResult(com.amazonaws.services.kinesis.model.DecreaseStreamRetentionPeriodResult) List(java.util.List) LimitExceededException(com.amazonaws.services.kinesis.model.LimitExceededException) UpdateShardCountRequest(com.amazonaws.services.kinesis.model.UpdateShardCountRequest) IntStream(java.util.stream.IntStream) ListStreamConsumersResult(com.amazonaws.services.kinesis.model.ListStreamConsumersResult) ListStreamsRequest(com.amazonaws.services.kinesis.model.ListStreamsRequest) DescribeStreamSummaryResult(com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult) Record(com.amazonaws.services.kinesis.model.Record) AddTagsToStreamRequest(com.amazonaws.services.kinesis.model.AddTagsToStreamRequest) EnableEnhancedMonitoringRequest(com.amazonaws.services.kinesis.model.EnableEnhancedMonitoringRequest) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) DisableEnhancedMonitoringRequest(com.amazonaws.services.kinesis.model.DisableEnhancedMonitoringRequest) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) StartStreamEncryptionRequest(com.amazonaws.services.kinesis.model.StartStreamEncryptionRequest) Splitter(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.base.Splitter) EnableEnhancedMonitoringResult(com.amazonaws.services.kinesis.model.EnableEnhancedMonitoringResult) DescribeStreamRequest(com.amazonaws.services.kinesis.model.DescribeStreamRequest) StopStreamEncryptionResult(com.amazonaws.services.kinesis.model.StopStreamEncryptionResult) IKinesisProducer(com.amazonaws.services.kinesis.producer.IKinesisProducer) CreateStreamRequest(com.amazonaws.services.kinesis.model.CreateStreamRequest) DescribeLimitsRequest(com.amazonaws.services.kinesis.model.DescribeLimitsRequest) DeregisterStreamConsumerRequest(com.amazonaws.services.kinesis.model.DeregisterStreamConsumerRequest) CreateStreamResult(com.amazonaws.services.kinesis.model.CreateStreamResult) RemoveTagsFromStreamRequest(com.amazonaws.services.kinesis.model.RemoveTagsFromStreamRequest) StopStreamEncryptionRequest(com.amazonaws.services.kinesis.model.StopStreamEncryptionRequest) Nullable(org.checkerframework.checker.nullness.qual.Nullable) ListTagsForStreamResult(com.amazonaws.services.kinesis.model.ListTagsForStreamResult) AmazonWebServiceRequest(com.amazonaws.AmazonWebServiceRequest) DecreaseStreamRetentionPeriodRequest(com.amazonaws.services.kinesis.model.DecreaseStreamRetentionPeriodRequest) ResponseMetadata(com.amazonaws.ResponseMetadata) DescribeStreamSummaryRequest(com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest) PutRecordResult(com.amazonaws.services.kinesis.model.PutRecordResult) UpdateStreamModeResult(com.amazonaws.services.kinesis.model.UpdateStreamModeResult) DeleteStreamResult(com.amazonaws.services.kinesis.model.DeleteStreamResult) IncreaseStreamRetentionPeriodRequest(com.amazonaws.services.kinesis.model.IncreaseStreamRetentionPeriodRequest) MergeShardsRequest(com.amazonaws.services.kinesis.model.MergeShardsRequest) DescribeStreamConsumerRequest(com.amazonaws.services.kinesis.model.DescribeStreamConsumerRequest) Integer.parseInt(java.lang.Integer.parseInt) DeregisterStreamConsumerResult(com.amazonaws.services.kinesis.model.DeregisterStreamConsumerResult) RegisterStreamConsumerResult(com.amazonaws.services.kinesis.model.RegisterStreamConsumerResult) IncreaseStreamRetentionPeriodResult(com.amazonaws.services.kinesis.model.IncreaseStreamRetentionPeriodResult) Mockito(org.mockito.Mockito) Lists.transform(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.Lists.transform) EqualsBuilder(org.apache.commons.lang.builder.EqualsBuilder) Instant(org.joda.time.Instant) GetRecordsRequest(com.amazonaws.services.kinesis.model.GetRecordsRequest) DeleteStreamRequest(com.amazonaws.services.kinesis.model.DeleteStreamRequest) SplitShardResult(com.amazonaws.services.kinesis.model.SplitShardResult) Region(com.amazonaws.regions.Region) DescribeLimitsResult(com.amazonaws.services.kinesis.model.DescribeLimitsResult) DisableEnhancedMonitoringResult(com.amazonaws.services.kinesis.model.DisableEnhancedMonitoringResult) RegisterStreamConsumerRequest(com.amazonaws.services.kinesis.model.RegisterStreamConsumerRequest) HttpResponse(com.amazonaws.http.HttpResponse) LimitExceededException(com.amazonaws.services.kinesis.model.LimitExceededException) Shard(com.amazonaws.services.kinesis.model.Shard)

Example 7 with ListShardsResult

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

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampWithRetriedDescribeStreamSummaryCallAfterStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampWithRetriedDescribeStreamSummaryCallAfterStreamCreationTimestamp() throws TransientKinesisException {
    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))).thenThrow(new LimitExceededException("Fake Exception: Limit exceeded")).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) LimitExceededException(com.amazonaws.services.kinesis.model.LimitExceededException) 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 8 with ListShardsResult

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

the class SimplifiedKinesisClient method listShards.

private List<Shard> listShards(final String streamName, final ShardFilter shardFilter) throws TransientKinesisException {
    return wrapExceptions(() -> {
        ImmutableList.Builder<Shard> shardsBuilder = ImmutableList.builder();
        String currentNextToken = null;
        do {
            ListShardsRequest request = new ListShardsRequest();
            request.setMaxResults(LIST_SHARDS_MAX_RESULTS);
            if (currentNextToken != null) {
                request.setNextToken(currentNextToken);
            } else {
                request.setStreamName(streamName);
            }
            request.setShardFilter(shardFilter);
            ListShardsResult response = kinesis.listShards(request);
            List<Shard> shards = response.getShards();
            shardsBuilder.addAll(shards);
            currentNextToken = response.getNextToken();
        } while (currentNextToken != null);
        return shardsBuilder.build();
    });
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ImmutableList(org.apache.beam.vendor.guava.v26_0_jre.com.google.common.collect.ImmutableList) Shard(com.amazonaws.services.kinesis.model.Shard)

Example 9 with ListShardsResult

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

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampOutsideStreamRetentionAfterStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampOutsideStreamRetentionAfterStreamCreationTimestamp() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    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 = new DescribeStreamSummaryRequest().withStreamName(STREAM);
    when(kinesis.describeStreamSummary(describeStreamRequest)).thenReturn(new DescribeStreamSummaryResult().withStreamDescriptionSummary(new StreamDescriptionSummary().withRetentionPeriodHours(retentionPeriodHours).withStreamCreationTimestamp(streamCreationTimestamp.toDate())));
    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(startingPointTimestampAfterStreamRetentionTimestamp));
    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 10 with ListShardsResult

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

the class SimplifiedKinesisClientTest method shouldListAllShardsForTimestampBeforeStreamCreationTimestamp.

@Test
public void shouldListAllShardsForTimestampBeforeStreamCreationTimestamp() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    Instant startingPointTimestamp = Instant.parse("2000-01-01T15:00:00.000Z");
    Instant streamCreationTimestamp = startingPointTimestamp.plus(Duration.standardHours(1));
    DescribeStreamSummaryRequest describeStreamRequest = new DescribeStreamSummaryRequest().withStreamName(STREAM);
    when(kinesis.describeStreamSummary(describeStreamRequest)).thenReturn(new DescribeStreamSummaryResult().withStreamDescriptionSummary(new StreamDescriptionSummary().withStreamCreationTimestamp(streamCreationTimestamp.toDate())));
    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(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) 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