Search in sources :

Example 6 with ShardFilter

use of com.amazonaws.services.kinesis.model.ShardFilter 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 7 with ShardFilter

use of com.amazonaws.services.kinesis.model.ShardFilter in project hazelcast by hazelcast.

the class RangeMonitor method listAllShardsRequest.

public static ListShardsRequest listAllShardsRequest(String stream, @Nullable String nextToken, ShardFilterType filterType) {
    ListShardsRequest request = new ListShardsRequest();
    if (nextToken == null) {
        request.setStreamName(stream);
    } else {
        request.setNextToken(nextToken);
    }
    // include all the shards within the retention period of the data stream
    request.setShardFilter(new ShardFilter().withType(filterType));
    return request;
}
Also used : ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter)

Example 8 with ShardFilter

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

the class SimplifiedKinesisClientTest method shouldListAllShardsForExclusiveStartShardId.

@Test
public void shouldListAllShardsForExclusiveStartShardId() throws Exception {
    Shard shard1 = new Shard().withShardId(SHARD_1);
    Shard shard2 = new Shard().withShardId(SHARD_2);
    Shard shard3 = new Shard().withShardId(SHARD_3);
    String exclusiveStartShardId = "exclusiveStartShardId";
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withMaxResults(1_000).withShardFilter(new ShardFilter().withType(ShardFilterType.AFTER_SHARD_ID).withShardId(exclusiveStartShardId)))).thenReturn(new ListShardsResult().withShards(shard1, shard2, shard3).withNextToken(null));
    List<Shard> shards = underTest.listShardsFollowingClosedShard(STREAM, exclusiveStartShardId);
    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 9 with ShardFilter

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

the class SimplifiedKinesisClientTest method shouldListAllShardsForTrimHorizonWithPagedResults.

@Test
public void shouldListAllShardsForTrimHorizonWithPagedResults() 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);
    String nextListShardsToken = "testNextToken";
    when(kinesis.listShards(new ListShardsRequest().withStreamName(STREAM).withShardFilter(shardFilter).withMaxResults(1_000))).thenReturn(new ListShardsResult().withShards(shard1, shard2).withNextToken(nextListShardsToken));
    when(kinesis.listShards(new ListShardsRequest().withMaxResults(1_000).withShardFilter(shardFilter).withNextToken(nextListShardsToken))).thenReturn(new ListShardsResult().withShards(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 10 with ShardFilter

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

the class SimplifiedKinesisClient method buildShardFilterForTimestamp.

private ShardFilter buildShardFilterForTimestamp(String streamName, Instant startingPointTimestamp) throws IOException, InterruptedException {
    StreamDescriptionSummary streamDescription = describeStreamSummary(streamName);
    Instant streamCreationTimestamp = new Instant(streamDescription.getStreamCreationTimestamp());
    if (streamCreationTimestamp.isAfter(startingPointTimestamp)) {
        return new ShardFilter().withType(ShardFilterType.AT_TRIM_HORIZON);
    }
    Duration retentionPeriod = Duration.standardHours(streamDescription.getRetentionPeriodHours());
    Instant streamTrimHorizonTimestamp = currentInstantSupplier.get().minus(retentionPeriod).plus(SPACING_FOR_TIMESTAMP_LIST_SHARDS_REQUEST_TO_NOT_EXCEED_TRIM_HORIZON);
    if (startingPointTimestamp.isAfter(streamTrimHorizonTimestamp)) {
        return new ShardFilter().withType(ShardFilterType.AT_TIMESTAMP).withTimestamp(startingPointTimestamp.toDate());
    } else {
        return new ShardFilter().withType(ShardFilterType.AT_TRIM_HORIZON);
    }
}
Also used : StreamDescriptionSummary(com.amazonaws.services.kinesis.model.StreamDescriptionSummary) Instant(org.joda.time.Instant) ShardFilter(com.amazonaws.services.kinesis.model.ShardFilter) Duration(org.joda.time.Duration)

Aggregations

ShardFilter (com.amazonaws.services.kinesis.model.ShardFilter)10 ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)9 ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)8 Shard (com.amazonaws.services.kinesis.model.Shard)8 Test (org.junit.Test)8 StreamDescriptionSummary (com.amazonaws.services.kinesis.model.StreamDescriptionSummary)5 Instant (org.joda.time.Instant)5 DescribeStreamSummaryRequest (com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest)4 DescribeStreamSummaryResult (com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult)4 Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)3 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)1 Duration (org.joda.time.Duration)1