org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor Java Examples

The following examples show how to use org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor. 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 File: TestQueryTimeoutInterceptor.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example #2
Source File: TestQueryTimeoutInterceptor.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example #3
Source File: TestValidationQueryTimeout.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testValidationQueryTimeoutWithQueryTimeoutInterceptor() throws Exception {
    int interceptorTimeout = 30;
    this.datasource.setJdbcInterceptors(
                        QueryTimeoutInterceptor.class.getName()+
                        "(queryTimeout="+ interceptorTimeout +")");

    // because testOnBorrow is true, this triggers the validation query
    Connection con = this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);

    // increase the expected timeout to 30, which is what we set for the interceptor
    TIMEOUT = 30;

    // now create a statement, make sure the query timeout is set by the interceptor
    Statement st = con.createStatement();
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    con.close();

    // pull another connection and check it
    TIMEOUT = 10;
    isTimeoutSet = false;
    this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);
}
 
Example #4
Source File: TestQueryTimeoutInterceptor.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
@Test
public void testTimeout() throws Exception {
    int timeout = 10;
    int withoutuser =10;
    int withuser = withoutuser;
    this.datasource.setMaxActive(withuser+withoutuser);
    this.datasource.setJdbcInterceptors(QueryTimeoutInterceptor.class.getName()+"(queryTimeout="+timeout+")");
    this.datasource.setDriverClassName(Driver.class.getName());
    this.datasource.setUrl("jdbc:tomcat:test");
    Connection con = this.datasource.getConnection();
    Statement st = con.createStatement();
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(st.getClass().getName(),timeout,st.getQueryTimeout());
    st.close();
    con.close();
}
 
Example #5
Source File: TestValidationQueryTimeout.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@Test
public void testValidationQueryTimeoutWithQueryTimeoutInterceptor() throws Exception {
    int interceptorTimeout = 30;
    this.datasource.setJdbcInterceptors(
                        QueryTimeoutInterceptor.class.getName()+
                        "(queryTimeout="+ interceptorTimeout +")");

    // because testOnBorrow is true, this triggers the validation query
    Connection con = this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);

    // increase the expected timeout to 30, which is what we set for the interceptor
    TIMEOUT = 30;

    // now create a statement, make sure the query timeout is set by the interceptor
    Statement st = con.createStatement();
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    con.close();

    // pull another connection and check it
    TIMEOUT = 10;
    isTimeoutSet = false;
    this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);
}
 
Example #6
Source File: TestValidationQueryTimeout.java    From Tomcat7.0.67 with Apache License 2.0 5 votes vote down vote up
@Test
public void testValidationQueryTimeoutWithQueryTimeoutInterceptor() throws Exception {
    int interceptorTimeout = 30;
    this.datasource.setJdbcInterceptors(
                        QueryTimeoutInterceptor.class.getName()+
                        "(queryTimeout="+ interceptorTimeout +")");

    // because testOnBorrow is true, this triggers the validation query
    Connection con = this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);

    // increase the expected timeout to 30, which is what we set for the interceptor
    TIMEOUT = 30;

    // now create a statement, make sure the query timeout is set by the interceptor
    Statement st = con.createStatement();
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareStatement("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    st = con.prepareCall("");
    Assert.assertEquals(interceptorTimeout, st.getQueryTimeout());
    st.close();
    con.close();

    // pull another connection and check it
    TIMEOUT = 10;
    isTimeoutSet = false;
    this.datasource.getConnection();
    Assert.assertTrue(isTimeoutSet);
}