Search in sources :

Example 16 with ListShardsRequest

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

the class KinesisTestHelper method listOpenShards.

private List<Shard> listOpenShards() {
    List<Shard> shards = new ArrayList<>();
    String nextToken = null;
    do {
        // only the currently open shards
        ShardFilterType filterType = ShardFilterType.AT_LATEST;
        ListShardsRequest request = RangeMonitor.listAllShardsRequest(stream, nextToken, filterType);
        ListShardsResult response = kinesis.listShards(request);
        shards.addAll(response.getShards());
        nextToken = response.getNextToken();
    } while (nextToken != null);
    return shards;
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) ShardFilterType(com.amazonaws.services.kinesis.model.ShardFilterType) ArrayList(java.util.ArrayList) Shard(com.amazonaws.services.kinesis.model.Shard)

Example 17 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest 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());
}
Also used : ListShardsResult(com.amazonaws.services.kinesis.model.ListShardsResult) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) HashMap(java.util.HashMap) AmazonKinesis(com.amazonaws.services.kinesis.AmazonKinesis) Test(org.junit.Test)

Example 18 with ListShardsRequest

use of com.amazonaws.services.kinesis.model.ListShardsRequest in project druid by druid-io.

the class KinesisRecordSupplierTest method testSupplierSetup.

@Test
public void testSupplierSetup() {
    final Capture<ListShardsRequest> capturedRequest0 = Capture.newInstance();
    final Capture<ListShardsRequest> capturedRequest1 = Capture.newInstance();
    EasyMock.expect(kinesis.listShards(EasyMock.capture(capturedRequest0))).andReturn(listShardsResult0).once();
    EasyMock.expect(listShardsResult0.getShards()).andReturn(ImmutableList.of(shard0)).once();
    String nextToken = "nextToken";
    EasyMock.expect(listShardsResult0.getNextToken()).andReturn(nextToken).once();
    EasyMock.expect(shard0.getShardId()).andReturn(SHARD_ID0).once();
    EasyMock.expect(kinesis.listShards(EasyMock.capture(capturedRequest1))).andReturn(listShardsResult1).once();
    EasyMock.expect(listShardsResult1.getShards()).andReturn(ImmutableList.of(shard1)).once();
    EasyMock.expect(listShardsResult1.getNextToken()).andReturn(null).once();
    EasyMock.expect(shard1.getShardId()).andReturn(SHARD_ID1).once();
    replayAll();
    Set<StreamPartition<String>> partitions = ImmutableSet.of(StreamPartition.of(STREAM, SHARD_ID0), StreamPartition.of(STREAM, SHARD_ID1));
    recordSupplier = new KinesisRecordSupplier(kinesis, recordsPerFetch, 0, 2, false, 100, 5000, 5000, 60000, 5, true);
    Assert.assertTrue(recordSupplier.getAssignment().isEmpty());
    recordSupplier.assign(partitions);
    Assert.assertEquals(partitions, recordSupplier.getAssignment());
    Assert.assertEquals(ImmutableSet.of(SHARD_ID1, SHARD_ID0), recordSupplier.getPartitionIds(STREAM));
    // calling poll would start background fetch if seek was called, but will instead be skipped and the results
    // empty
    Assert.assertEquals(Collections.emptyList(), recordSupplier.poll(100));
    verifyAll();
    final ListShardsRequest expectedRequest0 = new ListShardsRequest();
    expectedRequest0.setStreamName(STREAM);
    Assert.assertEquals(expectedRequest0, capturedRequest0.getValue());
    final ListShardsRequest expectedRequest1 = new ListShardsRequest();
    expectedRequest1.setNextToken(nextToken);
    Assert.assertEquals(expectedRequest1, capturedRequest1.getValue());
}
Also used : StreamPartition(org.apache.druid.indexing.seekablestream.common.StreamPartition) ListShardsRequest(com.amazonaws.services.kinesis.model.ListShardsRequest) Test(org.junit.Test)

Aggregations

ListShardsRequest (com.amazonaws.services.kinesis.model.ListShardsRequest)18 ListShardsResult (com.amazonaws.services.kinesis.model.ListShardsResult)15 Shard (com.amazonaws.services.kinesis.model.Shard)14 Test (org.junit.Test)10 ShardFilter (com.amazonaws.services.kinesis.model.ShardFilter)9 DescribeStreamSummaryRequest (com.amazonaws.services.kinesis.model.DescribeStreamSummaryRequest)5 DescribeStreamSummaryResult (com.amazonaws.services.kinesis.model.DescribeStreamSummaryResult)5 Instant (org.joda.time.Instant)5 StreamDescriptionSummary (com.amazonaws.services.kinesis.model.StreamDescriptionSummary)4 Datapoint (com.amazonaws.services.cloudwatch.model.Datapoint)3 LimitExceededException (com.amazonaws.services.kinesis.model.LimitExceededException)3 AmazonKinesis (com.amazonaws.services.kinesis.AmazonKinesis)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 AmazonWebServiceRequest (com.amazonaws.AmazonWebServiceRequest)1 ResponseMetadata (com.amazonaws.ResponseMetadata)1 SdkClientException (com.amazonaws.SdkClientException)1 HttpResponse (com.amazonaws.http.HttpResponse)1 SdkHttpMetadata (com.amazonaws.http.SdkHttpMetadata)1 Region (com.amazonaws.regions.Region)1 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1