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