Search in sources :

Example 16 with SdkAsyncHttpClient

use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project flink by apache.

the class AWSAsyncSinkUtilTest method testCreateKinesisAsyncClientWithEndpointOverride.

@Test
public void testCreateKinesisAsyncClientWithEndpointOverride() {
    Properties properties = TestUtil.properties(AWS_REGION, "eu-west-2");
    properties.setProperty(AWS_ENDPOINT, "https://localhost");
    MockAsyncClientBuilder builder = mockKinesisAsyncClientBuilder();
    ClientOverrideConfiguration clientOverrideConfiguration = ClientOverrideConfiguration.builder().build();
    SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().build();
    AWSAsyncSinkUtil.createAwsAsyncClient(properties, builder, httpClient, clientOverrideConfiguration);
    verify(builder).endpointOverride(URI.create("https://localhost"));
}
Also used : ClientOverrideConfiguration(software.amazon.awssdk.core.client.config.ClientOverrideConfiguration) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient) Properties(java.util.Properties) Test(org.junit.Test)

Example 17 with SdkAsyncHttpClient

use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method testAsync500Exception.

@Test
public void testAsync500Exception() {
    SdkAsyncHttpClient mockClient = mockSdkAsyncHttpClient(generateLambdaInvokeResponse(500));
    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(500, httpResponseStats.get("status"));
        Assert.assertEquals(false, subsegment.isError());
        Assert.assertEquals(false, subsegment.isThrottle());
        Assert.assertEquals(true, 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 18 with SdkAsyncHttpClient

use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method testAsync400Exception.

@Test
public void testAsync400Exception() {
    SdkAsyncHttpClient mockClient = mockSdkAsyncHttpClient(generateLambdaInvokeResponse(400));
    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(0, awsStats.get("retries"));
        Assert.assertEquals(2L, httpResponseStats.get("content_length"));
        Assert.assertEquals(400, httpResponseStats.get("status"));
        Assert.assertEquals(false, subsegment.isInProgress());
        Assert.assertEquals(true, subsegment.isError());
        Assert.assertEquals(false, 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 19 with SdkAsyncHttpClient

use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-doc-sdk-examples by awsdocs.

the class ClientConfiguration method main.

public static void main(String[] args) {
    // If configured with an httpClientBuilder, the SDK will manage the lifecycle of the HTTP client
    // and it will be shutdown when the client is shut down.
    // snippet-start:[kinesis.java2.client_configuration.client]
    KinesisAsyncClient client = KinesisAsyncClient.builder().httpClientBuilder(NettyNioAsyncHttpClient.builder().maxConcurrency(100).maxPendingConnectionAcquires(10_000)).build();
    // snippet-end:[kinesis.java2.client_configuration.client]
    // When passing in the httpClient directly, the lifecycle must be managed by the caller and the HTTP client
    // will not be shut down when the client is shut down.
    // snippet-start:[kinesis.java2.client_configuration.httpclient]
    SdkAsyncHttpClient httpClient = NettyNioAsyncHttpClient.builder().maxConcurrency(100).maxPendingConnectionAcquires(10_000).build();
    KinesisAsyncClient kinesisClient = KinesisAsyncClient.builder().httpClient(httpClient).build();
    httpClient.close();
// snippet-end:[kinesis.java2.client_configuration.httpclient]
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) SdkAsyncHttpClient(software.amazon.awssdk.http.async.SdkAsyncHttpClient)

Example 20 with SdkAsyncHttpClient

use of software.amazon.awssdk.http.async.SdkAsyncHttpClient in project aws-xray-sdk-java by aws.

the class TracingInterceptorTest method testAsyncLambdaInvokeSubsegmentContainsFunctionName.

@Test
public void testAsyncLambdaInvokeSubsegmentContainsFunctionName() {
    SdkAsyncHttpClient mockClient = mockSdkAsyncHttpClient(generateLambdaInvokeResponse(200));
    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();
    client.invoke(InvokeRequest.builder().functionName("testFunctionName").build()).join();
    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");
    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("Failure", awsStats.get("function_error"));
    Assert.assertEquals("us-west-42", awsStats.get("region"));
    Assert.assertEquals(0, awsStats.get("retries"));
    Assert.assertEquals(2L, httpResponseStats.get("content_length"));
    Assert.assertEquals(200, httpResponseStats.get("status"));
    Assert.assertEquals(false, subsegment.isInProgress());
}
Also used : 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)

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