/** * {@inheritDoc} */ @Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { pool.addObject(); }
@Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { pool.addObject(); }
/** * {@inheritDoc} */ @Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { pool.addObject(); } finally { writeLock.unlock(); } }
/** * Calls {@link ObjectPool#addObject()} on <code>pool</code> <code>count</code> * number of times. * * @param pool * the pool to prefill. * @param count * the number of idle objects to add. * @param <T> the type of objects in the pool * @throws Exception * when {@link ObjectPool#addObject()} fails. * @throws IllegalArgumentException * when <code>pool</code> is <code>null</code>. */ public static <T> void prefill(final ObjectPool<T> pool, final int count) throws Exception, IllegalArgumentException { if (pool == null) { throw new IllegalArgumentException("pool must not be null."); } for (int i = 0; i < count; i++) { pool.addObject(); } }
/** * {@inheritDoc} */ @Override public void run() { boolean success = false; try { if (pool.getNumIdle() < minIdle) { pool.addObject(); } success = true; } catch (final Exception e) { cancel(); } finally { // detect other types of Throwable and cancel this Timer if (!success) { cancel(); } } }
@Test(expected=IllegalStateException.class) public void testPassThroughMethods02() throws Exception { pool.close(); pool.addObject(); }
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; }
/** * {@inheritDoc} */ @Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { pool.addObject(); }
@Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { pool.addObject(); }
@Override public void addObject() throws Exception { delegate.addObject(); }
@Test public void testUnsupportedOperations() throws Exception { if (!getClass().equals(TestBaseObjectPool.class)) { return; // skip redundant tests } try (final ObjectPool<Object> pool = new TestObjectPool()) { assertTrue("Negative expected.", pool.getNumIdle() < 0); assertTrue("Negative expected.", pool.getNumActive() < 0); try { pool.clear(); fail("Expected UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { // expected } try { pool.addObject(); fail("Expected UnsupportedOperationException"); } catch (final UnsupportedOperationException e) { // expected } } }
pool.addObject(); expectedMethods.add("addObject");
/** * {@inheritDoc} */ @Override public void addObject() throws Exception, IllegalStateException, UnsupportedOperationException { final WriteLock writeLock = readWriteLock.writeLock(); writeLock.lock(); try { pool.addObject(); } finally { writeLock.unlock(); } }
assertEquals(0, pool.getNumIdle()); pool.addObject(); assertEquals(0, pool.getNumActive()); assertEquals(1, pool.getNumIdle()); pool.addObject(); fail("Expected addObject to propagate makeObject exception."); } catch (final PrivateException pe) { factory.setPassivateObjectFail(true); try { pool.addObject(); fail("Expected addObject to propagate passivateObject exception."); } catch (final PrivateException pe) {
@Test public void testPassThroughMethods01() throws Exception { assertEquals(0, pool.getNumActive()); assertEquals(0, pool.getNumIdle()); pool.addObject(); assertEquals(0, pool.getNumActive()); assertEquals(1, pool.getNumIdle()); pool.clear(); assertEquals(0, pool.getNumActive()); assertEquals(0, pool.getNumIdle()); }
/** * {@inheritDoc} */ @Override public void run() { boolean success = false; try { if (pool.getNumIdle() < minIdle) { pool.addObject(); } success = true; } catch (final Exception e) { cancel(); } finally { // detect other types of Throwable and cancel this Timer if (!success) { cancel(); } } }
@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(); } }
pool.addObject(); fail("A closed pool must throw an IllegalStateException when addObject is called."); } catch (final IllegalStateException ise) {