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();
}
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);
}
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());
}
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());
}
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
}
}
Aggregations