Search in sources :

Example 11 with TraceSegment

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

the class SWStatementTest method testPreparedStatementConfig.

@Test
public void testPreparedStatementConfig() throws SQLException {
    Statement statement = swConnection.createStatement();
    statement.cancel();
    statement.getUpdateCount();
    statement.setFetchDirection(1);
    statement.getFetchDirection();
    statement.getResultSetConcurrency();
    statement.getResultSetType();
    statement.isClosed();
    statement.setPoolable(false);
    statement.isPoolable();
    statement.getWarnings();
    statement.clearWarnings();
    statement.setCursorName("test");
    statement.setMaxFieldSize(11);
    statement.getMaxFieldSize();
    statement.setMaxRows(10);
    statement.getMaxRows();
    statement.setEscapeProcessing(true);
    statement.setFetchSize(1);
    statement.getFetchSize();
    statement.setQueryTimeout(1);
    statement.getQueryTimeout();
    Connection connection = statement.getConnection();
    statement.execute("SELECT * FROM test");
    statement.getMoreResults();
    statement.getMoreResults(1);
    statement.getResultSetHoldability();
    statement.getResultSet();
    statement.close();
    verify(mysqlStatement, times(1)).getUpdateCount();
    verify(mysqlStatement, times(1)).getMoreResults();
    verify(mysqlStatement, times(1)).setFetchDirection(anyInt());
    verify(mysqlStatement, times(1)).getFetchDirection();
    verify(mysqlStatement, times(1)).getResultSetType();
    verify(mysqlStatement, times(1)).isClosed();
    verify(mysqlStatement, times(1)).setPoolable(anyBoolean());
    verify(mysqlStatement, times(1)).getWarnings();
    verify(mysqlStatement, times(1)).clearWarnings();
    verify(mysqlStatement, times(1)).setCursorName(anyString());
    verify(mysqlStatement, times(1)).setMaxFieldSize(anyInt());
    verify(mysqlStatement, times(1)).getMaxFieldSize();
    verify(mysqlStatement, times(1)).setMaxRows(anyInt());
    verify(mysqlStatement, times(1)).getMaxRows();
    verify(mysqlStatement, times(1)).setEscapeProcessing(anyBoolean());
    verify(mysqlStatement, times(1)).getResultSetConcurrency();
    verify(mysqlStatement, times(1)).getResultSetConcurrency();
    verify(mysqlStatement, times(1)).getResultSetType();
    verify(mysqlStatement, times(1)).getMoreResults(anyInt());
    verify(mysqlStatement, times(1)).setFetchSize(anyInt());
    verify(mysqlStatement, times(1)).getFetchSize();
    verify(mysqlStatement, times(1)).getQueryTimeout();
    verify(mysqlStatement, times(1)).setQueryTimeout(anyInt());
    verify(mysqlStatement, times(1)).getResultSet();
    assertThat(connection, CoreMatchers.<Connection>is(swConnection));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "SELECT * FROM test");
}
Also used : Statement(java.sql.Statement) Connection(java.sql.Connection) JdbcConnection(com.mysql.cj.api.jdbc.JdbcConnection) 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 12 with TraceSegment

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

the class SWStatementTest method testExecuteWithColumnIndexes.

@Test
public void testExecuteWithColumnIndexes() throws SQLException {
    Statement statement = swConnection.createStatement(1, 1, 1);
    boolean executeSuccess = statement.execute("UPDATE test SET a = 1", new int[] { 1 });
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "UPDATE test SET a = 1");
}
Also used : Statement(java.sql.Statement) 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 13 with TraceSegment

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

the class SWStatementTest method testExecuteQuery.

@Test
public void testExecuteQuery() throws SQLException {
    Statement statement = swConnection.createStatement(1, 1, 1);
    ResultSet executeSuccess = statement.executeQuery("SELECT * FROM test");
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/executeQuery", "SELECT * FROM test");
}
Also used : Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) 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 14 with TraceSegment

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

the class SWStatementTest method testExecuteWithAutoGeneratedKey.

@Test
public void testExecuteWithAutoGeneratedKey() throws SQLException {
    Statement statement = swConnection.createStatement(1, 1);
    boolean executeSuccess = statement.execute("SELECT * FROM test", 1);
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/execute", "SELECT * FROM test");
}
Also used : Statement(java.sql.Statement) 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 15 with TraceSegment

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

the class SWStatementTest method testExecuteUpdateWithAutoGeneratedKey.

@Test
public void testExecuteUpdateWithAutoGeneratedKey() throws SQLException {
    Statement statement = swConnection.createStatement(1, 1, 1);
    int executeSuccess = statement.executeUpdate("UPDATE test SET a = 1", 1);
    statement.getGeneratedKeys();
    verify(mysqlStatement, times(1)).getGeneratedKeys();
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    assertDBSpan(spans.get(0), "Mysql/JDBI/Statement/executeUpdate", "UPDATE test SET a = 1");
}
Also used : Statement(java.sql.Statement) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) SegmentStoragePoint(org.apache.skywalking.apm.agent.test.tools.SegmentStoragePoint) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) 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