Search in sources :

Example 61 with TraceSegment

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

the class InterceptorTest method assertAsyncExecute.

@Test
public void assertAsyncExecute() throws Throwable {
    executeInterceptor.beforeMethod(null, null, allArguments, null, null);
    asyncExecuteInterceptor.beforeMethod(null, null, null, null, null);
    final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
    ES.submit(new Runnable() {

        @Override
        public void run() {
            ExecutorDataMap.setDataMap(dataMap);
            sendEvent("ds_1", "select * from t_order_1");
        }
    }).get();
    asyncExecuteInterceptor.afterMethod(null, null, null, null, null);
    sendEvent("ds_0", "select * from t_order_0");
    executeInterceptor.afterMethod(null, null, allArguments, null, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(2));
    TraceSegment segment0 = segmentStorage.getTraceSegments().get(0);
    TraceSegment segment1 = segmentStorage.getTraceSegments().get(1);
    assertThat(segment0.getRefs().size(), is(1));
    assertNull(segment1.getRefs());
    List<AbstractTracingSpan> spans0 = SegmentHelper.getSpans(segment0);
    assertNotNull(spans0);
    assertThat(spans0.size(), is(1));
    assertSpan(spans0.get(0), 1);
    List<AbstractTracingSpan> spans1 = SegmentHelper.getSpans(segment1);
    assertNotNull(spans1);
    assertThat(spans1.size(), is(2));
    assertSpan(spans1.get(0), 0);
    assertThat(spans1.get(1).getOperationName(), is("/SJDBC/TRUNK/DQL"));
}
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 62 with TraceSegment

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

the class InterceptorTest method assertExecuteError.

@Test
public void assertExecuteError() throws Throwable {
    executeInterceptor.beforeMethod(null, null, allArguments, null, null);
    asyncExecuteInterceptor.beforeMethod(null, null, null, null, null);
    final Map<String, Object> dataMap = ExecutorDataMap.getDataMap();
    ES.submit(new Runnable() {

        @Override
        public void run() {
            ExecutorDataMap.setDataMap(dataMap);
            sendError();
        }
    }).get();
    asyncExecuteInterceptor.handleMethodException(null, null, null, null, new SQLException("test"));
    asyncExecuteInterceptor.afterMethod(null, null, null, null, null);
    sendEvent("ds_0", "select * from t_order_0");
    executeInterceptor.handleMethodException(null, null, allArguments, null, new SQLException("Test"));
    executeInterceptor.afterMethod(null, null, allArguments, null, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(2));
    TraceSegment segment0 = segmentStorage.getTraceSegments().get(0);
    TraceSegment segment1 = segmentStorage.getTraceSegments().get(1);
    List<AbstractTracingSpan> spans0 = SegmentHelper.getSpans(segment0);
    assertNotNull(spans0);
    assertThat(spans0.size(), is(1));
    assertErrorSpan(spans0.get(0));
    List<AbstractTracingSpan> spans1 = SegmentHelper.getSpans(segment1);
    assertNotNull(spans1);
    assertThat(spans1.size(), is(2));
    assertSpan(spans1.get(0), 0);
    assertErrorSpan(spans1.get(1));
}
Also used : SQLException(java.sql.SQLException) 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 63 with TraceSegment

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

the class KafkaProducerInterceptorTest method testSendMessage.

@Test
public void testSendMessage() throws Throwable {
    producerInterceptor.beforeMethod(kafkaProducerInstance, null, arguments, argumentType, null);
    producerInterceptor.afterMethod(kafkaProducerInstance, null, arguments, argumentType, null);
    List<TraceSegment> traceSegmentList = segmentStorage.getTraceSegments();
    assertThat(traceSegmentList.size(), is(1));
    TraceSegment segment = traceSegmentList.get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertThat(spans.size(), is(1));
    assertMessageSpan(spans.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 64 with TraceSegment

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

the class MotanConsumerInterceptorTest method testResponseWithException.

@Test
public void testResponseWithException() throws Throwable {
    when(response.getException()).thenReturn(new RuntimeException());
    invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] { request }, new Class[] { request.getClass() }, null);
    invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] { request }, new Class[] { request.getClass() }, response);
    MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertTraceSegmentWhenOccurException(spans.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 65 with TraceSegment

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

the class MotanConsumerInterceptorTest method testInvokeInterceptor.

@Test
public void testInvokeInterceptor() throws Throwable {
    invokeInterceptor.beforeMethod(enhancedInstance, null, new Object[] { request }, new Class[] { request.getClass() }, null);
    invokeInterceptor.afterMethod(enhancedInstance, null, new Object[] { request }, new Class[] { request.getClass() }, response);
    MatcherAssert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertMotanConsumerSpan(spans.get(0));
    verify(request, times(1)).setAttachment(anyString(), anyString());
}
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