List of usage examples for org.apache.commons.pool KeyedObjectPool clear
void clear(Object key) throws Exception, UnsupportedOperationException;
key
(optional operation). From source file:edu.illinois.enforcemop.examples.apache.pool.TestKeyedObjectPool.java
public void testClosedPoolBehavior() throws Exception { final KeyedObjectPool pool; try {/*from w w w . jav a 2 s. c o m*/ pool = makeEmptyPool(new BaseKeyedPoolableObjectFactory() { public Object makeObject(final Object key) throws Exception { return new Object(); } }); } catch (UnsupportedOperationException uoe) { return; // test not supported } Object o1 = pool.borrowObject(KEY); Object o2 = pool.borrowObject(KEY); pool.close(); try { pool.addObject(KEY); fail("A closed pool must throw an IllegalStateException when addObject is called."); } catch (IllegalStateException ise) { // expected } try { pool.borrowObject(KEY); fail("A closed pool must throw an IllegalStateException when borrowObject is called."); } catch (IllegalStateException ise) { // expected } // The following should not throw exceptions just because the pool is closed. assertEquals("A closed pool shouldn't have any idle objects.", 0, pool.getNumIdle(KEY)); assertEquals("A closed pool shouldn't have any idle objects.", 0, pool.getNumIdle()); pool.getNumActive(); pool.getNumActive(KEY); pool.returnObject(KEY, o1); assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle(KEY)); assertEquals("returnObject should not add items back into the idle object pool for a closed pool.", 0, pool.getNumIdle()); pool.invalidateObject(KEY, o2); pool.clear(KEY); pool.clear(); pool.close(); }