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

The following examples show how to use org.apache.tomcat.jdbc.pool.interceptor.QueryTimeoutInterceptor. 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: TestQueryTimeoutInterceptor.java    License: 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 Project: Tomcat7.0.67   Source File: TestQueryTimeoutInterceptor.java    License: 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 Project: tomcatsrc   Source File: TestQueryTimeoutInterceptor.java    License: 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 4
Source Project: Tomcat8-Source-Read   Source File: TestValidationQueryTimeout.java    License: 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 5
Source Project: Tomcat7.0.67   Source File: TestValidationQueryTimeout.java    License: 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);
}
 
Example 6
Source Project: tomcatsrc   Source File: TestValidationQueryTimeout.java    License: 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);
}