Example usage for org.apache.commons.pool PoolUtils prefill

List of usage examples for org.apache.commons.pool PoolUtils prefill

Introduction

In this page you can find the example usage for org.apache.commons.pool PoolUtils prefill.

Prototype

public static void prefill(final ObjectPool pool, final int count) throws Exception, IllegalArgumentException 

Source Link

Document

Call addObject() on pool count number of times.

Usage

From source file:edu.illinois.enforcemop.examples.apache.pool.TestGenericObjectPool.java

public void checkEvict(boolean lifo) throws Exception {
    // yea this is hairy but it tests all the code paths in GOP.evict()
    final SimpleFactory factory = new SimpleFactory();
    final GenericObjectPool pool = new GenericObjectPool(factory);
    pool.setSoftMinEvictableIdleTimeMillis(10);
    pool.setMinIdle(2);// w  w w  . j a  va 2s.c o m
    pool.setTestWhileIdle(true);
    pool.setLifo(lifo);
    PoolUtils.prefill(pool, 5);
    pool.evict();
    factory.setEvenValid(false);
    factory.setOddValid(false);
    factory.setThrowExceptionOnActivate(true);
    pool.evict();
    PoolUtils.prefill(pool, 5);
    factory.setThrowExceptionOnActivate(false);
    factory.setThrowExceptionOnPassivate(true);
    pool.evict();
    factory.setThrowExceptionOnPassivate(false);
    factory.setEvenValid(true);
    factory.setOddValid(true);
    Thread.sleep(125);
    pool.evict();
    assertEquals(2, pool.getNumIdle());
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java

public void testPOFClearUsages() throws Exception {
    final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
    final ObjectPool pool;
    try {//from   w  w w.  ja  v a2  s  .c o m
        pool = makeEmptyPool(factory);
    } catch (UnsupportedOperationException uoe) {
        return; // test not supported
    }
    final List expectedMethods = new ArrayList();

    /// Test correct behavior code paths
    PoolUtils.prefill(pool, 5);
    pool.clear();

    //// Test exception handling clear should swallow destory object failures
    reset(pool, factory, expectedMethods);
    factory.setDestroyObjectFail(true);
    PoolUtils.prefill(pool, 5);
    pool.clear();
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java

public void testPOFCloseUsages() throws Exception {
    final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
    ObjectPool pool;/*from  ww w.  ja va2s.c  om*/
    try {
        pool = makeEmptyPool(factory);
    } catch (UnsupportedOperationException uoe) {
        return; // test not supported
    }
    final List expectedMethods = new ArrayList();

    /// Test correct behavior code paths
    PoolUtils.prefill(pool, 5);
    pool.close();

    //// Test exception handling close should swallow failures
    try {
        pool = makeEmptyPool(factory);
    } catch (UnsupportedOperationException uoe) {
        return; // test not supported
    }
    reset(pool, factory, expectedMethods);
    factory.setDestroyObjectFail(true);
    PoolUtils.prefill(pool, 5);
    pool.close();
}