/** * Closes the underlying {@code ObjectPool} when destroying this object. */ @Override public void destroy() throws Exception { if (this.pool != null) { logger.debug("Closing Commons ObjectPool"); this.pool.close(); } }
/** * {@inheritDoc} */ @Override public void close() { try { pool.close(); } catch (final Exception e) { // swallowed } }
@Override public void close() { pool.close(); }
/** * {@inheritDoc} */ @Override public void close() { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { pool.close(); } catch (final Exception e) { // swallowed as of Pool 2 } finally { writeLock.unlock(); } }
@Test(expected=IllegalStateException.class) public void testPassThroughMethods02() throws Exception { pool.close(); pool.addObject(); }
@Test public void testToString() throws Exception { ObjectPool<Object> pool; try { pool = makeEmptyPool(new MethodCallPoolableObjectFactory()); } catch (final UnsupportedOperationException uoe) { return; // test not supported } pool.toString(); pool.close(); }
private static List<String> invokeEveryMethod(final ObjectPool<Object> op) throws Exception { op.addObject(); op.borrowObject(); op.clear(); op.close(); op.getNumActive(); op.getNumIdle(); op.invalidateObject(new Object()); op.returnObject(new Object()); op.toString(); final List<String> expectedMethods = Arrays.asList(new String[] { "addObject", "borrowObject", "clear", "close", "getNumActive", "getNumIdle", "invalidateObject", "returnObject", "toString" }); return expectedMethods; }
@Test public void testPOFCloseUsages() throws Exception { final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory(); ObjectPool<Object> pool; try { pool = makeEmptyPool(factory); } catch (final UnsupportedOperationException uoe) { return; // test not supported } final List<MethodCall> 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 (final UnsupportedOperationException uoe) { return; // test not supported } reset(pool, factory, expectedMethods); factory.setDestroyObjectFail(true); PoolUtils.prefill(pool, 5); pool.close(); }
@Test public void testBaseClosePool() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } final String obj = _pool.borrowObject(); _pool.returnObject(obj); _pool.close(); try { _pool.borrowObject(); fail("Expected IllegalStateException"); } catch(final IllegalStateException e) { // expected } }
@Test public void testPOFClearUsages() throws Exception { final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory(); final ObjectPool<Object> pool; try { pool = makeEmptyPool(factory); } catch (final UnsupportedOperationException uoe) { return; // test not supported } final List<MethodCall> 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(); pool.close(); }
@Test public void testBaseBorrow() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(getNthObject(0),_pool.borrowObject()); assertEquals(getNthObject(1),_pool.borrowObject()); assertEquals(getNthObject(2),_pool.borrowObject()); _pool.close(); }
removeDestroyObjectCall(factory.getMethodCalls()); assertEquals(expectedMethods, factory.getMethodCalls()); pool.close();
factory.setDestroyObjectFail(true); pool.returnObject(obj); pool.close();
@Test public void testBaseInvalidateObject() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj0 = _pool.borrowObject(); final String obj1 = _pool.borrowObject(); assertEquals(2,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.invalidateObject(obj0); assertEquals(1,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.invalidateObject(obj1); assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.close(); }
@Test public void testBaseAddObject() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } try { assertEquals(0,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); _pool.addObject(); assertEquals(1,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); final String obj = _pool.borrowObject(); assertEquals(getNthObject(0),obj); assertEquals(0,_pool.getNumIdle()); assertEquals(1,_pool.getNumActive()); _pool.returnObject(obj); assertEquals(1,_pool.getNumIdle()); assertEquals(0,_pool.getNumActive()); } catch(final UnsupportedOperationException e) { return; // skip this test if one of those calls is unsupported } finally { _pool.close(); } }
@Test public void testBaseNumActiveNumIdle() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj0 = _pool.borrowObject(); assertEquals(1,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj1 = _pool.borrowObject(); assertEquals(2,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.returnObject(obj1); assertEquals(1,_pool.getNumActive()); assertEquals(1,_pool.getNumIdle()); _pool.returnObject(obj0); assertEquals(0,_pool.getNumActive()); assertEquals(2,_pool.getNumIdle()); _pool.close(); }
@Test public void testBaseClear() throws Exception { try { _pool = makeEmptyPool(3); } catch(final UnsupportedOperationException e) { return; // skip this test if unsupported } assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final String obj0 = _pool.borrowObject(); final String obj1 = _pool.borrowObject(); assertEquals(2,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); _pool.returnObject(obj1); _pool.returnObject(obj0); assertEquals(0,_pool.getNumActive()); assertEquals(2,_pool.getNumIdle()); _pool.clear(); assertEquals(0,_pool.getNumActive()); assertEquals(0,_pool.getNumIdle()); final Object obj2 = _pool.borrowObject(); assertEquals(getNthObject(2),obj2); _pool.close(); }
assertEquals(getNthObject(2),obj0); _pool.close();