Search in sources :

Example 1 with ShardFilter

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

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

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

Example 4 with ShardFilter

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

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

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