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());
}
Aggregations