use of com.amazonaws.services.kinesis.model.ListShardsResult 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);
}
use of com.amazonaws.services.kinesis.model.ListShardsResult 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);
}
use of com.amazonaws.services.kinesis.model.ListShardsResult 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.ListShardsResult in project flink by apache.
the class KinesisProxyTest method testGetShardWithNoNewShards.
@Test
public void testGetShardWithNoNewShards() throws Exception {
// given
String fakeStreamName = "fake-stream";
AmazonKinesis mockClient = mock(AmazonKinesis.class);
KinesisProxy kinesisProxy = getProxy(mockClient);
Mockito.when(mockClient.listShards(new ListShardsRequest().withStreamName(fakeStreamName).withExclusiveStartShardId(KinesisShardIdGenerator.generateFromShardOrder(1)))).thenReturn(new ListShardsResult().withShards(Collections.emptyList()));
HashMap<String, String> streamHashMap = new HashMap<>();
streamHashMap.put(fakeStreamName, KinesisShardIdGenerator.generateFromShardOrder(1));
// when
GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);
// then
Assert.assertFalse(shardListResult.hasRetrievedShards());
}
use of com.amazonaws.services.kinesis.model.ListShardsResult in project flink by apache.
the class KinesisProxyTest method testGetShardList.
@Test
public void testGetShardList() throws Exception {
List<String> shardIds = Arrays.asList("shardId-000000000000", "shardId-000000000001", "shardId-000000000002", "shardId-000000000003");
String nextToken = "NextToken";
String fakeStreamName = "fake-stream";
List<Shard> shards = shardIds.stream().map(shardId -> new Shard().withShardId(shardId)).collect(Collectors.toList());
AmazonKinesis mockClient = mock(AmazonKinesis.class);
KinesisProxy kinesisProxy = getProxy(mockClient);
ListShardsResult responseWithMoreData = new ListShardsResult().withShards(shards.subList(0, 2)).withNextToken(nextToken);
ListShardsResult responseFinal = new ListShardsResult().withShards(shards.subList(2, shards.size())).withNextToken(null);
doReturn(responseWithMoreData).when(mockClient).listShards(argThat(initialListShardsRequestMatcher()));
doReturn(responseFinal).when(mockClient).listShards(argThat(listShardsNextToken(nextToken)));
HashMap<String, String> streamHashMap = createInitialSubscribedStreamsToLastDiscoveredShardsState(Arrays.asList(fakeStreamName));
GetShardListResult shardListResult = kinesisProxy.getShardList(streamHashMap);
Assert.assertEquals(shardListResult.hasRetrievedShards(), true);
Set<String> expectedStreams = new HashSet<>();
expectedStreams.add(fakeStreamName);
Assert.assertEquals(shardListResult.getStreamsWithRetrievedShards(), expectedStreams);
List<StreamShardHandle> actualShardList = shardListResult.getRetrievedShardListOfStream(fakeStreamName);
List<StreamShardHandle> expectedStreamShard = new ArrayList<>();
assertThat(actualShardList, hasSize(4));
for (int i = 0; i < 4; i++) {
StreamShardHandle shardHandle = new StreamShardHandle(fakeStreamName, new Shard().withShardId(KinesisShardIdGenerator.generateFromShardOrder(i)));
expectedStreamShard.add(shardHandle);
}
Assert.assertThat(actualShardList, containsInAnyOrder(expectedStreamShard.toArray(new StreamShardHandle[actualShardList.size()])));
}
Aggregations