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