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