Search in sources :

Example 21 with SdkAsyncHttpClient

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;
}
Also used : MethodSorters(org.junit.runners.MethodSorters) AWSXRay(com.amazonaws.xray.AWSXRay) Subsegment(com.amazonaws.xray.entities.Subsegment) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) AwsSessionCredentials(software.amazon.awssdk.auth.credentials.AwsSessionCredentials) StaticCredentialsProvider(software.amazon.awssdk.auth.credentials.StaticCredentialsProvider) Segment(com.amazonaws.xray.entities.Segment) Context(software.amazon.awssdk.core.interceptor.Context) LambdaClient(software.amazon.awssdk.services.lambda.LambdaClient) Answer(org.mockito.stubbing.Answer) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) ByteArrayInputStream(java.io.ByteArrayInputStream) Map(java.util.Map) After(org.junit.After) ExecutionAttributes(software.amazon.awssdk.core.interceptor.ExecutionAttributes) URI(java.net.URI) Emitter(com.amazonaws.xray.emitters.Emitter) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) Region(software.amazon.awssdk.regions.Region) Before(org.junit.Before) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) EmptyPublisher(software.amazon.awssdk.core.async.EmptyPublisher) SdkHttpRequest(software.amazon.awssdk.http.SdkHttpRequest) Test(org.junit.Test) LambdaAsyncClient(software.amazon.awssdk.services.lambda.LambdaAsyncClient) Mockito.when(org.mockito.Mockito.when) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) ExecutableHttpRequest(software.amazon.awssdk.http.ExecutableHttpRequest) AWSXRayRecorderBuilder(com.amazonaws.xray.AWSXRayRecorderBuilder) StandardCharsets(java.nio.charset.StandardCharsets) Mockito.verify(org.mockito.Mockito.verify) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) Mockito(org.mockito.Mockito) AbortableInputStream(software.amazon.awssdk.http.AbortableInputStream) Mockito.never(org.mockito.Mockito.never) MockitoJUnitRunner(org.mockito.runners.MockitoJUnitRunner) InvokeRequest(software.amazon.awssdk.services.lambda.model.InvokeRequest) HttpExecuteResponse(software.amazon.awssdk.http.HttpExecuteResponse) Assert(org.junit.Assert) FixMethodOrder(org.junit.FixMethodOrder) Cause(com.amazonaws.xray.entities.Cause) ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AsyncExecuteRequest(software.amazon.awssdk.http.async.AsyncExecuteRequest) CompletableFuture(java.util.concurrent.CompletableFuture) SdkAsyncHttpResponseHandler(software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler) EmptyPublisher(software.amazon.awssdk.core.async.EmptyPublisher) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient)

Example 22 with SdkAsyncHttpClient

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());
    }
}
Also used : Cause(com.amazonaws.xray.entities.Cause) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Subsegment(com.amazonaws.xray.entities.Subsegment) Map(java.util.Map) LambdaAsyncClient(software.amazon.awssdk.services.lambda.LambdaAsyncClient) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 23 with SdkAsyncHttpClient

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);
}
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 24 with SdkAsyncHttpClient

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();
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Example 25 with SdkAsyncHttpClient

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());
}
Also used : NettyNioAsyncHttpClient(software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient) NettyConfiguration(software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Test(org.junit.Test)

Aggregations

SdkAsyncHttpClient (software.amazon.awssdk.http.async.SdkAsyncHttpClient)39 Test (org.junit.Test)37 NettyConfiguration (software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration)29 NettyNioAsyncHttpClient (software.amazon.awssdk.http.nio.netty.NettyNioAsyncHttpClient)25 AttributeMap (software.amazon.awssdk.utils.AttributeMap)11 Properties (java.util.Properties)8 Duration (java.time.Duration)6 Segment (com.amazonaws.xray.entities.Segment)5 Subsegment (com.amazonaws.xray.entities.Subsegment)5 Map (java.util.Map)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 LambdaAsyncClient (software.amazon.awssdk.services.lambda.LambdaAsyncClient)5 Cause (com.amazonaws.xray.entities.Cause)4 ClientOverrideConfiguration (software.amazon.awssdk.core.client.config.ClientOverrideConfiguration)3 KinesisAsyncClient (software.amazon.awssdk.services.kinesis.KinesisAsyncClient)3 URI (java.net.URI)2 Mockito.never (org.mockito.Mockito.never)2 Mockito.verify (org.mockito.Mockito.verify)2 Mockito.when (org.mockito.Mockito.when)2 AWSXRay (com.amazonaws.xray.AWSXRay)1