use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class SwPreparedStatementTest method testInsertWithIntColumnIndexes.
@Test
public void testInsertWithIntColumnIndexes() throws SQLException {
PreparedStatement preparedStatement = swConnection.prepareStatement("INSERT INTO test VALUES(?)", 1);
boolean insertCount = preparedStatement.execute("INSERT INTO test VALUES(1)", new int[] { 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.TraceSegment in project incubator-skywalking by apache.
the class SwPreparedStatementTest method testUpdateSql.
@Test
public void testUpdateSql() throws SQLException {
PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET a = ?");
int updateCount = preparedStatement.executeUpdate("UPDATE test SET a = 1");
preparedStatement.cancel();
preparedStatement.close();
verify(mysqlPreparedStatement, times(1)).executeUpdate(anyString());
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/executeUpdate", "UPDATE test SET a = 1");
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class SwPreparedStatementTest method testQuerySqlWithSql.
@Test
public void testQuerySqlWithSql() throws SQLException {
PreparedStatement preparedStatement = swConnection.prepareStatement("SELECT * FROM test", 1);
ResultSet resultSet = preparedStatement.executeQuery("SELECT * FROM test");
preparedStatement.getGeneratedKeys();
preparedStatement.close();
verify(mysqlPreparedStatement, times(1)).executeQuery(anyString());
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");
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class SwPreparedStatementTest method testExecuteWithSQL.
@Test
public void testExecuteWithSQL() throws SQLException {
PreparedStatement preparedStatement = swConnection.prepareStatement("UPDATE test SET a = ?");
preparedStatement.setString(1, "a");
boolean updateCount = preparedStatement.execute("UPDATE test SET a = 1");
preparedStatement.cancel();
preparedStatement.close();
verify(mysqlPreparedStatement, times(1)).execute(anyString());
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", "UPDATE test SET a = 1");
}
use of org.apache.skywalking.apm.agent.core.context.trace.TraceSegment in project incubator-skywalking by apache.
the class ContextManagerTest method createMultipleExitSpan.
@Test
public void createMultipleExitSpan() {
AbstractSpan entrySpan = ContextManager.createEntrySpan("/testEntrySpan", null);
entrySpan.setComponent(ComponentsDefine.TOMCAT);
Tags.HTTP.METHOD.set(entrySpan, "GET");
Tags.URL.set(entrySpan, "127.0.0.1:8080");
SpanLayer.asHttp(entrySpan);
ContextCarrier firstExitSpanContextCarrier = new ContextCarrier();
AbstractSpan firstExitSpan = ContextManager.createExitSpan("/testFirstExit", firstExitSpanContextCarrier, "127.0.0.1:8080");
firstExitSpan.setComponent(ComponentsDefine.DUBBO);
Tags.URL.set(firstExitSpan, "dubbo://127.0.0.1:8080");
SpanLayer.asRPCFramework(firstExitSpan);
ContextCarrier secondExitSpanContextCarrier = new ContextCarrier();
AbstractSpan secondExitSpan = ContextManager.createExitSpan("/testSecondExit", secondExitSpanContextCarrier, "127.0.0.1:9080");
secondExitSpan.setComponent(ComponentsDefine.TOMCAT);
Tags.HTTP.METHOD.set(secondExitSpan, "GET");
Tags.URL.set(secondExitSpan, "127.0.0.1:8080");
SpanLayer.asHttp(secondExitSpan);
secondExitSpan.setOperationName("/testSecondExit-setOperationName");
ContextManager.stopSpan();
ContextManager.stopSpan();
ContextManager.stopSpan();
assertThat(tracingData.getTraceSegments().size(), is(1));
TraceSegment actualSegment = tracingData.getTraceSegments().get(0);
assertNull(actualSegment.getRefs());
List<AbstractTracingSpan> spanList = SegmentHelper.getSpan(actualSegment);
assertThat(spanList.size(), is(2));
AbstractTracingSpan actualFirstExitSpan = spanList.get(0);
assertThat(actualFirstExitSpan.getOperationName(), is("/testFirstExit"));
assertThat(actualFirstExitSpan.getSpanId(), is(1));
assertThat(AbstractTracingSpanHelper.getParentSpanId(actualFirstExitSpan), is(0));
assertThat(SpanHelper.getComponentId(actualFirstExitSpan), is(ComponentsDefine.DUBBO.getId()));
assertThat(SpanHelper.getLayer(actualFirstExitSpan), is(SpanLayer.RPC_FRAMEWORK));
AbstractTracingSpan actualEntrySpan = spanList.get(1);
assertThat(actualEntrySpan.getOperationName(), is("/testEntrySpan"));
assertThat(actualEntrySpan.getSpanId(), is(0));
assertThat(AbstractTracingSpanHelper.getParentSpanId(actualEntrySpan), is(-1));
assertThat(firstExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
assertThat(firstExitSpanContextCarrier.getSpanId(), is(1));
assertThat(firstExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
assertThat(secondExitSpanContextCarrier.getPeerHost(), is("#127.0.0.1:8080"));
assertThat(secondExitSpanContextCarrier.getSpanId(), is(1));
assertThat(secondExitSpanContextCarrier.getEntryOperationName(), is("#/testEntrySpan"));
}
Aggregations