use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilterReadStringLengthTest method test_stat_1.
public void test_stat_1() throws Exception {
Connection conn = dataSource.getConnection();
String sql = "select 'x'";
PreparedStatement stmt = conn.prepareStatement("select 'x'");
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
Assert.assertEquals(0, sqlStat.getReadStringLength());
ResultSet rs = stmt.executeQuery();
rs.next();
rs.getString("1");
rs.close();
stmt.close();
conn.close();
Assert.assertEquals(7, sqlStat.getReadStringLength());
sqlStat.reset();
Assert.assertEquals(0, sqlStat.getReadStringLength());
}
use of com.alibaba.druid.stat.JdbcSqlStat in project druid by alibaba.
the class StatFilterResultSetMultiCloseTest method test_stat.
public void test_stat() throws Exception {
final String sql = "SELECT 1";
Assert.assertTrue(dataSource.isInited());
JdbcSqlStat sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
Assert.assertNull(sqlStat);
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
rs.next();
rs.close();
sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
Assert.assertNotNull(sqlStat);
Assert.assertEquals("first failed", 1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
rs.close();
Assert.assertEquals("second failed", 1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
stmt.close();
conn.close();
Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
}
Aggregations