use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan in project incubator-skywalking by apache.
the class RestMappingMethodInterceptorTest method testPatchMapping.
@Test
public void testPatchMapping() throws Throwable {
controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
RestMappingClass1 mappingClass1 = new RestMappingClass1();
Method m = mappingClass1.getClass().getMethod("patchRequestURL");
when(request.getRequestURI()).thenReturn("/test/testRequestURL");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/patchRequestURL"));
ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request, response);
RequestContextHolder.setRequestAttributes(servletRequestAttributes);
interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/patchRequestURL");
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan in project incubator-skywalking by apache.
the class RestMappingMethodInterceptorTest method testPutMapping.
@Test
public void testPutMapping() throws Throwable {
controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
RestMappingClass1 mappingClass1 = new RestMappingClass1();
Method m = mappingClass1.getClass().getMethod("putRequestURL");
when(request.getRequestURI()).thenReturn("/test/testRequestURL");
when(request.getRequestURL()).thenReturn(new StringBuffer("http://localhost:8080/test/putRequestURL"));
ServletRequestAttributes servletRequestAttributes = new ServletRequestAttributes(request, response);
RequestContextHolder.setRequestAttributes(servletRequestAttributes);
interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0), "/putRequestURL");
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan in project incubator-skywalking by apache.
the class TestException method testHttpClientWithException.
@Test
public void testHttpClientWithException() throws Throwable {
AbstractSpan localSpan = ContextManager.createLocalSpan("httpasyncclient/HttpAsyncRequestExecutor:");
stateInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
stateInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentsType, new RuntimeException("testException"));
processResponseInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
processResponseInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertThat(spans.size(), is(3));
AbstractTracingSpan span = spans.get(0);
assertThat(SpanHelper.getErrorOccurred(span), is(true));
assertHttpSpanErrorLog(SpanHelper.getLogs(span));
verify(request, times(1)).setHeader(anyString(), anyString());
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan in project incubator-skywalking by apache.
the class RequestMappingMethodInterceptorTest method testWithoutSerializedContextData.
@Test
public void testWithoutSerializedContextData() throws Throwable {
controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
RequestMappingClass1 mappingClass1 = new RequestMappingClass1();
Method m = mappingClass1.getClass().getMethod("testRequestURL");
RequestContextHolder.setRequestAttributes(servletRequestAttributes);
interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0));
}
use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan in project incubator-skywalking by apache.
the class RequestMappingMethodInterceptorTest method testWithOccurException.
@Test
public void testWithOccurException() throws Throwable {
controllerConstructorInterceptor.onConstruct(enhancedInstance, null);
RequestMappingClass1 mappingClass1 = new RequestMappingClass1();
Method m = mappingClass1.getClass().getMethod("testRequestURL");
RequestContextHolder.setRequestAttributes(servletRequestAttributes);
interceptor.beforeMethod(enhancedInstance, m, arguments, argumentType, methodInterceptResult);
interceptor.handleMethodException(enhancedInstance, m, arguments, argumentType, new RuntimeException());
interceptor.afterMethod(enhancedInstance, m, arguments, argumentType, null);
assertThat(segmentStorage.getTraceSegments().size(), is(1));
TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
assertHttpSpan(spans.get(0));
List<LogDataEntity> logDataEntities = SpanHelper.getLogs(spans.get(0));
assertThat(logDataEntities.size(), is(1));
SpanAssert.assertException(logDataEntities.get(0), RuntimeException.class);
}
Aggregations