You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rw...@apache.org on 2002/10/31 01:06:20 UTC
cvs commit: jakarta-commons/pool/src/test/org/apache/commons/pool/impl TestGenericObjectPool.java TestSoftReferenceObjectPool.java TestStackObjectPool.java
rwaldhoff 2002/10/30 16:06:20
Modified: pool/src/test/org/apache/commons/pool/impl
TestGenericObjectPool.java
TestSoftReferenceObjectPool.java
TestStackObjectPool.java
Added: pool/src/test/org/apache/commons/pool TestObjectPool.java
Log:
refactor the test suite a bit
Revision Changes Path
1.1 jakarta-commons/pool/src/test/org/apache/commons/pool/TestObjectPool.java
Index: TestObjectPool.java
===================================================================
/*
* $Id: TestObjectPool.java,v 1.1 2002/10/31 00:06:19 rwaldhoff Exp $
* $Revision: 1.1 $
* $Date: 2002/10/31 00:06:19 $
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.commons.pool;
import junit.framework.*;
/**
* Abstract {@link TestCase} for {@link ObjectPool} implementations.
* @author Rodney Waldhoff
* @version $Revision: 1.1 $ $Date: 2002/10/31 00:06:19 $
*/
public abstract class TestObjectPool extends TestCase {
public TestObjectPool(String testName) {
super(testName);
}
/**
* Create an {@link ObjectPool} instance
* that can contain at least <i>mincapacity</i>
* idle and active objects, or
* throw {@link IllegalArgumentException}
* if such a pool cannot be created.
*/
protected abstract ObjectPool makeEmptyPool(int mincapacity);
/**
* Return what we expect to be the n<sup>th</sup>
* object (zero indexed) created by the _pool.
*/
protected abstract Object getNthObject(int n);
public void setUp() throws Exception {
}
public void tearDown() throws Exception {
_pool = null;
}
public void testBorrow() throws Exception {
try {
_pool = makeEmptyPool(3);
} catch(IllegalArgumentException e) {
return; // skip this test if unsupported
}
assertEquals(getNthObject(0),_pool.borrowObject());
assertEquals(getNthObject(1),_pool.borrowObject());
assertEquals(getNthObject(2),_pool.borrowObject());
}
public void testBorrowReturn() throws Exception {
try {
_pool = makeEmptyPool(3);
} catch(IllegalArgumentException e) {
return; // skip this test if unsupported
}
Object obj0 = _pool.borrowObject();
assertEquals(getNthObject(0),obj0);
Object obj1 = _pool.borrowObject();
assertEquals(getNthObject(1),obj1);
Object obj2 = _pool.borrowObject();
assertEquals(getNthObject(2),obj2);
_pool.returnObject(obj2);
obj2 = _pool.borrowObject();
assertEquals(getNthObject(2),obj2);
_pool.returnObject(obj1);
obj1 = _pool.borrowObject();
assertEquals(getNthObject(1),obj1);
_pool.returnObject(obj0);
_pool.returnObject(obj2);
obj2 = _pool.borrowObject();
assertEquals(getNthObject(2),obj2);
obj0 = _pool.borrowObject();
assertEquals(getNthObject(0),obj0);
}
public void testNumActiveNumIdle() throws Exception {
try {
_pool = makeEmptyPool(3);
} catch(IllegalArgumentException e) {
return; // skip this test if unsupported
}
assertEquals(0,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
Object obj0 = _pool.borrowObject();
assertEquals(1,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
Object obj1 = _pool.borrowObject();
assertEquals(2,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
_pool.returnObject(obj1);
assertEquals(1,_pool.getNumActive());
assertEquals(1,_pool.getNumIdle());
_pool.returnObject(obj0);
assertEquals(0,_pool.getNumActive());
assertEquals(2,_pool.getNumIdle());
}
public void testClear() throws Exception {
try {
_pool = makeEmptyPool(3);
} catch(IllegalArgumentException e) {
return; // skip this test if unsupported
}
assertEquals(0,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
Object obj0 = _pool.borrowObject();
Object obj1 = _pool.borrowObject();
assertEquals(2,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
_pool.returnObject(obj1);
_pool.returnObject(obj0);
assertEquals(0,_pool.getNumActive());
assertEquals(2,_pool.getNumIdle());
_pool.clear();
assertEquals(0,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
Object obj2 = _pool.borrowObject();
assertEquals(getNthObject(2),obj2);
}
public void testInvalidateObject() throws Exception {
try {
_pool = makeEmptyPool(3);
} catch(IllegalArgumentException e) {
return; // skip this test if unsupported
}
assertEquals(0,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
Object obj0 = _pool.borrowObject();
Object obj1 = _pool.borrowObject();
assertEquals(2,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
_pool.invalidateObject(obj0);
assertEquals(1,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
_pool.invalidateObject(obj1);
assertEquals(0,_pool.getNumActive());
assertEquals(0,_pool.getNumIdle());
}
private ObjectPool _pool = null;
}
1.8 +41 -98 jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
Index: TestGenericObjectPool.java
===================================================================
RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TestGenericObjectPool.java 30 Oct 2002 22:54:42 -0000 1.7
+++ TestGenericObjectPool.java 31 Oct 2002 00:06:19 -0000 1.8
@@ -1,5 +1,5 @@
/*
- * $Header$
+ * $Id$
* $Revision$
* $Date$
*
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,14 +61,18 @@
package org.apache.commons.pool.impl;
-import junit.framework.*;
-import org.apache.commons.pool.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.TestObjectPool;
/**
* @author Rodney Waldhoff
- * @version $Id$
+ * @version $Revision$ $Date$
*/
-public class TestGenericObjectPool extends TestCase {
+public class TestGenericObjectPool extends TestObjectPool {
public TestGenericObjectPool(String testName) {
super(testName);
}
@@ -77,14 +81,27 @@
return new TestSuite(TestGenericObjectPool.class);
}
- public static void main(String args[]) {
- String[] testCaseName = { TestGenericObjectPool.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
+ protected ObjectPool makeEmptyPool(int mincap) {
+ GenericObjectPool pool = new GenericObjectPool(
+ new PoolableObjectFactory() {
+ int counter = 0;
+ public Object makeObject() { return String.valueOf(counter++); }
+ public void destroyObject(Object obj) { }
+ public boolean validateObject(Object obj) { return true; }
+ public void activateObject(Object obj) { }
+ public void passivateObject(Object obj) { }
+ });
+ pool.setMaxActive(mincap);
+ pool.setMaxIdle(mincap);
+ return pool;
+ }
+
+ protected Object getNthObject(int n) {
+ return String.valueOf(n);
}
- private GenericObjectPool pool = null;
-
- public void setUp() {
+ public void setUp() throws Exception {
+ super.setUp();
pool = new GenericObjectPool(
new PoolableObjectFactory() {
int counter = 0;
@@ -93,15 +110,19 @@
public boolean validateObject(Object obj) { return true; }
public void activateObject(Object obj) { }
public void passivateObject(Object obj) { }
- }
- );
+ });
+ }
+
+ public void tearDown() throws Exception {
+ super.tearDown();
+ pool = null;
}
public void testZeroMaxActive() throws Exception {
pool.setMaxActive(0);
pool.setWhenExhaustedAction(pool.WHEN_EXHAUSTED_FAIL);
Object obj = pool.borrowObject();
- assertEquals("0",obj);
+ assertEquals(getNthObject(0),obj);
pool.returnObject(obj);
}
@@ -109,90 +130,10 @@
pool.setMaxActive(-1);
pool.setWhenExhaustedAction(pool.WHEN_EXHAUSTED_FAIL);
Object obj = pool.borrowObject();
- assertEquals("0",obj);
+ assertEquals(getNthObject(0),obj);
pool.returnObject(obj);
}
- public void testBorrow() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testBorrowReturn() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- pool.returnObject(obj1);
- obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- pool.returnObject(obj0);
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- }
-
- public void testNumActiveNumIdle() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- assertEquals(1,pool.getNumActive());
- assertEquals(1,pool.getNumIdle());
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- }
-
- public void testClear() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- pool.clear();
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testInvalidateObject() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj0);
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj1);
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- }
-
public void testMaxIdle() throws Exception {
pool.setMaxActive(100);
pool.setMaxIdle(8);
@@ -361,6 +302,8 @@
_complete = true;
}
}
+
+ private GenericObjectPool pool = null;
}
1.4 +13 -96 jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
Index: TestSoftReferenceObjectPool.java
===================================================================
RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestSoftReferenceObjectPool.java 30 Oct 2002 22:54:42 -0000 1.3
+++ TestSoftReferenceObjectPool.java 31 Oct 2002 00:06:19 -0000 1.4
@@ -1,5 +1,5 @@
/*
- * $Header$
+ * $Id$
* $Revision$
* $Date$
*
@@ -61,15 +61,18 @@
package org.apache.commons.pool.impl;
-import junit.framework.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.TestObjectPool;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
-public class TestSoftReferenceObjectPool extends TestCase {
+public class TestSoftReferenceObjectPool extends TestObjectPool {
public TestSoftReferenceObjectPool(String testName) {
super(testName);
}
@@ -78,15 +81,8 @@
return new TestSuite(TestSoftReferenceObjectPool.class);
}
- public static void main(String args[]) {
- String[] testCaseName = { TestSoftReferenceObjectPool.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- private SoftReferenceObjectPool pool = null;
-
- public void setUp() {
- pool = new SoftReferenceObjectPool(
+ protected ObjectPool makeEmptyPool(int cap) {
+ return new SoftReferenceObjectPool(
new PoolableObjectFactory() {
int counter = 0;
public Object makeObject() { return String.valueOf(counter++); }
@@ -98,87 +94,8 @@
);
}
- public void testBorrow() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testBorrowReturn() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("borrowObject from an empty pool should create a new instance.","0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("A second borrowObject from an empty pool should create a second instance.","1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("A third borrowObject from an empty pool should create a third instance.","2",obj2);
-
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("Having returned the third instance to the empty pool, borrowObject should return it.","2",obj2);
-
- pool.returnObject(obj1);
- obj1 = pool.borrowObject();
- assertEquals("Having returned the second instance to the empty pool, borrowObject should return it.","1",obj1);
-
- pool.returnObject(obj0);
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("Having returned the first, then third instance to the empty pool, borrowObject should return the third instance.","2",obj2);
- obj0 = pool.borrowObject();
- assertEquals("Having returned the first, then third instance to the empty pool, the second call to borrowObject should return the first instance.","0",obj0);
- }
-
- public void testNumActiveNumIdle() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- assertEquals(1,pool.getNumActive());
- assertEquals(1,pool.getNumIdle());
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- }
-
- public void testClear() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- pool.clear();
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testInvalidateObject() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj0);
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj1);
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
+ protected Object getNthObject(int n) {
+ return String.valueOf(n);
}
}
1.5 +20 -97 jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
Index: TestStackObjectPool.java
===================================================================
RCS file: /home/cvs/jakarta-commons/pool/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestStackObjectPool.java 30 Oct 2002 22:54:42 -0000 1.4
+++ TestStackObjectPool.java 31 Oct 2002 00:06:19 -0000 1.5
@@ -1,5 +1,5 @@
/*
- * $Header$
+ * $Id$
* $Revision$
* $Date$
*
@@ -7,7 +7,7 @@
*
* The Apache Software License, Version 1.1
*
- * Copyright (c) 1999-2001 The Apache Software Foundation. All rights
+ * Copyright (c) 2001-2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -61,14 +61,18 @@
package org.apache.commons.pool.impl;
-import junit.framework.*;
-import org.apache.commons.pool.*;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.commons.pool.ObjectPool;
+import org.apache.commons.pool.PoolableObjectFactory;
+import org.apache.commons.pool.TestObjectPool;
/**
* @author Rodney Waldhoff
- * @version $Id$
+ * @version $Revision$ $Date$
*/
-public class TestStackObjectPool extends TestCase {
+public class TestStackObjectPool extends TestObjectPool {
public TestStackObjectPool(String testName) {
super(testName);
}
@@ -77,15 +81,8 @@
return new TestSuite(TestStackObjectPool.class);
}
- public static void main(String args[]) {
- String[] testCaseName = { TestStackObjectPool.class.getName() };
- junit.textui.TestRunner.main(testCaseName);
- }
-
- private StackObjectPool pool = null;
-
- public void setUp() {
- pool = new StackObjectPool(
+ protected ObjectPool makeEmptyPool(int mincap) {
+ return new StackObjectPool(
new PoolableObjectFactory() {
int counter = 0;
public Object makeObject() { return String.valueOf(counter++); }
@@ -93,91 +90,17 @@
public boolean validateObject(Object obj) { return true; }
public void activateObject(Object obj) { }
public void passivateObject(Object obj) { }
- }
+ },
+ mincap
);
}
-
- public void testBorrow() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testBorrowReturn() throws Exception {
- Object obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- Object obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- pool.returnObject(obj1);
- obj1 = pool.borrowObject();
- assertEquals("1",obj1);
- pool.returnObject(obj0);
- pool.returnObject(obj2);
- obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- obj0 = pool.borrowObject();
- assertEquals("0",obj0);
- }
-
- public void testNumActiveNumIdle() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- assertEquals(1,pool.getNumActive());
- assertEquals(1,pool.getNumIdle());
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- }
-
- public void testClear() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.returnObject(obj1);
- pool.returnObject(obj0);
- assertEquals(0,pool.getNumActive());
- assertEquals(2,pool.getNumIdle());
- pool.clear();
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj2 = pool.borrowObject();
- assertEquals("2",obj2);
- }
-
- public void testInvalidateObject() throws Exception {
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- Object obj0 = pool.borrowObject();
- Object obj1 = pool.borrowObject();
- assertEquals(2,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj0);
- assertEquals(1,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
- pool.invalidateObject(obj1);
- assertEquals(0,pool.getNumActive());
- assertEquals(0,pool.getNumIdle());
+
+ protected Object getNthObject(int n) {
+ return String.valueOf(n);
}
public void testIdleCap() throws Exception {
+ ObjectPool pool = makeEmptyPool(8);
Object[] active = new Object[100];
for(int i=0;i<100;i++) {
active[i] = pool.borrowObject();
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>