Search in sources :

Example 16 with TraceSegment

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

the class JedisMethodInterceptorTest method testInterceptWithMultiHost.

@Test
public void testInterceptWithMultiHost() throws Throwable {
    when(enhancedInstance.getSkyWalkingDynamicField()).thenReturn("127.0.0.1:6379;127.0.0.1:16379;");
    interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertRedisSpan(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 17 with TraceSegment

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

the class JedisMethodInterceptorTest method testIntercept.

@Test
public void testIntercept() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    interceptor.afterMethod(enhancedInstance, getMockGetMethod(), allArgument, argumentType, null);
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertRedisSpan(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 18 with TraceSegment

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

the class JedisMethodInterceptorTest method testInterceptWithException.

@Test
public void testInterceptWithException() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    interceptor.handleMethodException(enhancedInstance, getMockSetMethod(), allArgument, argumentType, new RuntimeException());
    interceptor.afterMethod(enhancedInstance, getMockSetMethod(), allArgument, argumentType, null);
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertRedisSpan(spans.get(0));
    assertLogData(SpanHelper.getLogs(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 19 with TraceSegment

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

Example 20 with TraceSegment

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

the class DubboInterceptorTest method testConsumerWithException.

@Test
public void testConsumerWithException() throws Throwable {
    dubboInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, methodInterceptResult);
    dubboInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException());
    dubboInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, result);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    assertConsumerTraceSegmentInErrorCase(traceSegment);
}
Also used : TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) 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