Search in sources :

Example 11 with KinesisAsyncClient

use of software.amazon.awssdk.services.kinesis.KinesisAsyncClient in project flink by apache.

the class KinesisProxyV2Factory method createKinesisProxyV2.

/**
 * Uses the given properties to instantiate a new instance of {@link KinesisProxyV2}.
 *
 * @param configProps the properties used to parse configuration
 * @return the Kinesis proxy
 */
public static KinesisProxyV2Interface createKinesisProxyV2(final Properties configProps) {
    Preconditions.checkNotNull(configProps);
    final AttributeMap convertedProperties = AwsV2Util.convertProperties(configProps);
    final AttributeMap.Builder clientConfiguration = AttributeMap.builder();
    populateDefaultValues(clientConfiguration);
    final SdkAsyncHttpClient httpClient = AWSGeneralUtil.createAsyncHttpClient(convertedProperties.merge(clientConfiguration.build()), NettyNioAsyncHttpClient.builder());
    final FanOutRecordPublisherConfiguration configuration = new FanOutRecordPublisherConfiguration(configProps, emptyList());
    Properties legacyConfigProps = new Properties(configProps);
    legacyConfigProps.setProperty(KinesisDataStreamsConfigConstants.KINESIS_CLIENT_USER_AGENT_PREFIX, AWSAsyncSinkUtil.formatFlinkUserAgentPrefix(KinesisDataStreamsConfigConstants.BASE_KINESIS_USER_AGENT_PREFIX_FORMAT));
    final KinesisAsyncClient client = AWSAsyncSinkUtil.createAwsAsyncClient(legacyConfigProps, httpClient, KinesisAsyncClient.builder(), KinesisDataStreamsConfigConstants.BASE_KINESIS_USER_AGENT_PREFIX_FORMAT, KinesisDataStreamsConfigConstants.KINESIS_CLIENT_USER_AGENT_PREFIX);
    return new KinesisProxyV2(client, httpClient, configuration, BACKOFF);
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) AttributeMap(software.amazon.awssdk.utils.AttributeMap) FanOutRecordPublisherConfiguration(org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Properties(java.util.Properties)

Example 12 with KinesisAsyncClient

use of software.amazon.awssdk.services.kinesis.KinesisAsyncClient in project flink by apache.

the class KinesisProxyV2Test method testDescribeStreamConsumerBackoffJitter.

@Test
public void testDescribeStreamConsumerBackoffJitter() throws Exception {
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    KinesisAsyncClient client = mock(KinesisAsyncClient.class);
    KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), backoff);
    when(client.describeStreamConsumer(any(DescribeStreamConsumerRequest.class))).thenThrow(new RuntimeException(LimitExceededException.builder().build())).thenReturn(CompletableFuture.completedFuture(DescribeStreamConsumerResponse.builder().build()));
    proxy.describeStreamConsumer("arn");
    verify(backoff).sleep(anyLong());
    verify(backoff).calculateFullJitterBackoff(EXPECTED_DESCRIBE_CONSUMER_BASE, EXPECTED_DESCRIBE_CONSUMER_MAX, EXPECTED_DESCRIBE_CONSUMER_POW, 1);
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Example 13 with KinesisAsyncClient

use of software.amazon.awssdk.services.kinesis.KinesisAsyncClient in project flink by apache.

the class KinesisProxyV2Test method testRegisterStreamConsumer.

@Test
public void testRegisterStreamConsumer() throws Exception {
    KinesisAsyncClient client = mock(KinesisAsyncClient.class);
    KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), mock(FullJitterBackoff.class));
    RegisterStreamConsumerResponse expected = RegisterStreamConsumerResponse.builder().build();
    ArgumentCaptor<RegisterStreamConsumerRequest> requestCaptor = ArgumentCaptor.forClass(RegisterStreamConsumerRequest.class);
    when(client.registerStreamConsumer(requestCaptor.capture())).thenReturn(CompletableFuture.completedFuture(expected));
    RegisterStreamConsumerResponse actual = proxy.registerStreamConsumer("arn", "name");
    assertEquals(expected, actual);
    RegisterStreamConsumerRequest request = requestCaptor.getValue();
    assertEquals("arn", request.streamARN());
    assertEquals("name", request.consumerName());
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) RegisterStreamConsumerRequest(software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerRequest) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) RegisterStreamConsumerResponse(software.amazon.awssdk.services.kinesis.model.RegisterStreamConsumerResponse) Test(org.junit.Test)

