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