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());
}
JdbcStatManager.getInstance().reset();
Assert.assertFalse(sqlStat.isRemoved());
JdbcStatManager.getInstance().reset();
Assert.assertTrue(sqlStat.isRemoved());
{
Connection conn = dataSource.getConnection();
PreparedStatement stmt = conn.prepareStatement(sql);
ResultSet rs = stmt.executeQuery();
rs.next();
rs.close();
conn.close();
}
Assert.assertNotSame(sqlStat, dataSource.getDataSourceStat().getSqlStat(sql));
{
Assert.assertEquals(0, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
}
sqlStat = dataSource.getDataSourceStat().getSqlStat(sql);
Assert.assertEquals(1, sqlStat.getExecuteAndResultHoldTimeHistogramSum());
}