Example usage for org.apache.commons.pool.impl GenericKeyedObjectPool getTimeBetweenEvictionRunsMillis

List of usage examples for org.apache.commons.pool.impl GenericKeyedObjectPool getTimeBetweenEvictionRunsMillis

Introduction

In this page you can find the example usage for org.apache.commons.pool.impl GenericKeyedObjectPool getTimeBetweenEvictionRunsMillis.

Prototype

public synchronized long getTimeBetweenEvictionRunsMillis() 

Source Link

Document

Returns the number of milliseconds to sleep between runs of the idle object evictor thread.

Usage

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

public void testConstructors() {

    // Make constructor arguments all different from defaults
    int maxActive = 1;
    int maxIdle = 2;
    long maxWait = 3;
    int minIdle = 4;
    int maxTotal = 5;
    long minEvictableIdleTimeMillis = 6;
    int numTestsPerEvictionRun = 7;
    boolean testOnBorrow = true;
    boolean testOnReturn = true;
    boolean testWhileIdle = true;
    long timeBetweenEvictionRunsMillis = 8;
    byte whenExhaustedAction = GenericObjectPool.WHEN_EXHAUSTED_GROW;
    boolean lifo = false;

    GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_ACTIVE, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    GenericKeyedObjectPool.Config config = new GenericKeyedObjectPool.Config();
    config.lifo = lifo;/*from w w  w .j  av a 2s  . c o m*/
    config.maxActive = maxActive;
    config.maxIdle = maxIdle;
    config.minIdle = minIdle;
    config.maxTotal = maxTotal;
    config.maxWait = maxWait;
    config.minEvictableIdleTimeMillis = minEvictableIdleTimeMillis;
    config.numTestsPerEvictionRun = numTestsPerEvictionRun;
    config.testOnBorrow = testOnBorrow;
    config.testOnReturn = testOnReturn;
    config.testWhileIdle = testWhileIdle;
    config.timeBetweenEvictionRunsMillis = timeBetweenEvictionRunsMillis;
    config.whenExhaustedAction = whenExhaustedAction;
    pool = new GenericKeyedObjectPool(null, config);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(lifo, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_WAIT, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_WHEN_EXHAUSTED_ACTION, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, testOnBorrow,
            testOnReturn);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_IDLE, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_BORROW, pool.getTestOnBorrow());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_ON_RETURN, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, testOnBorrow,
            testOnReturn);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,
            pool.getMinEvictableIdleTimeMillis());
    assertEquals(GenericKeyedObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TEST_WHILE_IDLE, pool.getTestWhileIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,
            pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, testOnBorrow,
            testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun, minEvictableIdleTimeMillis,
            testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MAX_TOTAL, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(GenericKeyedObjectPool.DEFAULT_MIN_IDLE, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, minIdle,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(GenericKeyedObjectPool.DEFAULT_LIFO, pool.getLifo());

    pool = new GenericKeyedObjectPool(null, maxActive, whenExhaustedAction, maxWait, maxIdle, maxTotal, minIdle,
            testOnBorrow, testOnReturn, timeBetweenEvictionRunsMillis, numTestsPerEvictionRun,
            minEvictableIdleTimeMillis, testWhileIdle, lifo);
    assertEquals(maxActive, pool.getMaxActive());
    assertEquals(maxIdle, pool.getMaxIdle());
    assertEquals(maxWait, pool.getMaxWait());
    assertEquals(minIdle, pool.getMinIdle());
    assertEquals(maxTotal, pool.getMaxTotal());
    assertEquals(minEvictableIdleTimeMillis, pool.getMinEvictableIdleTimeMillis());
    assertEquals(numTestsPerEvictionRun, pool.getNumTestsPerEvictionRun());
    assertEquals(testOnBorrow, pool.getTestOnBorrow());
    assertEquals(testOnReturn, pool.getTestOnReturn());
    assertEquals(testWhileIdle, pool.getTestWhileIdle());
    assertEquals(timeBetweenEvictionRunsMillis, pool.getTimeBetweenEvictionRunsMillis());
    assertEquals(whenExhaustedAction, pool.getWhenExhaustedAction());
    assertEquals(lifo, pool.getLifo());
}

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

public void testSettersAndGetters() throws Exception {
    GenericKeyedObjectPool pool = new GenericKeyedObjectPool();
    {/*  ww  w.ja v a 2 s .  c o m*/
        pool.setFactory(new SimpleFactory());
    }
    {
        pool.setMaxActive(123);
        assertEquals(123, pool.getMaxActive());
    }
    {
        pool.setMaxIdle(12);
        assertEquals(12, pool.getMaxIdle());
    }
    {
        pool.setMaxWait(1234L);
        assertEquals(1234L, pool.getMaxWait());
    }
    {
        pool.setMinEvictableIdleTimeMillis(12345L);
        assertEquals(12345L, pool.getMinEvictableIdleTimeMillis());
    }
    {
        pool.setNumTestsPerEvictionRun(11);
        assertEquals(11, pool.getNumTestsPerEvictionRun());
    }
    {
        pool.setTestOnBorrow(true);
        assertTrue(pool.getTestOnBorrow());
        pool.setTestOnBorrow(false);
        assertTrue(!pool.getTestOnBorrow());
    }
    {
        pool.setTestOnReturn(true);
        assertTrue(pool.getTestOnReturn());
        pool.setTestOnReturn(false);
        assertTrue(!pool.getTestOnReturn());
    }
    {
        pool.setTestWhileIdle(true);
        assertTrue(pool.getTestWhileIdle());
        pool.setTestWhileIdle(false);
        assertTrue(!pool.getTestWhileIdle());
    }
    {
        pool.setTimeBetweenEvictionRunsMillis(11235L);
        assertEquals(11235L, pool.getTimeBetweenEvictionRunsMillis());
    }
    {
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_BLOCK);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_BLOCK, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_FAIL, pool.getWhenExhaustedAction());
        pool.setWhenExhaustedAction(GenericKeyedObjectPool.WHEN_EXHAUSTED_GROW);
        assertEquals(GenericObjectPool.WHEN_EXHAUSTED_GROW, pool.getWhenExhaustedAction());
    }
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
@SuppressWarnings("unchecked")
public void verifyParsePoolingValidationSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-pooling-test-specified.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource,
            "keyedObjectPool");
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPoolableObjectFactory");
    DefaultDirContextValidator validator = (DefaultDirContextValidator) getInternalState(objectFactory,
            "dirContextValidator");
    assertThat(validator.getBase()).isEqualTo("ou=test");
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");

    SearchControls searchControls = ctx.getBean(SearchControls.class);
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");
    assertThat(validator.getSearchControls()).isSameAs(searchControls);

    Set<Class<? extends Throwable>> nonTransientExceptions = (Set<Class<? extends Throwable>>) getInternalState(
            objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(2);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
    assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
public void verifyParsePooling2Defaults() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-pooling2-defaults.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();
    assertThat(outerContextSource instanceof TransactionAwareContextSourceProxy).isTrue();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();
    assertThat(pooledContextSource instanceof PooledContextSource).isTrue();
    assertThat(getInternalState(pooledContextSource, "poolConfig")).isNotNull();

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
    assertThat(getInternalState(objectFactory, "contextSource")).isNotNull();
    assertThat(getInternalState(objectFactory, "dirContextValidator")).isNull();
    Set<Class<? extends Throwable>> nonTransientExceptions = (Set<Class<? extends Throwable>>) getInternalState(
            objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(1);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(
            pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(8);
    assertThat(objectPool.getMaxTotal()).isEqualTo(-1);
    assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(8);
    assertThat(objectPool.getMinIdlePerKey()).isEqualTo(0);
    assertThat(objectPool.getBlockWhenExhausted()).isEqualTo(true);
    assertThat(objectPool.getEvictionPolicyClassName())
            .isEqualTo(GenericKeyedObjectPoolConfig.DEFAULT_EVICTION_POLICY_CLASS_NAME);
    assertThat(objectPool.getFairness()).isEqualTo(false);

    // ensures the pool is registered
    ObjectName oname = objectPool.getJmxName();
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    Set<ObjectName> result = mbs.queryNames(oname, null);
    assertThat(result).hasSize(1);// www .  j  a  va  2  s .  c  o m

    assertThat(objectPool.getLifo()).isEqualTo(true);
    assertThat(objectPool.getMaxWaitMillis()).isEqualTo(-1L);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(1000L * 60L * 30L);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(3);
    assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(-1L);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(-1L);
    assertThat(objectPool.getTestOnBorrow()).isEqualTo(false);
    assertThat(objectPool.getTestOnCreate()).isEqualTo(false);
    assertThat(objectPool.getTestOnReturn()).isEqualTo(false);
    assertThat(objectPool.getTestWhileIdle()).isEqualTo(false);
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
public void verifyParsePool2ValidationSet() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-pool2-test-specified.xml");

    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(
            pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(123);
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(321);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(22);
    assertThat(objectPool.getSoftMinEvictableIdleTimeMillis()).isEqualTo(12);

    assertThat(objectPool.getTestOnBorrow()).isEqualTo(true);
    assertThat(objectPool.getTestOnReturn()).isEqualTo(true);
    assertThat(objectPool.getTestOnCreate()).isEqualTo(true);
    assertThat(objectPool.getTestWhileIdle()).isEqualTo(true);

    Object objectFactory = getInternalState(pooledContextSource, "dirContextPooledObjectFactory");
    org.springframework.ldap.pool2.validation.DefaultDirContextValidator validator = (org.springframework.ldap.pool2.validation.DefaultDirContextValidator) getInternalState(
            objectFactory, "dirContextValidator");
    assertThat(validator.getBase()).isEqualTo("ou=test");
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");

    SearchControls searchControls = ctx.getBean(SearchControls.class);
    assertThat(validator.getFilter()).isEqualTo("objectclass=person");
    assertThat(validator.getSearchControls()).isSameAs(searchControls);

    Set<Class<? extends Throwable>> nonTransientExceptions = (Set<Class<? extends Throwable>>) getInternalState(
            objectFactory, "nonTransientExceptions");
    assertThat(nonTransientExceptions).hasSize(2);
    assertThat(nonTransientExceptions.contains(CommunicationException.class)).isTrue();
    assertThat(nonTransientExceptions.contains(CannotProceedException.class)).isTrue();
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
public void verifyParsePoolWithPlaceholders() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-pooling-config-with-placeholders.xml");
    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    GenericKeyedObjectPool objectPool = (GenericKeyedObjectPool) getInternalState(pooledContextSource,
            "keyedObjectPool");
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
    assertThat(objectPool.getMaxWait()).isEqualTo(10);
    assertThat(objectPool.getMaxTotal()).isEqualTo(11);
    assertThat(objectPool.getMaxActive()).isEqualTo(15);
    assertThat(objectPool.getMinIdle()).isEqualTo(16);
    assertThat(objectPool.getMaxIdle()).isEqualTo(17);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}

From source file:org.springframework.ldap.config.LdapTemplateNamespaceHandlerTest.java

@Test
public void verifyParsePool2WithPlaceholders() {
    ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext(
            "/ldap-namespace-config-pooling2-config-with-placeholders.xml");
    ContextSource outerContextSource = ctx.getBean(ContextSource.class);
    assertThat(outerContextSource).isNotNull();

    ContextSource pooledContextSource = ((TransactionAwareContextSourceProxy) outerContextSource).getTarget();
    assertThat(pooledContextSource).isNotNull();

    org.apache.commons.pool2.impl.GenericKeyedObjectPool objectPool = (org.apache.commons.pool2.impl.GenericKeyedObjectPool) getInternalState(
            pooledContextSource, "keyedObjectPool");
    assertThat(objectPool.getTimeBetweenEvictionRunsMillis()).isEqualTo(10);
    assertThat(objectPool.getMinEvictableIdleTimeMillis()).isEqualTo(20);
    assertThat(objectPool.getMaxWaitMillis()).isEqualTo(10);
    assertThat(objectPool.getMaxTotal()).isEqualTo(11);
    assertThat(objectPool.getMinIdlePerKey()).isEqualTo(12);
    assertThat(objectPool.getMaxIdlePerKey()).isEqualTo(13);
    assertThat(objectPool.getMaxTotalPerKey()).isEqualTo(14);
    assertThat(objectPool.getNumTestsPerEvictionRun()).isEqualTo(18);
}