Search in sources :

Example 6 with Segment

use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.

the class AWSXRayServletFilterTest method testNameOverrideEnvironmentVariable.

@Test
public void testNameOverrideEnvironmentVariable() throws IOException, ServletException {
    environmentVariables.set(SegmentNamingStrategy.NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY, "pass");
    AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("fail");
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
    Mockito.when(request.getMethod()).thenReturn("TEST_METHOD");
    Mockito.when(request.isAsyncStarted()).thenReturn(false);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    FilterChain chain = Mockito.mock(FilterChain.class);
    servletFilter.doFilter(request, response, chain);
    ArgumentCaptor<Segment> emittedSegment = ArgumentCaptor.forClass(Segment.class);
    Mockito.verify(AWSXRay.getGlobalRecorder().getEmitter(), Mockito.times(1)).sendSegment(emittedSegment.capture());
    Assert.assertEquals("pass", emittedSegment.getValue().getName());
    environmentVariables.set(SegmentNamingStrategy.NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY, null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 7 with Segment

use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.

the class AWSXRayServletFilterTest method testNameOverrideEnvironmentVariableOverridesSystemProperty.

@Test
public void testNameOverrideEnvironmentVariableOverridesSystemProperty() throws IOException, ServletException {
    environmentVariables.set(SegmentNamingStrategy.NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY, "pass");
    System.setProperty(SegmentNamingStrategy.NAME_OVERRIDE_SYSTEM_PROPERTY_KEY, "fail");
    AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("fail");
    HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
    Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
    Mockito.when(request.getMethod()).thenReturn("TEST_METHOD");
    Mockito.when(request.isAsyncStarted()).thenReturn(false);
    HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
    FilterChain chain = Mockito.mock(FilterChain.class);
    servletFilter.doFilter(request, response, chain);
    ArgumentCaptor<Segment> emittedSegment = ArgumentCaptor.forClass(Segment.class);
    Mockito.verify(AWSXRay.getGlobalRecorder().getEmitter(), Mockito.times(1)).sendSegment(emittedSegment.capture());
    Assert.assertEquals("pass", emittedSegment.getValue().getName());
    environmentVariables.set(SegmentNamingStrategy.NAME_OVERRIDE_ENVIRONMENT_VARIABLE_KEY, null);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterChain(javax.servlet.FilterChain) HttpServletResponse(javax.servlet.http.HttpServletResponse) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 8 with Segment

use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.

the class DefaultStreamingStrategyTest method testDefaultStreamingStrategyRequiresStreaming.

@Test
public void testDefaultStreamingStrategyRequiresStreaming() {
    DefaultStreamingStrategy defaultStreamingStrategy = new DefaultStreamingStrategy(1);
    Segment smallSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "small");
    Assert.assertFalse(defaultStreamingStrategy.requiresStreaming(smallSegment));
    Segment bigSegment = new SegmentImpl(AWSXRay.getGlobalRecorder(), "big");
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    bigSegment.addSubsegment(new SubsegmentImpl(AWSXRay.getGlobalRecorder(), "big_child", bigSegment));
    Assert.assertTrue(defaultStreamingStrategy.requiresStreaming(bigSegment));
}
Also used : SubsegmentImpl(com.amazonaws.xray.entities.SubsegmentImpl) SegmentImpl(com.amazonaws.xray.entities.SegmentImpl) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 9 with Segment

use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.

the class TracedResponseHandlerTest method testHandleResponse400SetsErrorFlag.

@Test
public void testHandleResponse400SetsErrorFlag() {
    Segment segment = segmentInResponseToCode(400);
    Subsegment subsegment = segment.getSubsegments().get(0);
    Assert.assertFalse(subsegment.isFault());
    Assert.assertTrue(subsegment.isError());
    Assert.assertFalse(subsegment.isThrottle());
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Example 10 with Segment

use of com.amazonaws.xray.entities.Segment in project aws-xray-sdk-java by aws.

the class TracedResponseHandlerTest method testHandleResponse500SetsFaultFlag.

@Test
public void testHandleResponse500SetsFaultFlag() {
    Segment segment = segmentInResponseToCode(500);
    Subsegment subsegment = segment.getSubsegments().get(0);
    Assert.assertTrue(subsegment.isFault());
    Assert.assertFalse(subsegment.isError());
    Assert.assertFalse(subsegment.isThrottle());
}
Also used : Subsegment(com.amazonaws.xray.entities.Subsegment) Segment(com.amazonaws.xray.entities.Segment) Test(org.junit.Test)

Aggregations

Segment (com.amazonaws.xray.entities.Segment)29 Test (org.junit.Test)16 Subsegment (com.amazonaws.xray.entities.Subsegment)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 TraceID (com.amazonaws.xray.entities.TraceID)5 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 SegmentImpl (com.amazonaws.xray.entities.SegmentImpl)4 SubsegmentImpl (com.amazonaws.xray.entities.SubsegmentImpl)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 AWSStaticCredentialsProvider (com.amazonaws.auth.AWSStaticCredentialsProvider)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 HashMap (java.util.HashMap)3 FilterChain (javax.servlet.FilterChain)3 AmazonS3 (com.amazonaws.services.s3.AmazonS3)2 TraceHeader (com.amazonaws.xray.entities.TraceHeader)2 AWSLambda (com.amazonaws.services.lambda.AWSLambda)1 InvokeRequest (com.amazonaws.services.lambda.model.InvokeRequest)1 InvokeResult (com.amazonaws.services.lambda.model.InvokeResult)1 Emitter (com.amazonaws.xray.emitters.Emitter)1 UDPEmitter (com.amazonaws.xray.emitters.UDPEmitter)1