Search in sources :

Example 61 with AbstractTracingSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan 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 62 with AbstractTracingSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan 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 63 with AbstractTracingSpan

use of org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan 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)

Example 64 with AbstractTracingSpan

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

the class SyncHttpRequestSendInterceptorTest method testMethodsAround.

@Test
public void testMethodsAround() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
    AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
    List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
    assertThat(tags.size(), is(2));
    assertThat(tags.get(0).getValue(), is("GET"));
    assertThat(tags.get(1).getValue(), is(uri.toString()));
    Assert.assertEquals(false, SpanHelper.getErrorOccurred(finishedSpan));
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) 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 AbstractTracingSpan

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

the class SyncHttpRequestSendInterceptorTest method testMethodsAroundError.

@Test
public void testMethodsAroundError() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException());
    interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
    AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
    List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
    assertThat(tags.size(), is(2));
    assertThat(tags.get(0).getValue(), is("GET"));
    assertThat(tags.get(1).getValue(), is(uri.toString()));
    Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
    SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class);
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) 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

AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)151 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)149 Test (org.junit.Test)144 PreparedStatement (java.sql.PreparedStatement)19 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 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