while (iter.hasNext()) { final K key = iter.next(); final TimerTask task = checkMinIdle(keyedPool, key, minIdle, period); tasks.put(key, task);
@Test public void testCheckMinIdleKeyedObjectPoolKeysNulls() throws Exception { try (@SuppressWarnings("unchecked") final KeyedObjectPool<Object,Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null)) { PoolUtils.checkMinIdle(pool, (Collection<?>) null, 1, 1); fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must not accept null keys."); } catch (final IllegalArgumentException iae) { // expected } try (@SuppressWarnings("unchecked") final KeyedObjectPool<Object,Object> pool = createProxy(KeyedObjectPool.class, (List<String>)null)) { PoolUtils.checkMinIdle(pool, (Collection<?>) Collections.emptyList(), 1, 1); } catch (final IllegalArgumentException iae) { fail("PoolUtils.checkMinIdle(KeyedObjectPool,Collection,int,long) must accept empty lists."); } }
keys.add("two"); final Map<String, TimerTask> tasks = PoolUtils.checkMinIdle(pool, keys, 1, CHECK_PERIOD);
@Test public void testCheckMinIdleObjectPool() throws Exception { try { PoolUtils.checkMinIdle(null, 1, 1); fail("PoolUtils.checkMinIdle(ObjectPool,,) must not allow null pool."); } catch (final IllegalArgumentException iae) { PoolUtils.checkMinIdle(pool, -1, 1); fail("PoolUtils.checkMinIdle(ObjectPool,,) must not accept negative min idle values."); } catch (final IllegalArgumentException iae) { final PooledObjectFactory<Object> pof = createProxy(PooledObjectFactory.class, calledMethods); try (final ObjectPool<Object> op = new GenericObjectPool<>(pof)) { PoolUtils.checkMinIdle(op, 2, 100); Thread.sleep(1000); assertEquals(2, op.getNumIdle()); try (@SuppressWarnings("unchecked") final ObjectPool<Object> pool = createProxy(ObjectPool.class, calledMethods)) { final TimerTask task = PoolUtils.checkMinIdle(pool, 1, CHECK_PERIOD); // checks minIdle immediately
@Test public void testCheckMinIdleKeyedObjectPool() throws Exception { try { PoolUtils.checkMinIdle(null, new Object(), 1, 1); fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not allow null pool."); } catch (final IllegalArgumentException iae) { PoolUtils.checkMinIdle(pool, (Object)null, 1, 1); fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept null keys."); } catch (final IllegalArgumentException iae) { PoolUtils.checkMinIdle(pool, new Object(), -1, 1); fail("PoolUtils.checkMinIdle(KeyedObjectPool,Object,int,long) must not accept negative min idle values."); } catch (final IllegalArgumentException iae) { try (final KeyedObjectPool<Object,Object> kop = new GenericKeyedObjectPool<>(kpof)) { PoolUtils.checkMinIdle(kop, key, 2, 100); Thread.sleep(400); assertEquals(2, kop.getNumIdle(key)); final KeyedObjectPool<Object, Object> pool = createProxy(KeyedObjectPool.class, calledMethods)) { final TimerTask task = PoolUtils.checkMinIdle(pool, key, 1, CHECK_PERIOD);
while (iter.hasNext()) { final K key = iter.next(); final TimerTask task = checkMinIdle(keyedPool, key, minIdle, period); tasks.put(key, task);