use of org.apache.tomcat.jdbc.pool.PooledConnection 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 org.apache.tomcat.jdbc.pool.PooledConnection in project dal by ctripcorp.
the class DalConnection method markDiscard.
private void markDiscard(Connection conn) throws SQLException {
PooledConnection pConn = (PooledConnection) conn.unwrap(PooledConnection.class);
pConn.setDiscarded(true);
}
use of org.apache.tomcat.jdbc.pool.PooledConnection in project dal by ctripcorp.
the class ConnectionActionTest method testCleanupCloseConnection.
@Test
public void testCleanupCloseConnection() {
SQLException e1 = new SQLException("test discard", "1234");
e1.setNextException(new SQLException("test discard", "08006"));
SQLException e2 = new SQLException("test discard", "1234");
e2.setNextException(new SQLException("test discard", "08S01"));
Exception[] el = new Exception[] { // Case 1 detect direct SQLException
new SQLException("test discard", "08006"), // Case 2 detect embedded SQLException wrapped by DalException
new DalException("test discard", new SQLException("test discard", "08006")), // Case 3 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", new SQLException("test discard", "08006")), // Case 4 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", e1), // Case 1 detect direct SQLException
new SQLException("test discard", "08006"), // Case 2 detect embedded SQLException wrapped by DalException
new DalException("test discard", new SQLException("test discard", "08006")), // Case 3 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", new SQLException("test discard", "08006")), // Case 4 detect embedded SQLException wrapped by NullPinterException
new RuntimeException("test discard", e2) };
for (Exception e : el) {
try {
TestConnectionAction test = new TestConnectionAction();
DalConnection connHolder = getDalConnection();
test.connHolder = connHolder;
test.statement = test.connHolder.getConn().createStatement();
test.rs = test.statement.executeQuery("select * from " + SqlServerTestInitializer.TABLE_NAME);
test.rs.next();
PooledConnection c = (PooledConnection) connHolder.getConn().unwrap(PooledConnection.class);
connHolder.error(e);
test.cleanup();
assertTrue(c.isDiscarded());
assertTrue(c.isReleased());
assertNotNull(test);
assertTrue(test.conn == null);
assertTrue(test.statement == null);
assertTrue(test.rs == null);
assertTrue(test.connHolder == null);
} catch (Exception ex) {
ex.printStackTrace();
fail("There should be no exception here");
}
}
}
use of org.apache.tomcat.jdbc.pool.PooledConnection in project dal by ctripcorp.
the class ConnectionActionTest method testCleanupCloseConnectionNegative.
@Test
public void testCleanupCloseConnectionNegative() {
try {
TestConnectionAction test = new TestConnectionAction();
DalConnection connHolder = getDalConnection();
test.connHolder = connHolder;
test.statement = test.connHolder.getConn().createStatement();
test.rs = test.statement.executeQuery("select * from " + SqlServerTestInitializer.TABLE_NAME);
test.rs.next();
PooledConnection c = (PooledConnection) connHolder.getConn().unwrap(PooledConnection.class);
connHolder.error(new NullPointerException("0800"));
test.cleanup();
assertTrue(!c.isDiscarded());
assertTrue(!c.isReleased());
assertNotNull(test);
assertTrue(test.conn == null);
assertTrue(test.statement == null);
assertTrue(test.rs == null);
assertTrue(test.connHolder == null);
} catch (Exception ex) {
ex.printStackTrace();
fail("There should be no exception here");
}
}
use of org.apache.tomcat.jdbc.pool.PooledConnection in project tomcat by apache.
the class ResetAbandonedTimer method resetTimer.
public boolean resetTimer() {
boolean result = false;
JdbcInterceptor interceptor = this.getNext();
while (interceptor != null && result == false) {
if (interceptor instanceof ProxyConnection) {
PooledConnection con = ((ProxyConnection) interceptor).getConnection();
if (con != null) {
con.setTimestamp(System.currentTimeMillis());
result = true;
} else {
break;
}
}
interceptor = interceptor.getNext();
}
return result;
}
Aggregations