Search in sources :

Example 1 with AbstractTracingSpan

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

the class HttpClientExecuteInterceptorTest method testStatusCodeNotEquals200.

@Test
public void testStatusCodeNotEquals200() throws Throwable {
    when(statusLine.getStatusCode()).thenReturn(500);
    httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    List<KeyValuePair> tags = SpanHelper.getTags(spans.get(0));
    assertThat(tags.size(), is(3));
    assertThat(tags.get(2).getValue(), is("500"));
    assertHttpSpan(spans.get(0));
    assertThat(SpanHelper.getErrorOccurred(spans.get(0)), is(true));
    verify(request, times(1)).setHeader(anyString(), anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with AbstractTracingSpan

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

the class HttpClientExecuteInterceptorTest method testHttpClientWithException.

@Test
public void testHttpClientWithException() throws Throwable {
    httpClientExecuteInterceptor.beforeMethod(enhancedInstance, null, allArguments, argumentsType, null);
    httpClientExecuteInterceptor.handleMethodException(enhancedInstance, null, allArguments, argumentsType, new RuntimeException("testException"));
    httpClientExecuteInterceptor.afterMethod(enhancedInstance, null, allArguments, argumentsType, httpResponse);
    Assert.assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    AbstractTracingSpan span = spans.get(0);
    assertHttpSpan(span);
    assertThat(SpanHelper.getErrorOccurred(span), is(true));
    assertHttpSpanErrorLog(SpanHelper.getLogs(span));
    verify(request, times(1)).setHeader(anyString(), anyString());
}
Also used : AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with AbstractTracingSpan

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

the class SwPreparedStatementTest method testMultiHostWithException.

@Test(expected = SQLException.class)
public void testMultiHostWithException() throws SQLException {
    when(mysqlPreparedStatement.executeQuery()).thenThrow(new SQLException());
    try {
        PreparedStatement preparedStatement = multiHostConnection.prepareStatement("SELECT * FROM test WHERE a = ? or b = ? or c=? or d = ? or e=?");
        preparedStatement.setBigDecimal(1, new BigDecimal(10000));
        preparedStatement.setBlob(2, inputStream);
        preparedStatement.setBlob(3, inputStream, 1000000L);
        preparedStatement.setByte(3, (byte) 1);
        preparedStatement.setBytes(4, new byte[] { 1, 2 });
        preparedStatement.setLong(5, 100L);
        ResultSet resultSet = preparedStatement.executeQuery();
        preparedStatement.close();
    } finally {
        verify(mysqlPreparedStatement, times(1)).executeQuery();
        verify(mysqlPreparedStatement, times(0)).close();
        verify(mysqlPreparedStatement, times(1)).setBigDecimal(anyInt(), any(BigDecimal.class));
        verify(mysqlPreparedStatement, times(1)).setBlob(anyInt(), any(InputStream.class));
        verify(mysqlPreparedStatement, times(1)).setBlob(anyInt(), any(InputStream.class), anyLong());
        verify(mysqlPreparedStatement, times(1)).setByte(anyInt(), anyByte());
        TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
        List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
        assertThat(spans.size(), is(1));
        assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeQuery", "SELECT * FROM test WHERE a = ? or b = ? or c=? or d = ? or e=?");
        List<LogDataEntity> logData = SpanHelper.getLogs(spans.get(0));
        Assert.assertThat(logData.size(), is(1));
        assertThat(logData.size(), is(1));
        assertDBSpanLog(logData.get(0));
    }
}
Also used : SQLException(java.sql.SQLException) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) LogDataEntity(org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity) PreparedStatement(java.sql.PreparedStatement) BigDecimal(java.math.BigDecimal) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 4 with AbstractTracingSpan

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

the class SwPreparedStatementTest method testInsertWithStringColumnIndexes.

@Test
public void testInsertWithStringColumnIndexes() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES(?)", 1);
    boolean insertCount = preparedStatement.execute("INSERT INTO test VALUES(1)", new String[] { "1", "2" });
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/execute", "INSERT INTO test VALUES(1)");
}
Also used : 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 5 with AbstractTracingSpan

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

the class SwPreparedStatementTest method testExecuteQuery.

@Test
public void testExecuteQuery() throws SQLException {
    PreparedStatement preparedStatement = swConnection.prepareStatement("SELECT * FROM test", 1, 1, 1);
    ResultSet resultSet = preparedStatement.executeQuery();
    preparedStatement.close();
    verify(mysqlPreparedStatement, times(1)).executeQuery();
    verify(mysqlPreparedStatement, times(1)).close();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/PreparedStatement/executeQuery", "SELECT * FROM test");
}
Also used : ResultSet(java.sql.ResultSet) 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)

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