use of javax.sql.PooledConnection in project geode by apache.
the class AbstractPoolCacheJUnitTest method testValidateConnection.
/**
* Test of validateConnection method, of class
* org.apache.geode.internal.datasource.AbstractPoolCache.
*/
@Test
public void testValidateConnection() throws Exception {
Context ctx = cache.getJNDIContext();
GemFireConnPooledDataSource ds = (GemFireConnPooledDataSource) ctx.lookup("java:/PooledDataSource");
GemFireConnectionPoolManager provider = (GemFireConnectionPoolManager) ds.getConnectionProvider();
ConnectionPoolCacheImpl poolCache = (ConnectionPoolCacheImpl) provider.getConnectionPoolCache();
PooledConnection poolConn = (PooledConnection) poolCache.getPooledConnectionFromPool();
Connection conn = poolConn.getConnection();
if (!ds.validateConnection(conn))
fail("validate connection failed");
conn.close();
if (ds.validateConnection(conn))
fail("validate connection failed");
}
use of javax.sql.PooledConnection in project geode by apache.
the class AbstractPoolCacheJUnitTest method testReturnPooledConnectionToPool.
/**
* Test of returnPooledConnectionToPool method, of class
* org.apache.geode.internal.datasource.AbstractPoolCache.
*/
@Test
public void testReturnPooledConnectionToPool() throws Exception {
Context ctx = cache.getJNDIContext();
GemFireConnPooledDataSource ds = (GemFireConnPooledDataSource) ctx.lookup("java:/PooledDataSource");
GemFireConnectionPoolManager provider = (GemFireConnectionPoolManager) ds.getConnectionProvider();
ConnectionPoolCacheImpl poolCache = (ConnectionPoolCacheImpl) provider.getConnectionPoolCache();
PooledConnection conn = (PooledConnection) poolCache.getPooledConnectionFromPool();
if (poolCache.availableCache.containsKey(conn))
fail("connection not removed from available cache list");
if (!poolCache.activeCache.containsKey(conn))
fail("connection not put in active connection list");
provider.returnConnection(conn);
if (!poolCache.availableCache.containsKey(conn))
fail("connection not returned to pool");
if (poolCache.activeCache.containsKey(conn))
fail("connection not returned to active list");
}
use of javax.sql.PooledConnection in project geode by apache.
the class AbstractPoolCacheJUnitTest method testGetPooledConnectionFromPool.
/**
* Test of getPooledConnectionFromPool method, of class
* org.apache.geode.internal.datasource.AbstractPoolCache.
*/
@Test
public void testGetPooledConnectionFromPool() throws Exception {
Context ctx = cache.getJNDIContext();
GemFireConnPooledDataSource ds = (GemFireConnPooledDataSource) ctx.lookup("java:/PooledDataSource");
GemFireConnectionPoolManager provider = (GemFireConnectionPoolManager) ds.getConnectionProvider();
ConnectionPoolCacheImpl poolCache = (ConnectionPoolCacheImpl) provider.getConnectionPoolCache();
PooledConnection poolConn = (PooledConnection) poolCache.getPooledConnectionFromPool();
if (poolConn == null)
fail("getPooledConnectionFromPool failed to get a connection from pool");
}
use of javax.sql.PooledConnection in project cdap by caskdata.
the class DBConnectionPoolManager method getValidConnection2.
// CHECKSTYLE ON
private Connection getValidConnection2(long time, long timeoutTime) {
long rtime = Math.max(1, timeoutTime - time);
Connection conn;
try {
conn = getConnection2(rtime);
} catch (SQLException e) {
return null;
}
rtime = timeoutTime - System.currentTimeMillis();
int rtimeSecs = Math.max(1, (int) ((rtime + 999) / 1000));
try {
if (conn.isValid(rtimeSecs)) {
return conn;
}
} catch (SQLException e) {
}
// This Exception should never occur. If it nevertheless occurs,
// it's because of an error in the JDBC driver which we ignore and assume
// that the connection is not valid. When isValid() returns false, the JDBC
// driver should have already called connectionErrorOccurred()
// and the PooledConnection has been removed from the pool, i.e. the
// PooledConnection will not be added to recycledConnections when
// Connection.close() is called. But to be sure that this works even with
// a faulty JDBC driver, we call purgeConnection().
purgeConnection(conn);
return null;
}
use of javax.sql.PooledConnection in project cdap by caskdata.
the class DBConnectionPoolManager method getConnection3.
private synchronized Connection getConnection3() throws SQLException {
// test again within synchronized lock
if (isDisposed) {
throw new IllegalStateException("Connection pool has been disposed.");
}
PooledConnection pconn;
if (!recycledConnections.isEmpty()) {
pconn = recycledConnections.remove();
} else {
pconn = dataSource.getPooledConnection();
pconn.addConnectionEventListener(poolConnectionEventListener);
}
Connection conn;
try {
// The JDBC driver may call ConnectionEventListener.connectionErrorOccurred()
// from within PooledConnection.getConnection(). To detect this within
// disposeConnection(), we temporarily set connectionInTransition.
connectionInTransition = pconn;
conn = pconn.getConnection();
} finally {
connectionInTransition = null;
}
activeConnections++;
assertInnerState();
return conn;
}
Aggregations