public void testBlockOnExhaust() throws Exception { ObjectPool pool = createPool(getTestDescriptor("orange", Orange.class.getName()), BLOCK_WHEN_EXHAUSTED); Object borrowed = null; assertEquals(0, pool.getSize()); borrowed = pool.borrowObject(); borrowed = pool.borrowObject(); assertEquals(2, pool.getSize()); // TODO // long starttime = System.currentTimeMillis(); long borrowerWait = 500; Borrower borrower = new Borrower(pool, borrowerWait); borrower.start(); // Make sure the borrower borrows first try { Thread.sleep(200); } catch (InterruptedException e) { } borrowed = pool.borrowObject(); // TODO // long totalTime = System.currentTimeMillis() - starttime; // Need to allow for alittle variance in system time // This is unreliable // assertTrue(totalTime < (borrowerWait + 300) && totalTime > // (borrowerWait -300)); assertNotNull(borrowed); }
public void testBlockOnExhaust() throws Exception { PoolingProfile pp = getDefaultPoolingProfile(); pp.setExhaustedAction(PoolingProfile.WHEN_EXHAUSTED_WAIT); PooledJavaComponent component = new PooledJavaComponent(getObjectFactory(), pp); component.setService(getTestService()); component.initialise(); component.start(); Object borrowed = null; assertEquals(0, component.lifecycleAdapterPool.getNumActive()); borrowed = component.borrowComponentLifecycleAdaptor(); borrowed = component.borrowComponentLifecycleAdaptor(); assertEquals(2, component.lifecycleAdapterPool.getNumActive()); // TODO // long starttime = System.currentTimeMillis(); long borrowerWait = 500; Borrower borrower = new Borrower(component, borrowerWait); borrower.start(); // Make sure the borrower borrows first try { Thread.sleep(200); } catch (InterruptedException e) { // ignore } borrowed = component.borrowComponentLifecycleAdaptor(); // TODO // long totalTime = System.currentTimeMillis() - starttime; // Need to allow for alittle variance in system time // This is unreliable // assertTrue(totalTime < (borrowerWait + 300) && totalTime > // (borrowerWait -300)); assertNotNull(borrowed); }