use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-xray-sdk-java by aws.
the class TracingInterceptorTest method mockSdkAsyncHttpClient.
private SdkAsyncHttpClient mockSdkAsyncHttpClient(SdkHttpResponse response) {
SdkAsyncHttpClient mockClient = Mockito.mock(SdkAsyncHttpClient.class);
when(mockClient.execute(Mockito.any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
AsyncExecuteRequest request = invocationOnMock.getArgument(0);
SdkAsyncHttpResponseHandler handler = request.responseHandler();
handler.onHeaders(response);
handler.onStream(new EmptyPublisher<>());
return CompletableFuture.completedFuture(null);
});
return mockClient;
}
use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-xray-sdk-java by aws.
the class TracingInterceptorTest method testAsyncThrottledException.
@Test
public void testAsyncThrottledException() {
SdkAsyncHttpClient mockClient = mockSdkAsyncHttpClient(generateLambdaInvokeResponse(429));
LambdaAsyncClient client = LambdaAsyncClient.builder().httpClient(mockClient).endpointOverride(URI.create("http://example.com")).region(Region.of("us-west-42")).credentialsProvider(StaticCredentialsProvider.create(AwsSessionCredentials.create("key", "secret", "session"))).overrideConfiguration(ClientOverrideConfiguration.builder().addExecutionInterceptor(new TracingInterceptor()).build()).build();
Segment segment = AWSXRay.getCurrentSegment();
try {
client.invoke(InvokeRequest.builder().functionName("testFunctionName").build()).get();
} catch (Exception e) {
// ignore exceptions
} finally {
Assert.assertEquals(1, segment.getSubsegments().size());
Subsegment subsegment = segment.getSubsegments().get(0);
Map<String, Object> awsStats = subsegment.getAws();
@SuppressWarnings("unchecked") Map<String, Object> httpResponseStats = (Map<String, Object>) subsegment.getHttp().get("response");
Cause cause = subsegment.getCause();
Assert.assertEquals("Invoke", awsStats.get("operation"));
Assert.assertEquals("testFunctionName", awsStats.get("function_name"));
Assert.assertEquals("1111-2222-3333-4444", awsStats.get("request_id"));
Assert.assertEquals("extended", awsStats.get("id_2"));
Assert.assertEquals("us-west-42", awsStats.get("region"));
Assert.assertEquals(2L, httpResponseStats.get("content_length"));
Assert.assertEquals(429, httpResponseStats.get("status"));
Assert.assertEquals(true, subsegment.isError());
Assert.assertEquals(true, subsegment.isThrottle());
Assert.assertEquals(false, subsegment.isFault());
Assert.assertEquals(1, cause.getExceptions().size());
Assert.assertEquals(true, cause.getExceptions().get(0).isRemote());
}
}
use of software.amazon.awssdk.http.async.SdkAsyncHttpClient 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.http.async.SdkAsyncHttpClient 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();
}
use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project flink by apache.
the class AWSGeneralUtilTest method testCreateNettyAsyncHttpClientWithDefaultsTcpKeepAlive.
@Test
public void testCreateNettyAsyncHttpClientWithDefaultsTcpKeepAlive() throws Exception {
NettyNioAsyncHttpClient.Builder builder = NettyNioAsyncHttpClient.builder();
SdkAsyncHttpClient httpClient = AWSGeneralUtil.createAsyncHttpClient(builder);
NettyConfiguration nettyConfiguration = TestUtil.getNettyConfiguration(httpClient);
SdkAsyncHttpClient httpDefaultClient = NettyNioAsyncHttpClient.create();
NettyConfiguration nettyDefaultConfiguration = TestUtil.getNettyConfiguration(httpDefaultClient);
assertEquals(nettyDefaultConfiguration.tcpKeepAlive(), nettyConfiguration.tcpKeepAlive());
}
Aggregations