Search in sources :

Example 56 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.

the class RealCallInterceptorTest method testException.

@Test
public void testException() throws Throwable {
    realCallInterceptor.onConstruct(enhancedInstance, allArguments);
    realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    realCallInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new NullPointerException("testException"));
    Response response = mock(Response.class);
    when(response.code()).thenReturn(200);
    realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertSpan(spans.get(0));
    SpanAssert.assertOccurException(spans.get(0), true);
    SpanAssert.assertLogSize(spans.get(0), 1);
    SpanAssert.assertException(SpanHelper.getLogs(spans.get(0)).get(0), NullPointerException.class, "testException");
}
Also used : Response(okhttp3.Response) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 57 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.

the class RealCallInterceptorTest method testMethodsAroundError.

@Test
public void testMethodsAroundError() throws Throwable {
    realCallInterceptor.onConstruct(enhancedInstance, allArguments);
    realCallInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    Response response = mock(Response.class);
    when(response.code()).thenReturn(404);
    realCallInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, response);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertSpan(spans.get(0));
    SpanAssert.assertOccurException(spans.get(0), true);
}
Also used : Response(okhttp3.Response) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 58 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.

the class ResinV3InterceptorTest method testWithSerializedContextData.

@Test
public void testWithSerializedContextData() throws Throwable {
    when(request.getHeader(SW3CarrierItem.HEADER_NAME)).thenReturn("1.333.2345|3|1|1|#192.168.1.8:18002|#/portal/|#/testEntrySpan|#AQA*#AQA*Et0We0tQNQA*");
    interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
    interceptor.afterMethod(enhancedInstance, null, 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));
    assertTraceSegmentRef(traceSegment.getRefs().get(0));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 59 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.

the class ResinV3InterceptorTest method testWithOccurException.

@Test
public void testWithOccurException() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, null, arguments, argumentType, methodInterceptResult);
    interceptor.handleMethodException(enhancedInstance, null, arguments, argumentType, new RuntimeException());
    interceptor.afterMethod(enhancedInstance, null, 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);
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 60 with TraceSegment

use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.

the class OnSuccessInterceptorTest method testOnSuccessWithErrorStatus.

@Test
public void testOnSuccessWithErrorStatus() throws Throwable {
    when(sendResult.getSendStatus()).thenReturn(SendStatus.FLUSH_SLAVE_TIMEOUT);
    successInterceptor.beforeMethod(enhancedInstance, null, new Object[] { sendResult }, null, null);
    successInterceptor.afterMethod(enhancedInstance, null, new Object[] { sendResult }, null, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    AbstractTracingSpan successSpan = spans.get(0);
    SpanAssert.assertComponent(successSpan, ComponentsDefine.ROCKET_MQ);
    SpanAssert.assertOccurException(successSpan, true);
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Aggregations

TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)158 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)149 Test (org.junit.Test)147 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)20 PreparedStatement (java.sql.PreparedStatement)19 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)15 SegmentStoragePoint (org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint)14 CallableStatement (java.sql.CallableStatement)13 Method (java.lang.reflect.Method)11 Statement (java.sql.Statement)11 SQLException (java.sql.SQLException)10 KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)10 ResultSet (java.sql.ResultSet)7 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)7 ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)7 Response (feign.Response)3 HashMap (java.util.HashMap)3 Response (okhttp3.Response)3 TraceSegmentRef (org.apache.skywalking.apm.agent.core.context.trace.TraceSegmentRef)3 TextMap (io.opentracing.propagation.TextMap)2