* Verifies that when returning objects cause maxSleeping exceeded, oldest instances
* are destroyed to make room for returning objects.
*/
public void testReturnObjectDiscardOrder() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool pool = new StackObjectPool(factory, 3);
// borrow more objects than the pool can hold
Integer i0 = (Integer)pool.borrowObject();
Integer i1 = (Integer)pool.borrowObject();
Integer i2 = (Integer)pool.borrowObject();
Integer i3 = (Integer)pool.borrowObject();
// tests
// return as many as the pool will hold.
pool.returnObject(i0);
pool.returnObject(i1);
pool.returnObject(i2);
// the pool should now be full.
assertEquals("No returned objects should have been destroyed yet.", 0, factory.getDestroyed().size());
// cause the pool to discard a stale object.
pool.returnObject(i3);
assertEquals("One object should have been destroyed.", 1, factory.getDestroyed().size());
// check to see what object was destroyed
Integer d = (Integer)factory.getDestroyed().get(0);
assertEquals("Destoryed object should be the stalest object.", i0, d);