Search in sources :

Example 6 with SdkHttpResponse

use of software.amazon.awssdk.http.SdkHttpResponse 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

SdkHttpResponse (software.amazon.awssdk.http.SdkHttpResponse)6 Test (org.junit.Test)4 Segment (com.amazonaws.xray.entities.Segment)2 Subsegment (com.amazonaws.xray.entities.Subsegment)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Map (java.util.Map)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 Mockito.when (org.mockito.Mockito.when)2 Answer (org.mockito.stubbing.Answer)2 SdkHttpClient (software.amazon.awssdk.http.SdkHttpClient)2 SdkHttpRequest (software.amazon.awssdk.http.SdkHttpRequest)2 AsyncExecuteRequest (software.amazon.awssdk.http.async.AsyncExecuteRequest)2 SdkAsyncHttpResponseHandler (software.amazon.awssdk.http.async.SdkAsyncHttpResponseHandler)2 DynamoDbClient (software.amazon.awssdk.services.dynamodb.DynamoDbClient)2 AWSXRay (com.amazonaws.xray.AWSXRay)1 AWSXRayRecorderBuilder (com.amazonaws.xray.AWSXRayRecorderBuilder)1 Emitter (com.amazonaws.xray.emitters.Emitter)1 Cause (com.amazonaws.xray.entities.Cause)1 ImmutableList (com.google.common.collect.ImmutableList)1