use of org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx in project tomcat by apache.
the class TestSlowQueryReport method testSlowSqlJmx.
@Test
public void testSlowSqlJmx() throws Exception {
int count = 1;
Connection con = this.datasource.getConnection();
for (int i = 0; i < count; i++) {
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(superSlowSql);
rs.close();
st.close();
}
Map<String, SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
Assert.assertNotNull(map);
Assert.assertEquals(1, map.size());
String key = map.keySet().iterator().next();
SlowQueryReport.QueryStats stats = map.get(key);
System.out.println("Stats:" + stats);
ClientListener listener = new ClientListener();
ConnectionPool pool = datasource.getPool();
ManagementFactory.getPlatformMBeanServer().addNotificationListener(new SlowQueryReportJmx().getObjectName(SlowQueryReportJmx.class, pool.getName()), listener, null, null);
for (int i = 0; i < count; i++) {
PreparedStatement st = con.prepareStatement(superSlowSql);
ResultSet rs = st.executeQuery();
rs.close();
st.close();
}
System.out.println("Stats:" + stats);
for (int i = 0; i < count; i++) {
CallableStatement st = con.prepareCall(superSlowSql);
ResultSet rs = st.executeQuery();
rs.close();
st.close();
}
System.out.println("Stats:" + stats);
Assert.assertEquals("Expecting to have received " + (2 * count) + " notifications.", 2 * count, listener.notificationCount.get());
con.close();
tearDown();
//make sure we actually did clean up when the pool closed
Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
Aggregations