Example 14 with KinesisAsyncClient

use of software.amazon.awssdk.services.kinesis.KinesisAsyncClient in project flink by apache.

the class KinesisProxyV2Test method testDeregisterStreamConsumerBackoffJitter.

@Test
public void testDeregisterStreamConsumerBackoffJitter() throws Exception {
    FullJitterBackoff backoff = mock(FullJitterBackoff.class);
    KinesisAsyncClient client = mock(KinesisAsyncClient.class);
    KinesisProxyV2 proxy = new KinesisProxyV2(client, mock(SdkAsyncHttpClient.class), createConfiguration(), backoff);
    when(client.deregisterStreamConsumer(any(DeregisterStreamConsumerRequest.class))).thenThrow(new RuntimeException(LimitExceededException.builder().build())).thenReturn(CompletableFuture.completedFuture(DeregisterStreamConsumerResponse.builder().build()));
    proxy.deregisterStreamConsumer("arn");
    verify(backoff).sleep(anyLong());
    verify(backoff).calculateFullJitterBackoff(EXPECTED_DEREGISTRATION_BASE, EXPECTED_DEREGISTRATION_MAX, EXPECTED_DEREGISTRATION_POW, 1);
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Example 15 with KinesisAsyncClient

use of software.amazon.awssdk.services.kinesis.KinesisAsyncClient in project flink by apache.

the class KinesisProxyV2Test method testCloseInvokesClientClose.

@Test
public void testCloseInvokesClientClose() {
    SdkAsyncHttpClient httpClient = mock(SdkAsyncHttpClient.class);
    KinesisAsyncClient kinesis = mock(KinesisAsyncClient.class);
    KinesisProxyV2 proxy = new KinesisProxyV2(kinesis, httpClient, createConfiguration(), mock(FullJitterBackoff.class));
    proxy.close();
    verify(kinesis).close();
    verify(httpClient).close();
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Aggregations

KinesisAsyncClient (software.amazon.awssdk.services.kinesis.KinesisAsyncClient)18 SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)14 Test (org.junit.Test)12 SubscribeToShardRequest (software.amazon.awssdk.services.kinesis.model.SubscribeToShardRequest)4 CompletableFuture (java.util.concurrent.CompletableFuture)3 DescribeStreamConsumerRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerRequest)3 DescribeStreamConsumerResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamConsumerResponse)3 DescribeStreamSummaryRequest (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryRequest)3 Properties (java.util.Properties)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 FanOutRecordPublisherConfiguration (org.apache.flink.streaming.connectors.kinesis.internals.publisher.fanout.FanOutRecordPublisherConfiguration)2 Subscriber (org.reactivestreams.Subscriber)2 Subscription (org.reactivestreams.Subscription)2 SdkPublisher (software.amazon.awssdk.core.async.SdkPublisher)2 Region (software.amazon.awssdk.regions.Region)2 DescribeStreamSummaryResponse (software.amazon.awssdk.services.kinesis.model.DescribeStreamSummaryResponse)2 ShardIteratorType (software.amazon.awssdk.services.kinesis.model.ShardIteratorType)2 SubscribeToShardEvent (software.amazon.awssdk.services.kinesis.model.SubscribeToShardEvent)2 SubscribeToShardEventStream (software.amazon.awssdk.services.kinesis.model.SubscribeToShardEventStream)2 SubscribeToShardResponse (software.amazon.awssdk.services.kinesis.model.SubscribeToShardResponse)2