@Test public void testStatementUsingRelativeForward() throws Exception { // given // when container.executeAppUnderTest(ExecuteStatementAndUseRelativeForward.class); // then Trace trace = container.getTraceService().getLastTrace(); assertThat(trace.getSpans()).hasSize(2); Span jdbcSpan = trace.getSpans().get(1); assertThat(jdbcSpan.getMessage().getText()) .startsWith("jdbc execution: select * from employee => 3 rows [connection: "); }
@Test public void testPreparedStatementWithoutBindParameters() throws Exception { // given container.getConfigService().setPluginProperty(PLUGIN_ID, "captureBindParameters", false); // when container.executeAppUnderTest(ExecutePreparedStatementAndIterateOverResults.class); // then Trace trace = container.getTraceService().getLastTrace(); assertThat(trace.getSpans()).hasSize(2); Span jdbcSpan = trace.getSpans().get(1); assertThat(jdbcSpan.getMessage().getText()) .startsWith( "jdbc execution: select * from employee where name like ? => 1 row [connection: "); }
@Test public void testCallableStatement() throws Exception { // given container.getConfigService().setPluginProperty(PLUGIN_ID, "captureBindParameters", true); // when container.executeAppUnderTest(ExecuteCallableStatement.class); // then Trace trace = container.getTraceService().getLastTrace(); assertThat(trace.getSpans()).hasSize(2); Span jdbcSpan = trace.getSpans().get(1); assertThat(jdbcSpan.getMessage().getText()) .startsWith( "jdbc execution: insert into employee values (?, ?) ['jane', NULL] [connection: "); }
@Test public void testPreparedStatement() throws Exception { // given // when container.executeAppUnderTest(ExecutePreparedStatementAndIterateOverResults.class); // then Trace trace = container.getTraceService().getLastTrace(); assertThat(trace.getSpans()).hasSize(2); Span jdbcSpan = trace.getSpans().get(1); assertThat(jdbcSpan.getMessage().getText()) .startsWith( "jdbc execution: select * from employee" + " where name like ? ['john%'] => 1 row [connection: "); }
@Test public void testRollback() throws Exception { // given // when container.executeAppUnderTest(ExecuteJdbcRollback.class); // then Trace trace = container.getTraceService().getLastTrace(); assertThat(trace.getSpans()).hasSize(3); Span jdbcInsertSpan = trace.getSpans().get(1); assertThat(jdbcInsertSpan.getMessage().getText()) .startsWith( "jdbc execution: insert into employee (name) values ('john doe') [connection: "); Span jdbcCommitSpan = trace.getSpans().get(2); assertThat(jdbcCommitSpan.getMessage().getText()).startsWith("jdbc rollback [connection: "); assertThat(trace.getMetrics()).hasSize(4); // ordering is by total desc, so not fixed (though root span will be first since it // encompasses all other timings) assertThat(trace.getMetrics().get(0).getName()).isEqualTo("mock trace marker"); assertThat(trace.getMetricNames()) .containsOnly("mock trace marker", "jdbc execute", "jdbc rollback", "jdbc statement close"); }