Search in sources :

Example 81 with Connection

use of java.sql.Connection in project tomcat by apache.

the class TestSuspectTimeout method testSuspect.

@Test
public void testSuspect() throws Exception {
    this.datasource.setMaxActive(100);
    this.datasource.setMaxIdle(100);
    this.datasource.setInitialSize(0);
    this.datasource.getPoolProperties().setAbandonWhenPercentageFull(0);
    this.datasource.getPoolProperties().setTimeBetweenEvictionRunsMillis(100);
    this.datasource.getPoolProperties().setRemoveAbandoned(true);
    this.datasource.getPoolProperties().setRemoveAbandonedTimeout(100);
    this.datasource.getPoolProperties().setSuspectTimeout(1);
    this.datasource.getPoolProperties().setLogAbandoned(true);
    Connection con = datasource.getConnection();
    Assert.assertEquals("Number of connections active/busy should be 1", 1, datasource.getPool().getActive());
    Thread.sleep(3000);
    PooledConnection pcon = con.unwrap(PooledConnection.class);
    Assert.assertTrue("Connection should be marked suspect", pcon.isSuspect());
    con.close();
}
Also used : PooledConnection(org.apache.tomcat.jdbc.pool.PooledConnection) Connection(java.sql.Connection) PooledConnection(org.apache.tomcat.jdbc.pool.PooledConnection) Test(org.junit.Test)

Example 82 with Connection

use of java.sql.Connection in project tomcat by apache.

the class EqualsHashCodeTest method testEquals.

@Test
public void testEquals() throws Exception {
    Connection con1 = datasource.getConnection();
    Connection real1 = ((PooledConnection) con1).getConnection();
    Assert.assertEquals(con1, con1);
    con1.close();
    Assert.assertEquals(con1, con1);
    Connection con2 = datasource.getConnection();
    Connection real2 = ((PooledConnection) con2).getConnection();
    Assert.assertEquals(real1, real2);
    Assert.assertEquals(con2, con2);
    Assert.assertNotSame(con1, con2);
    con2.close();
    Assert.assertEquals(con2, con2);
}
Also used : PooledConnection(javax.sql.PooledConnection) Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) Test(org.junit.Test)

Example 83 with Connection

use of java.sql.Connection in project tomcat by apache.

the class EqualsHashCodeTest method testHashCode.

@Test
public void testHashCode() throws Exception {
    Connection con1 = datasource.getConnection();
    Assert.assertEquals(con1.hashCode(), con1.hashCode());
    con1.close();
    Assert.assertEquals(con1.hashCode(), con1.hashCode());
    Connection con2 = datasource.getConnection();
    Assert.assertEquals(con2.hashCode(), con2.hashCode());
    Assert.assertTrue(con1.hashCode() != con2.hashCode());
    con2.close();
    Assert.assertEquals(con2.hashCode(), con2.hashCode());
}
Also used : Connection(java.sql.Connection) PooledConnection(javax.sql.PooledConnection) Test(org.junit.Test)

Example 84 with Connection

use of java.sql.Connection in project tomcat by apache.

the class TestConnectionState method testAutoCommitTrue.

@Test
public void testAutoCommitTrue() throws Exception {
    DataSourceProxy d1 = this.createDefaultDataSource();
    d1.setMaxActive(1);
    d1.setJdbcInterceptors(ConnectionState.class.getName());
    d1.setDefaultAutoCommit(Boolean.TRUE);
    d1.setMinIdle(1);
    Connection c1 = d1.getConnection();
    Assert.assertTrue("Auto commit should be true", c1.getAutoCommit());
    c1.setAutoCommit(false);
    Assert.assertFalse("Auto commit should be false", c1.getAutoCommit());
    c1.close();
    c1 = d1.getConnection();
    Assert.assertTrue("Auto commit should be true for a reused connection", c1.getAutoCommit());
}
Also used : DataSourceProxy(org.apache.tomcat.jdbc.pool.DataSourceProxy) Connection(java.sql.Connection) ConnectionState(org.apache.tomcat.jdbc.pool.interceptor.ConnectionState) Test(org.junit.Test)

Example 85 with Connection

use of java.sql.Connection in project tomcat by apache.

the class TestException method testException.

@Test
public void testException() throws Exception {
    datasource.getPoolProperties().setJdbcInterceptors(TestInterceptor.class.getName());
    Connection con = datasource.getConnection();
    try {
        con.createStatement();
    } catch (Exception x) {
    // Ignore
    }
}
Also used : Connection(java.sql.Connection) PooledConnection(org.apache.tomcat.jdbc.pool.PooledConnection) Test(org.junit.Test)

Aggregations

Connection (java.sql.Connection)6326 PreparedStatement (java.sql.PreparedStatement)2793 ResultSet (java.sql.ResultSet)2657 Test (org.junit.Test)2455 SQLException (java.sql.SQLException)2267 Properties (java.util.Properties)1188 Statement (java.sql.Statement)1078 PhoenixConnection (org.apache.phoenix.jdbc.PhoenixConnection)689 ArrayList (java.util.ArrayList)397 BaseConnectionlessQueryTest (org.apache.phoenix.query.BaseConnectionlessQueryTest)232 DataSource (javax.sql.DataSource)211 BaseTest (org.apache.phoenix.query.BaseTest)201 CallableStatement (java.sql.CallableStatement)192 IOException (java.io.IOException)158 Reader (java.io.Reader)144 DatabaseMetaData (java.sql.DatabaseMetaData)144 SqlSessionFactoryBuilder (org.apache.ibatis.session.SqlSessionFactoryBuilder)134 HashMap (java.util.HashMap)123 ScriptRunner (org.apache.ibatis.jdbc.ScriptRunner)114 Timestamp (java.sql.Timestamp)113