Search in sources :

Example 36 with AbstractTracingSpan

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

the class SWConnectionTest method testCommitWithException.

@Test(expected = SQLException.class)
public void testCommitWithException() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("SELECT * FROM test", new int[] { 1 });
    doThrow(new SQLException()).when(jdbcConnection).commit();
    try {
        swConnection.commit();
    } finally {
        assertThat(segmentStorage.getTraceSegments().size(), is(1));
        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
        List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
        assertThat(spans.size(), is(1));
        assertDBSpan(spans.get(0), "Mysql/JDBI/Connection/commit");
        assertThat(SpanHelper.getLogs(spans.get(0)).size(), is(1));
        assertDBSpanLog(SpanHelper.getLogs(spans.get(0)).get(0));
    }
}
Also used : SQLException(java.sql.SQLException) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) PreparedStatement(java.sql.PreparedStatement) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 37 with AbstractTracingSpan

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

the class SWConnectionTest method testRollBackWithSavePoint.

@Test
public void testRollBackWithSavePoint() throws SQLException {
    swConnection.rollback(savepoint);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Connection/rollback to savepoint");
}
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 38 with AbstractTracingSpan

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

the class JobExecutorInterceptorTest method assertSuccess.

@Test
public void assertSuccess() throws Throwable {
    jobExecutorInterceptor.beforeMethod(null, null, new Object[] { mockShardingContext("fooJob", 1), 1 }, null, null);
    jobExecutorInterceptor.afterMethod(null, null, null, null, null);
    TraceSegment segment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertNotNull(spans);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).transform().getOperationName(), is("fooJob-test"));
    assertThat(spans.get(0).transform().getComponentId(), is(24));
    assertThat(spans.get(0).transform().getTags(0).getKey(), is("sharding_context"));
    assertThat(spans.get(0).transform().getTags(0).getValue(), is("ShardingContext(jobName=fooJob, taskId=fooJob1, shardingTotalCount=2, jobParameter=, shardingItem=1, shardingParameter=test)"));
}
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 39 with AbstractTracingSpan

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

the class JobExecutorInterceptorTest method assertSuccessWithoutSharding.

@Test
public void assertSuccessWithoutSharding() throws Throwable {
    jobExecutorInterceptor.beforeMethod(null, null, new Object[] { mockShardingContext("fooJob", 0), 0 }, null, null);
    jobExecutorInterceptor.afterMethod(null, null, null, null, null);
    TraceSegment segment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertNotNull(spans);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).transform().getOperationName(), is("fooJob"));
    assertThat(spans.get(0).transform().getTags(0).getValue(), is("ShardingContext(jobName=fooJob, taskId=fooJob0, shardingTotalCount=1, jobParameter=, shardingItem=0, shardingParameter=null)"));
}
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 40 with AbstractTracingSpan

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

the class JobExecutorInterceptorTest method assertError.

@Test
public void assertError() throws Throwable {
    jobExecutorInterceptor.beforeMethod(null, null, new Object[] { mockShardingContext("fooJob", 0), 0 }, null, null);
    jobExecutorInterceptor.handleMethodException(null, null, null, null, new Exception("fooError"));
    jobExecutorInterceptor.afterMethod(null, null, null, null, null);
    TraceSegment segment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(segment);
    assertNotNull(spans);
    assertThat(spans.size(), is(1));
    assertThat(spans.get(0).transform().getIsError(), is(true));
    assertThat(spans.get(0).transform().getLogs(0).getDataList().size(), is(4));
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) SQLException(java.sql.SQLException) 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