use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class TestPStmtPooling method testClosePool.
@Test
public void testClosePool() throws Exception {
DriverManager.registerDriver(new TesterDriver());
final ConnectionFactory connFactory = new DriverManagerConnectionFactory("jdbc:apache:commons:testdriver", "u1", "p1");
final PoolableConnectionFactory pcf = new PoolableConnectionFactory(connFactory, null);
pcf.setPoolStatements(true);
pcf.setDefaultReadOnly(Boolean.FALSE);
pcf.setDefaultAutoCommit(Boolean.TRUE);
final ObjectPool<PoolableConnection> connPool = new GenericObjectPool<>(pcf);
pcf.setPool(connPool);
final PoolingDataSource<?> ds = new PoolingDataSource<>(connPool);
((PoolingDataSource<?>) ds).setAccessToUnderlyingConnectionAllowed(true);
final Connection conn = ds.getConnection();
try (Statement s = conn.prepareStatement("select 1 from dual")) {
}
final Connection poolableConnection = ((DelegatingConnection<?>) conn).getDelegate();
final Connection poolingConnection = ((DelegatingConnection<?>) poolableConnection).getDelegate();
poolingConnection.close();
try (PreparedStatement ps = conn.prepareStatement("select 1 from dual")) {
fail("Expecting SQLException");
} catch (final SQLException ex) {
assertTrue(ex.getMessage().endsWith("invalid PoolingConnection."));
}
ds.close();
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project commons-dbcp by apache.
the class TestPoolingDataSource method testClose.
@Test
public void testClose() throws Exception {
final Properties properties = new Properties();
properties.setProperty(Constants.KEY_USER, "userName");
properties.setProperty(Constants.KEY_PASSWORD, "password");
final PoolableConnectionFactory f = new PoolableConnectionFactory(new DriverConnectionFactory(new TesterDriver(), "jdbc:apache:commons:testdriver", properties), null);
f.setValidationQuery("SELECT DUMMY FROM DUAL");
f.setDefaultReadOnly(Boolean.TRUE);
f.setDefaultAutoCommit(Boolean.TRUE);
final GenericObjectPool<PoolableConnection> p = new GenericObjectPool<>(f);
p.setMaxTotal(getMaxTotal());
p.setMaxWait(getMaxWaitDuration());
try (PoolingDataSource<PoolableConnection> dataSource = new PoolingDataSource<>(p)) {
final Connection connection = dataSource.getConnection();
assertNotNull(connection);
connection.close();
}
assertTrue(p.isClosed());
assertEquals(0, p.getNumIdle());
assertEquals(0, p.getNumActive());
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project interlok by adaptris.
the class WorkflowWithObjectPoolTest method testPopulatePool_FailToInit.
@Test(expected = CoreException.class)
public void testPopulatePool_FailToInit() throws Exception {
setMinIdle(10);
setServiceCollection(new ServiceList(new MockService(MockService.FailureCondition.Lifecycle)));
setInitWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
GenericObjectPool<Worker> pool = (GenericObjectPool<Worker>) createObjectPool();
try {
populatePool(pool);
} finally {
Closer.closeQuietly(pool);
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project interlok by adaptris.
the class WorkflowWithObjectPoolTest method testPopulatePool.
@Test
public void testPopulatePool() throws Exception {
setMinIdle(10);
setInitWaitTime(new TimeInterval(1L, TimeUnit.SECONDS));
GenericObjectPool<Worker> pool = (GenericObjectPool<Worker>) createObjectPool();
try {
populatePool(pool);
} finally {
Closer.closeQuietly(pool);
}
}
use of com.frameworkset.commons.pool2.impl.GenericObjectPool in project spring-framework-5.2.9.RELEASE by somepeopleHavingDream.
the class CommonsPool2TargetSource method createObjectPool.
/**
* Subclasses can override this if they want to return a specific Commons pool.
* They should apply any configuration properties to the pool here.
* <p>Default is a GenericObjectPool instance with the given pool size.
* @return an empty Commons {@code ObjectPool}.
* @see GenericObjectPool
* @see #setMaxSize
*/
protected ObjectPool createObjectPool() {
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(getMaxSize());
config.setMaxIdle(getMaxIdle());
config.setMinIdle(getMinIdle());
config.setMaxWaitMillis(getMaxWait());
config.setTimeBetweenEvictionRunsMillis(getTimeBetweenEvictionRunsMillis());
config.setMinEvictableIdleTimeMillis(getMinEvictableIdleTimeMillis());
config.setBlockWhenExhausted(isBlockWhenExhausted());
return new GenericObjectPool(this, config);
}
Aggregations