public void testPoolLifecycle() throws Exception { MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName()); ObjectPool pool = createPool(d, FAIL_WHEN_EXHAUSTED); assertNotNull(pool); assertEquals(0, pool.getSize()); }
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); }
/* * (non-Javadoc) * * @see java.lang.Runnable#run() */ public void run() { try { Object object = pool.borrowObject(); try { sleep(time); } catch (InterruptedException e) { // ignore } pool.returnObject(object); } catch (Exception e) { e.printStackTrace(); fail("Borrower thread failed"); } }
public void testBlockExpiryOnExhaust() throws Exception { ObjectPool pool = createPool(getTestDescriptor("orange", Orange.class.getName()), BLOCK_WHEN_EXHAUSTED); Object borrowed = null; assertEquals(0, pool.getSize()); borrowed = pool.borrowObject(); assertNotNull(borrowed); borrowed = pool.borrowObject(); assertNotNull(borrowed); borrowed = pool.borrowObject(); assertNotNull(borrowed); assertEquals(3, pool.getSize()); // TODO // long starttime = System.currentTimeMillis(); try { borrowed = pool.borrowObject(); fail("Should throw an Exception"); } catch (Exception e) { // TODO // long totalTime = System.currentTimeMillis() - starttime; // Need to allow for alittle variance in system time // This is unreliable // assertTrue(totalTime < (DEFAULT_WAIT + 300) && totalTime > // (DEFAULT_WAIT - 300)); } }
public void testFailOnExhaust() throws Exception { ObjectPool pool = createPool(getTestDescriptor("orange", Orange.class.getName()), FAIL_WHEN_EXHAUSTED); Object borrowed = null; for (int i = 0; i < pool.getMaxSize(); i++) { borrowed = pool.borrowObject(); assertNotNull(borrowed); assertEquals(pool.getSize(), i + 1); } try { borrowed = pool.borrowObject(); fail("Should throw an Exception"); } catch (Exception e) { // expected } }
public void testClearPool() throws Exception { ObjectPool pool = createPool(getTestDescriptor("orange", Orange.class.getName()), FAIL_WHEN_EXHAUSTED); Object borrowed = pool.borrowObject(); assertEquals(1, pool.getSize()); pool.returnObject(borrowed); pool.clearPool(); assertEquals(0, pool.getSize()); borrowed = pool.borrowObject(); assertEquals(1, pool.getSize()); }
public void testCreatePool() throws Exception { MuleDescriptor d = getTestDescriptor("orange", Orange.class.getName()); ObjectPool pool = createPool(d, FAIL_WHEN_EXHAUSTED); assertNotNull(pool); assertEquals(0, pool.getSize()); Object borrowed = pool.borrowObject(); assertNotNull(borrowed); assertEquals(1, pool.getSize()); pool.returnObject(borrowed); borrowed = pool.borrowObject(); assertNotNull(borrowed); assertEquals(1, pool.getSize()); Object borrowed2 = pool.borrowObject(); assertNotNull(borrowed2); assertEquals(2, pool.getSize()); }
public void testGrowOnExhaust() throws Exception { ObjectPool pool = createPool(getTestDescriptor("orange", Orange.class.getName()), GROW_WHEN_EXHAUSTED); Object borrowed = pool.borrowObject(); borrowed = pool.borrowObject(); borrowed = pool.borrowObject(); assertEquals(3, pool.getSize()); assertEquals(3, pool.getMaxSize()); // Should now grow borrowed = pool.borrowObject(); assertNotNull(borrowed); assertEquals(4, pool.getSize()); }