Package org.apache.commons.pool

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


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


    public void testBorrowWithSometimesInvalidObjects() throws Exception {
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

       
        // now reject even numbers
        factory.reject = true;

        for(int i=0;i<10;i++) {
            pool.returnObject(obj[i]);
            assertEquals("Each time we return, get one less active.", 9-i, pool.getNumActive());
        }
        // 0,2,4,6,8 fail validation, 3, 9 fail passivation - 3 left.
        assertEquals(3,pool.getNumIdle());
    }
View Full Code Here

        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, destroyed.size());
View Full Code Here

        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, destroyed.size());
View Full Code Here

        // 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, destroyed.size());

        // cause the pool to discard a returned object.
View Full Code Here

        // the pool should now be full.
        assertEquals("No returned objects should have been destroyed yet.",0, destroyed.size());

        // cause the pool to discard a returned object.
        pool.returnObject(i3);
        assertEquals("One object should have been destroyed.", 1, destroyed.size());

        // check to see what object was destroyed
        Integer d = (Integer)destroyed.get(0);
        assertEquals("Destoryed objects should have the stalest object.", i0, d);
View Full Code Here

                    ObjectPool pool = getClientPool(endpoint);
                    if (logger.isDebugEnabled())
                    {
                        logger.debug("Releasing connection for endpoint " + endpoint.getEndpointURI());
                    }
                    pool.returnObject(client);
                }
            }
        }
        else
        {
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

    }

    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

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.