Search in sources :

Example 6 with SdkHttpClient

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

the class TracingInterceptorTest method testResponseDescriptors.

@Test
public void testResponseDescriptors() throws Exception {
    String responseBody = "{\"LastEvaluatedTableName\":\"baz\",\"TableNames\":[\"foo\",\"bar\",\"baz\"]}";
    SdkHttpResponse mockResponse = SdkHttpResponse.builder().statusCode(200).putHeader("x-amzn-requestid", "1111-2222-3333-4444").putHeader("Content-Length", "84").putHeader("Content-Type", "application/x-amz-json-1.0").build();
    SdkHttpClient mockClient = mockSdkHttpClient(mockResponse, responseBody);
    DynamoDbClient client = DynamoDbClient.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.listTables(ListTablesRequest.builder().limit(3).build());
    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("ListTables", awsStats.get("operation"));
    Assert.assertEquals(3, awsStats.get("limit"));
    Assert.assertEquals("1111-2222-3333-4444", awsStats.get("request_id"));
    Assert.assertEquals(3, awsStats.get("table_count"));
    Assert.assertEquals("us-west-42", awsStats.get("region"));
    Assert.assertEquals(0, awsStats.get("retries"));
    Assert.assertEquals(84L, httpResponseStats.get("content_length"));
    Assert.assertEquals(200, httpResponseStats.get("status"));
    Assert.assertEquals(false, subsegment.isInProgress());
}
Also used : DynamoDbClient(software.amazon.awssdk.services.dynamodb.DynamoDbClient) SdkHttpClient(software.amazon.awssdk.http.SdkHttpClient) SdkHttpResponse(software.amazon.awssdk.http.SdkHttpResponse) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Subsegment(com.amazonaws.xray.entities.Subsegment) Map(java.util.Map) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Aggregations

SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)6 Segment (com.amazonaws.xray.entities.Segment)5 Subsegment (com.amazonaws.xray.entities.Subsegment)5 Map (java.util.Map)5 Test (org.junit.Test)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 LambdaClient (software.amazon.awssdk.services.lambda.LambdaClient)4 Cause (com.amazonaws.xray.entities.Cause)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ExecutableHttpRequest (software.amazon.awssdk.http.ExecutableHttpRequest)1 SdkHttpResponse (software.amazon.awssdk.http.SdkHttpResponse)1 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)1