Java Code Examples for org.apache.commons.pool2.impl.GenericKeyedObjectPool#setTestOnBorrow()

The following examples show how to use org.apache.commons.pool2.impl.GenericKeyedObjectPool#setTestOnBorrow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeyedObjectPoolForTest.java    From x-pipe with Apache License 2.0 6 votes vote down vote up
@Override
protected void doInitialize() throws Exception {

    if (this.pooledObjectFactory == null) {
        this.pooledObjectFactory = new ObjectFactory();
    }

    GenericKeyedObjectPool<String, Object> genericKeyedObjectPool = new GenericKeyedObjectPool<String, Object>(
            pooledObjectFactory, config);
    genericKeyedObjectPool.setTestOnBorrow(true);
    genericKeyedObjectPool.setTestOnCreate(true);
    genericKeyedObjectPool.setSoftMinEvictableIdleTimeMillis(DEFAULT_SOFT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    genericKeyedObjectPool.setMinEvictableIdleTimeMillis(DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS);
    genericKeyedObjectPool.setTimeBetweenEvictionRunsMillis(DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS);
    this.objectPool = genericKeyedObjectPool;
}
 
Example 2
Source File: TestKeyedCPDSConnectionFactory.java    From commons-dbcp with Apache License 2.0 5 votes vote down vote up
/**
 * JIRA: DBCP-442
 */
@Test
public void testNullValidationQuery() throws Exception {
    final UserPassKey key = new UserPassKey("userName", "password");
    final KeyedCPDSConnectionFactory factory =
            new KeyedCPDSConnectionFactory(cpds, null, -1, false);
    final GenericKeyedObjectPool<UserPassKey, PooledConnectionAndInfo> pool = new GenericKeyedObjectPool<>(factory);
    factory.setPool(pool);
    pool.setTestOnBorrow(true);
    final PooledConnection pcon = pool.borrowObject(key).getPooledConnection();
    final Connection con = pcon.getConnection();
    con.close();
}