Package org.apache.commons.pool

Examples of org.apache.commons.pool.ObjectPool.returnObject()


        }
        assertEquals(0, pool.getNumIdle());
       
        // returnObject swallows
        Object obj = pool.borrowObject();
        pool.returnObject(obj);
        assertEquals(0, pool.getNumIdle());
    }
   
    /**
     * Verifies that validation exceptions always propagate
View Full Code Here


        // returnObject
        factory.setThrowOnValidate(false);
        Object obj = pool.borrowObject();
        factory.setThrowOnValidate(true);
        try {
            pool.returnObject(obj);
            fail("Expecting IntegerFactoryException");
        } catch (IntegerFactoryException ex) {
            assertEquals("validateObject", ex.getType());
        }
        assertEquals(0, pool.getNumIdle());
View Full Code Here

        assertEquals(1, pool.getNumActive());
        List destroyed = factory.getDestroyed();
        assertEquals(2, destroyed.size());
        assertTrue(destroyed.contains(new Integer(0)));
        assertTrue(destroyed.contains(new Integer(0)));
        pool.returnObject(two);
        assertTrue(destroyed.contains(two));
        try {
            pool.addObject();
            fail("Expecting IllegalStateException");
        } catch (IllegalStateException ex) {
View Full Code Here

            active[i] = pool.borrowObject();
        }
        assertEquals(100,pool.getNumActive());
        assertEquals(0,pool.getNumIdle());
        for(int i=0;i<100;i++) {
            pool.returnObject(active[i]);
            assertEquals(99 - i,pool.getNumActive());
            assertEquals((i < 8 ? i+1 : 8),pool.getNumIdle());
        }
    }
View Full Code Here

     * @deprecated - to be removed in pool 2.0
     */
    public void testPoolWithNullFactory() throws Exception {
        ObjectPool pool = new StackObjectPool(10);
        for(int i=0;i<10;i++) {
            pool.returnObject(new Integer(i));
        }
        for(int j=0;j<3;j++) {
            Integer[] borrowed = new Integer[10];
            BitSet found = new BitSet();
            for(int i=0;i<10;i++) {
View Full Code Here

                assertNotNull(borrowed);
                assertTrue(!found.get(borrowed[i].intValue()));
                found.set(borrowed[i].intValue());
            }
            for(int i=0;i<10;i++) {
                pool.returnObject(borrowed[i]);
            }
        }
        pool.invalidateObject(pool.borrowObject());
        pool.invalidateObject(pool.borrowObject());
        pool.clear();       
View Full Code Here

            // expected
        }
        pool.setFactory(new SimpleFactory());
        Object obj = pool.borrowObject();
        assertNotNull(obj);
        pool.returnObject(obj);
    }

    /**
     * @deprecated - to be removed in pool 2.0
     */
 
View Full Code Here

        ObjectPool pool = new StackObjectPool();
        {
            pool.setFactory(new SimpleFactory());
            Object obj = pool.borrowObject();       
            assertNotNull(obj);
            pool.returnObject(obj);
        }
        {
            pool.setFactory(new SimpleFactory());
            Object obj = pool.borrowObject();       
            assertNotNull(obj);
View Full Code Here

        }
        {
            pool.setFactory(new SimpleFactory());
            Object obj = pool.borrowObject();       
            assertNotNull(obj);
            pool.returnObject(obj);
        }
    }

    /**
     * Verifies that validation failures when borrowing newly created instances
View Full Code Here

            }
            assertEquals("Each time we borrow, get one more active.", i+1, pool.getNumActive());
        }
        // 1,3,5,...,19 pass validation, get checked out
        for(int i=0;i<10;i++) {
            pool.returnObject(obj[i]);
            assertEquals("Each time we return, get one less active.", 9-i, pool.getNumActive());
        }
        // 3, 9, 15 fail passivation. 
        assertEquals(7,pool.getNumIdle());
        assertEquals(new Integer(19), pool.borrowObject());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.