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);
}
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;
}
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);
}
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);
}
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);
}
}
Aggregations