Java Code Examples for org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport

The following examples show how to use org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Tomcat8-Source-Read   Source File: TestSlowQueryReport.java    License: MIT License 6 votes vote down vote up
@Test
public void testFastSql() throws Exception {
    int count = 3;
    Connection con = this.datasource.getConnection();
    String fastSql = this.datasource.getValidationQuery();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(fastSql);
        rs.close();
        st.close();
    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(1,map.size());
    ConnectionPool pool = datasource.getPool();
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
Example 2
Source Project: Tomcat8-Source-Read   Source File: TestSlowQueryReport.java    License: MIT License 6 votes vote down vote up
@Test
public void testFailedSql() throws Exception {
    int count = 3;
    Connection con = this.datasource.getConnection();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        try {
            ResultSet rs = st.executeQuery(failedSql);
            rs.close();
        }catch (Exception x) {
            // NO-OP
        }
        st.close();
    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(1,map.size());
    ConnectionPool pool = datasource.getPool();
    String key = map.keySet().iterator().next();
    SlowQueryReport.QueryStats stats = map.get(key);
    System.out.println("Stats:"+stats);
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
Example 3
Source Project: Tomcat7.0.67   Source File: TestSlowQueryReport.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFastSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String fastSql = this.datasource.getValidationQuery();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(fastSql);
        rs.close();
        st.close();
    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(0,map.size());
    ConnectionPool pool = datasource.getPool();
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
Example 4
Source Project: tomcatsrc   Source File: TestSlowQueryReport.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testFastSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String fastSql = this.datasource.getValidationQuery();
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        ResultSet rs = st.executeQuery(fastSql);
        rs.close();
        st.close();
    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(0,map.size());
    ConnectionPool pool = datasource.getPool();
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
Example 5
Source Project: Tomcat7.0.67   Source File: TestSlowQueryReport.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String slowSql = "select 1 from non_existent";
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        try {
            ResultSet rs = st.executeQuery(slowSql);
            rs.close();
        }catch (Exception x) {
            // NO-OP
        }
        st.close();

    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(1,map.size());
    ConnectionPool pool = datasource.getPool();
    String key = map.keySet().iterator().next();
    SlowQueryReport.QueryStats stats = map.get(key);
    System.out.println("Stats:"+stats);
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}
 
Example 6
Source Project: tomcatsrc   Source File: TestSlowQueryReport.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedSql() throws Exception {
    int count = 3;
    this.init();
    this.datasource.setMaxActive(1);
    this.datasource.setJdbcInterceptors(SlowQueryReport.class.getName());
    Connection con = this.datasource.getConnection();
    String slowSql = "select 1 from non_existent";
    for (int i=0; i<count; i++) {
        Statement st = con.createStatement();
        try {
            ResultSet rs = st.executeQuery(slowSql);
            rs.close();
        }catch (Exception x) {
            // NO-OP
        }
        st.close();

    }
    Map<String,SlowQueryReport.QueryStats> map = SlowQueryReport.getPoolStats(datasource.getPool().getName());
    Assert.assertNotNull(map);
    Assert.assertEquals(1,map.size());
    ConnectionPool pool = datasource.getPool();
    String key = map.keySet().iterator().next();
    SlowQueryReport.QueryStats stats = map.get(key);
    System.out.println("Stats:"+stats);
    con.close();
    tearDown();
    Assert.assertNull(SlowQueryReport.getPoolStats(pool.getName()));
}