You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by si...@apache.org on 2010/10/13 17:50:46 UTC
svn commit: r1022153 - in
/commons/proper/pool/trunk/src/test/org/apache/commons/pool: ./ impl/
Author: simonetripodi
Date: Wed Oct 13 15:50:30 2010
New Revision: 1022153
URL: http://svn.apache.org/viewvc?rev=1022153&view=rev
Log:
test classes migrated from junit3.x to 4.x
Modified:
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedPoolableObjectFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBasePoolableObjectFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedObjectPool.java Wed Oct 13 15:50:30 2010
@@ -16,6 +16,12 @@
*/
package org.apache.commons.pool;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.After;
+import org.junit.Test;
/**
* @author Rodney Waldhoff
@@ -25,10 +31,6 @@ package org.apache.commons.pool;
public class TestBaseKeyedObjectPool extends TestKeyedObjectPool {
private KeyedObjectPool<Object,Object> _pool = null;
- public TestBaseKeyedObjectPool(final String testName) {
- super(testName);
- }
-
@Override
protected KeyedObjectPool<Object,Object> makeEmptyPool(KeyedPoolableObjectFactory<Object,Object> factory) {
if (this.getClass() != TestBaseKeyedObjectPool.class) {
@@ -70,17 +72,12 @@ public class TestBaseKeyedObjectPool ext
throw new UnsupportedOperationException("BaseKeyedObjectPool isn't a complete implementation.");
}
- @Override
- public void setUp() throws Exception {
- super.setUp();
- }
-
- @Override
+ @After
public void tearDown() throws Exception {
_pool = null;
- super.tearDown();
}
+ @Test
public void testUnsupportedOperations() throws Exception {
if (!getClass().equals(TestBaseKeyedObjectPool.class)) {
return; // skip redundant tests
@@ -142,6 +139,7 @@ public class TestBaseKeyedObjectPool ext
return false;
}
+ @Test
public void testBaseBorrowReturn() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -179,6 +177,7 @@ public class TestBaseKeyedObjectPool ext
}
}
+ @Test
public void testBaseBorrow() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -195,6 +194,7 @@ public class TestBaseKeyedObjectPool ext
assertEquals("6",getNthObject(keya,2),_pool.borrowObject(keya));
}
+ @Test
public void testBaseNumActiveNumIdle() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -221,6 +221,7 @@ public class TestBaseKeyedObjectPool ext
assertEquals(0,_pool.getNumIdle("xyzzy12345"));
}
+ @Test
public void testBaseNumActiveNumIdle2() throws Exception {
try {
_pool = makeEmptyPool(6);
@@ -277,6 +278,7 @@ public class TestBaseKeyedObjectPool ext
assertEquals(2,_pool.getNumIdle(keyb));
}
+ @Test
public void testBaseClear() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -301,6 +303,7 @@ public class TestBaseKeyedObjectPool ext
assertEquals(getNthObject(keya,2),obj2);
}
+ @Test
public void testBaseInvalidateObject() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -322,6 +325,7 @@ public class TestBaseKeyedObjectPool ext
assertEquals(0,_pool.getNumIdle(keya));
}
+ @Test
public void testBaseAddObject() throws Exception {
try {
_pool = makeEmptyPool(3);
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedPoolableObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedPoolableObjectFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedPoolableObjectFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseKeyedPoolableObjectFactory.java Wed Oct 13 15:50:30 2010
@@ -16,17 +16,16 @@
*/
package org.apache.commons.pool;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
-public class TestBaseKeyedPoolableObjectFactory extends TestCase {
- public TestBaseKeyedPoolableObjectFactory(String testName) {
- super(testName);
- }
-
+public class TestBaseKeyedPoolableObjectFactory {
+ @Test
public void testDefaultMethods() throws Exception {
KeyedPoolableObjectFactory<Object,Object> factory = new BaseKeyedPoolableObjectFactory<Object,Object>() {
@Override
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBaseObjectPool.java Wed Oct 13 15:50:30 2010
@@ -16,6 +16,11 @@
*/
package org.apache.commons.pool;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.junit.Test;
/**
* @author Rodney Waldhoff
@@ -25,10 +30,6 @@ package org.apache.commons.pool;
public class TestBaseObjectPool extends TestObjectPool {
private ObjectPool<Object> _pool = null;
- public TestBaseObjectPool(String testName) {
- super(testName);
- }
-
protected ObjectPool<Object> makeEmptyPool(int mincapacity) {
if (this.getClass() != TestBaseObjectPool.class) {
fail("Subclasses of TestBaseObjectPool must reimplement this method.");
@@ -66,6 +67,7 @@ public class TestBaseObjectPool extends
}
// tests
+ @Test
public void testUnsupportedOperations() throws Exception {
if (!getClass().equals(TestBaseObjectPool.class)) {
return; // skip redundant tests
@@ -101,6 +103,7 @@ public class TestBaseObjectPool extends
}
}
+ @Test
public void testClose() throws Exception {
ObjectPool<Object> pool = new BaseObjectPool<Object>() {
@Override
@@ -119,6 +122,7 @@ public class TestBaseObjectPool extends
pool.close(); // should not error as of Pool 2.0.
}
+ @Test
public void testBaseBorrow() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -130,6 +134,7 @@ public class TestBaseObjectPool extends
assertEquals(getNthObject(2),_pool.borrowObject());
}
+ @Test
public void testBaseAddObject() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -154,6 +159,7 @@ public class TestBaseObjectPool extends
}
}
+ @Test
public void testBaseBorrowReturn() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -191,6 +197,7 @@ public class TestBaseObjectPool extends
}
}
+ @Test
public void testBaseNumActiveNumIdle() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -213,6 +220,7 @@ public class TestBaseObjectPool extends
assertEquals(2,_pool.getNumIdle());
}
+ @Test
public void testBaseClear() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -236,6 +244,7 @@ public class TestBaseObjectPool extends
assertEquals(getNthObject(2),obj2);
}
+ @Test
public void testBaseInvalidateObject() throws Exception {
try {
_pool = makeEmptyPool(3);
@@ -256,6 +265,7 @@ public class TestBaseObjectPool extends
assertEquals(0,_pool.getNumIdle());
}
+ @Test
public void testBaseClosePool() throws Exception {
try {
_pool = makeEmptyPool(3);
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBasePoolableObjectFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBasePoolableObjectFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBasePoolableObjectFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestBasePoolableObjectFactory.java Wed Oct 13 15:50:30 2010
@@ -16,17 +16,16 @@
*/
package org.apache.commons.pool;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
-public class TestBasePoolableObjectFactory extends TestCase {
- public TestBasePoolableObjectFactory(String testName) {
- super(testName);
- }
-
+public class TestBasePoolableObjectFactory {
+ @Test
public void testDefaultMethods() throws Exception {
PoolableObjectFactory<Object> factory = new BasePoolableObjectFactory<Object>() {
@Override
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPool.java Wed Oct 13 15:50:30 2010
@@ -16,14 +16,18 @@
*/
package org.apache.commons.pool;
-import junit.framework.TestCase;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
-import java.util.List;
import java.util.ArrayList;
+import java.util.List;
import java.util.NoSuchElementException;
+import junit.framework.TestCase;
+
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.StackKeyedObjectPool;
+import org.junit.Test;
/**
* Abstract {@link TestCase} for {@link ObjectPool} implementations.
@@ -31,11 +35,7 @@ import org.apache.commons.pool.impl.Stac
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public abstract class TestKeyedObjectPool extends TestCase {
- public TestKeyedObjectPool(String testName) {
- super(testName);
- }
-
+public abstract class TestKeyedObjectPool {
/**
* Create an <code>KeyedObjectPool</code> with the specified factory.
* The pool should be in a default configuration and conform to the expected
@@ -46,6 +46,7 @@ public abstract class TestKeyedObjectPoo
protected final String KEY = "key";
+ @Test
public void testClosedPoolBehavior() throws Exception {
final KeyedObjectPool<Object,Object> pool;
try {
@@ -95,6 +96,7 @@ public abstract class TestKeyedObjectPoo
private final Integer ZERO = new Integer(0);
private final Integer ONE = new Integer(1);
+ @Test
public void testKPOFAddObjectUsage() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
final KeyedObjectPool<Object,Object> pool;
@@ -149,6 +151,7 @@ public abstract class TestKeyedObjectPoo
assertEquals(expectedMethods, factory.getMethodCalls());
}
+ @Test
public void testKPOFBorrowObjectUsages() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
final KeyedObjectPool<Object,Object> pool;
@@ -235,6 +238,7 @@ public abstract class TestKeyedObjectPoo
assertEquals(expectedMethods, factory.getMethodCalls());
}
+ @Test
public void testKPOFReturnObjectUsages() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
final KeyedObjectPool<Object,Object> pool;
@@ -299,6 +303,7 @@ public abstract class TestKeyedObjectPoo
}
}
+ @Test
public void testKPOFInvalidateObjectUsages() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
final KeyedObjectPool<Object,Object> pool;
@@ -336,6 +341,7 @@ public abstract class TestKeyedObjectPoo
assertEquals(expectedMethods, factory.getMethodCalls());
}
+ @Test
public void testKPOFClearUsages() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
final KeyedObjectPool<Object,Object> pool;
@@ -357,6 +363,7 @@ public abstract class TestKeyedObjectPoo
pool.clear();
}
+ @Test
public void testKPOFCloseUsages() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
KeyedObjectPool<Object,Object> pool;
@@ -380,6 +387,7 @@ public abstract class TestKeyedObjectPoo
pool.close();
}
+ @Test
public void testToString() throws Exception {
final FailingKeyedPoolableObjectFactory factory = new FailingKeyedPoolableObjectFactory();
try {
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestKeyedObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,7 +17,7 @@
package org.apache.commons.pool;
-import junit.framework.TestCase;
+import org.junit.Test;
/**
* Tests for all {@link KeyedObjectPoolFactory}s.
@@ -25,11 +25,7 @@ import junit.framework.TestCase;
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public abstract class TestKeyedObjectPoolFactory extends TestCase {
- protected TestKeyedObjectPoolFactory(final String name) {
- super(name);
- }
-
+public abstract class TestKeyedObjectPoolFactory {
/**
* @throws UnsupportedOperationException when this is unsupported by this KeyedPoolableObjectFactory type.
*/
@@ -46,6 +42,7 @@ public abstract class TestKeyedObjectPoo
return PoolUtils.adapt(new MethodCallPoolableObjectFactory());
}
+ @Test
public void testCreatePool() throws Exception {
final KeyedObjectPoolFactory<Object,Object> factory;
try {
@@ -57,6 +54,7 @@ public abstract class TestKeyedObjectPoo
pool.close();
}
+ @Test
public void testToString() {
final KeyedObjectPoolFactory<Object,Object> factory;
try {
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPool.java Wed Oct 13 15:50:30 2010
@@ -16,6 +16,10 @@
*/
package org.apache.commons.pool;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
@@ -26,6 +30,7 @@ import junit.framework.TestCase;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.apache.commons.pool.impl.SoftReferenceObjectPool;
import org.apache.commons.pool.impl.StackObjectPool;
+import org.junit.Test;
/**
* Abstract {@link TestCase} for {@link ObjectPool} implementations.
@@ -33,11 +38,7 @@ import org.apache.commons.pool.impl.Stac
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public abstract class TestObjectPool extends TestCase {
- public TestObjectPool(String testName) {
- super(testName);
- }
-
+public abstract class TestObjectPool {
/**
* Create an <code>ObjectPool</code> with the specified factory.
* The pool should be in a default configuration and conform to the expected
@@ -47,6 +48,7 @@ public abstract class TestObjectPool ext
*/
protected abstract ObjectPool<Object> makeEmptyPool(PoolableObjectFactory<Object> factory) throws UnsupportedOperationException;
+ @Test
public void testClosedPoolBehavior() throws Exception {
final ObjectPool<Object> pool;
try {
@@ -101,6 +103,7 @@ public abstract class TestObjectPool ext
private final Integer ZERO = new Integer(0);
private final Integer ONE = new Integer(1);
+ @Test
public void testPOFAddObjectUsage() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
final ObjectPool<Object> pool;
@@ -163,6 +166,7 @@ public abstract class TestObjectPool ext
assertEquals(expectedMethods, factory.getMethodCalls());
}
+ @Test
public void testPOFBorrowObjectUsages() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
final ObjectPool<Object> pool;
@@ -245,6 +249,7 @@ public abstract class TestObjectPool ext
assertTrue(factory.getMethodCalls().containsAll(expectedMethods));
}
+ @Test
public void testPOFReturnObjectUsages() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
final ObjectPool<Object> pool;
@@ -306,6 +311,7 @@ public abstract class TestObjectPool ext
pool.returnObject(obj);
}
+ @Test
public void testPOFInvalidateObjectUsages() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
final ObjectPool<Object> pool;
@@ -343,6 +349,7 @@ public abstract class TestObjectPool ext
assertEquals(expectedMethods, factory.getMethodCalls());
}
+ @Test
public void testPOFClearUsages() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
final ObjectPool<Object> pool;
@@ -364,6 +371,7 @@ public abstract class TestObjectPool ext
pool.clear();
}
+ @Test
public void testPOFCloseUsages() throws Exception {
final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
ObjectPool<Object> pool;
@@ -391,6 +399,7 @@ public abstract class TestObjectPool ext
pool.close();
}
+ @Test
public void testToString() {
ObjectPool<Object> pool;
try {
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,7 +17,8 @@
package org.apache.commons.pool;
-import junit.framework.TestCase;
+import org.junit.Test;
+
/**
* Unit tests for all {@link ObjectPoolFactory}.
@@ -25,11 +26,7 @@ import junit.framework.TestCase;
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public abstract class TestObjectPoolFactory extends TestCase {
- protected TestObjectPoolFactory(final String name) {
- super(name);
- }
-
+public abstract class TestObjectPoolFactory {
/**
* @throws UnsupportedOperationException when this is unsupported by this PoolableObjectFactory type.
*/
@@ -42,6 +39,7 @@ public abstract class TestObjectPoolFact
*/
protected abstract ObjectPoolFactory<Object> makeFactory(PoolableObjectFactory<Object> objectFactory) throws UnsupportedOperationException;
+ @Test
public void testCreatePool() throws Exception {
final ObjectPoolFactory<Object> factory;
try {
@@ -53,6 +51,7 @@ public abstract class TestObjectPoolFact
pool.close();
}
+ @Test
public void testToString() {
final ObjectPoolFactory<Object> factory;
try {
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/TestPoolUtils.java Wed Oct 13 15:50:30 2010
@@ -17,6 +17,9 @@
package org.apache.commons.pool;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
@@ -30,10 +33,10 @@ import java.util.Set;
import java.util.TimerTask;
import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
import org.apache.commons.pool.impl.GenericKeyedObjectPool;
import org.apache.commons.pool.impl.GenericObjectPool;
+import org.junit.Test;
/**
* Unit tests for {@link PoolUtils}.
@@ -41,7 +44,7 @@ import org.apache.commons.pool.impl.Gene
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public class TestPoolUtils extends TestCase {
+public class TestPoolUtils {
/** Period between checks for minIdle tests. Increase this if you happen to get too many false failures. */
private static final int CHECK_PERIOD = 300;
@@ -56,6 +59,7 @@ public class TestPoolUtils extends TestC
new PoolUtils();
}
+ @Test
public void testAdaptKeyedPoolableObjectFactory() throws Exception {
try {
PoolUtils.adapt((KeyedPoolableObjectFactory<Object,Object>)null);
@@ -65,6 +69,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testAdaptKeyedPoolableObjectFactoryKey() throws Exception {
try {
PoolUtils.adapt((KeyedPoolableObjectFactory<Object,Object>)null, new Object());
@@ -88,6 +93,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testAdaptPoolableObjectFactory() throws Exception {
try {
PoolUtils.adapt((PoolableObjectFactory<Object>)null);
@@ -105,6 +111,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testAdaptKeyedObjectPool() throws Exception {
try {
PoolUtils.adapt((KeyedObjectPool<Object,Object>)null);
@@ -114,6 +121,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testAdaptKeyedObjectPoolKey() throws Exception {
try {
PoolUtils.adapt((KeyedObjectPool<Object,Object>)null, new Object());
@@ -136,6 +144,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testAdaptObjectPool() throws Exception {
try {
PoolUtils.adapt((ObjectPool<Object>)null);
@@ -152,6 +161,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testCheckedPoolObjectPool() throws Exception {
try {
PoolUtils.checkedPool((ObjectPool<Object>)null, Object.class);
@@ -205,6 +215,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testCheckedPoolKeyedObjectPool() throws Exception {
try {
PoolUtils.checkedPool((KeyedObjectPool<Object,Object>)null, Object.class);
@@ -261,6 +272,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testCheckMinIdleObjectPool() throws Exception {
try {
PoolUtils.checkMinIdle(null, 1, 1);
@@ -323,6 +335,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testCheckMinIdleKeyedObjectPool() throws Exception {
try {
PoolUtils.checkMinIdle(null, new Object(), 1, 1);
@@ -394,6 +407,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testCheckMinIdleKeyedObjectPoolKeys() throws Exception {
try {
final KeyedObjectPool<Object,Object> pool = (KeyedObjectPool<Object,Object>)createProxy(KeyedObjectPool.class, (List<String>)null);
@@ -436,6 +450,7 @@ public class TestPoolUtils extends TestC
}
}
+ @Test
public void testPrefillObjectPool() throws Exception {
try {
PoolUtils.prefill(null, 1);
@@ -459,6 +474,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testPrefillKeyedObjectPool() throws Exception {
try {
PoolUtils.prefill(null, new Object(), 1);
@@ -489,6 +505,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testPrefillKeyedObjectPoolCollection() throws Exception {
// FIXME any reason why when using Object as K the methods signature match?
try {
@@ -518,6 +535,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testSynchronizedPoolObjectPool() throws Exception {
try {
PoolUtils.synchronizedPool((ObjectPool<Object>)null);
@@ -536,6 +554,7 @@ public class TestPoolUtils extends TestC
// TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
}
+ @Test
public void testSynchronizedPoolKeyedObjectPool() throws Exception {
try {
PoolUtils.synchronizedPool((KeyedObjectPool<Object,Object>)null);
@@ -554,6 +573,7 @@ public class TestPoolUtils extends TestC
// TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
}
+ @Test
public void testSynchronizedPoolableFactoryPoolableObjectFactory() throws Exception {
try {
PoolUtils.synchronizedPoolableFactory((PoolableObjectFactory<?>)null);
@@ -573,6 +593,7 @@ public class TestPoolUtils extends TestC
// TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
}
+ @Test
public void testSynchronizedPoolableFactoryKeyedPoolableObjectFactory() throws Exception {
try {
PoolUtils.synchronizedPoolableFactory((KeyedPoolableObjectFactory<Object,Object>)null);
@@ -592,6 +613,7 @@ public class TestPoolUtils extends TestC
// TODO: Anyone feel motivated to construct a test that verifies proper synchronization?
}
+ @Test
public void testErodingPoolObjectPool() throws Exception {
try {
PoolUtils.erodingPool((ObjectPool<Object>)null);
@@ -669,6 +691,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testErodingPoolKeyedObjectPool() throws Exception {
try {
PoolUtils.erodingPool((KeyedObjectPool<Object,Object>)null);
@@ -762,6 +785,7 @@ public class TestPoolUtils extends TestC
assertEquals(expectedMethods, calledMethods);
}
+ @Test
public void testErodingPerKeyKeyedObjectPool() throws Exception {
try {
PoolUtils.erodingPool((KeyedObjectPool<Object,Object>)null, 1, true);
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPool.java Wed Oct 13 15:50:30 2010
@@ -17,6 +17,13 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.HashMap;
@@ -29,16 +36,15 @@ import org.apache.commons.pool.KeyedPool
import org.apache.commons.pool.TestBaseKeyedObjectPool;
import org.apache.commons.pool.VisitTracker;
import org.apache.commons.pool.VisitTrackerFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
public class TestGenericKeyedObjectPool extends TestBaseKeyedObjectPool {
- public TestGenericKeyedObjectPool(String testName) {
- super(testName);
- }
-
@Override
protected KeyedObjectPool<Object,Object> makeEmptyPool(int mincapacity) {
GenericKeyedObjectPool <Object,Object>pool = new GenericKeyedObjectPool<Object,Object>(
@@ -84,12 +90,12 @@ public class TestGenericKeyedObjectPool
private final Integer one = new Integer(1);
private final Integer two = new Integer(2);
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
pool = new GenericKeyedObjectPool<String,String>(new SimpleFactory<String>());
}
+ @After
@Override
public void tearDown() throws Exception {
super.tearDown();
@@ -98,6 +104,7 @@ public class TestGenericKeyedObjectPool
pool = null;
}
+ @Test
public void testNegativeMaxActive() throws Exception {
pool.setMaxActive(-1);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -106,6 +113,7 @@ public class TestGenericKeyedObjectPool
pool.returnObject("",obj);
}
+ @Test
public void testNumActiveNumIdle2() throws Exception {
assertEquals(0,pool.getNumActive());
assertEquals(0,pool.getNumIdle());
@@ -155,6 +163,7 @@ public class TestGenericKeyedObjectPool
assertEquals(2,pool.getNumIdle("B"));
}
+ @Test
public void testMaxIdle() throws Exception {
pool.setMaxActive(100);
pool.setMaxIdle(8);
@@ -189,6 +198,7 @@ public class TestGenericKeyedObjectPool
}
+ @Test
public void testMaxActive() throws Exception {
pool.setMaxActive(3);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -204,6 +214,7 @@ public class TestGenericKeyedObjectPool
}
}
+ @Test
public void testMaxActiveZero() throws Exception {
pool.setMaxActive(0);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -216,6 +227,7 @@ public class TestGenericKeyedObjectPool
}
}
+ @Test
public void testWhenExhaustedGrow() throws Exception {
pool.setMaxActive(1);
pool.setMaxTotal(1);
@@ -225,6 +237,7 @@ public class TestGenericKeyedObjectPool
}
}
+ @Test
public void testMaxTotal() throws Exception {
pool.setMaxActive(2);
pool.setMaxTotal(3);
@@ -266,6 +279,7 @@ public class TestGenericKeyedObjectPool
pool.getMaxTotal());
}
+ @Test
public void testMaxTotalZero() throws Exception {
pool.setMaxTotal(0);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -278,6 +292,7 @@ public class TestGenericKeyedObjectPool
}
}
+ @Test
public void testMaxTotalLRU() throws Exception {
pool.setMaxActive(2);
pool.setMaxTotal(3);
@@ -327,6 +342,7 @@ public class TestGenericKeyedObjectPool
assertSame(o4, o7);
}
+ @Test
public void testSettersAndGetters() throws Exception {
GenericKeyedObjectPool<String,String> pool = new GenericKeyedObjectPool<String,String>(new SimpleFactory<String>());
{
@@ -381,6 +397,7 @@ public class TestGenericKeyedObjectPool
}
}
+ @Test
public void testEviction() throws Exception {
pool.setMaxIdle(500);
pool.setMaxActive(500);
@@ -430,6 +447,7 @@ public class TestGenericKeyedObjectPool
assertEquals("Should be zero idle, found " + pool.getNumIdle(""),0,pool.getNumIdle(""));
}
+ @Test
public void testEviction2() throws Exception {
pool.setMaxIdle(500);
pool.setMaxActive(500);
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericKeyedObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,9 +17,12 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.pool.KeyedObjectPoolFactory;
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.TestKeyedObjectPoolFactory;
+import org.junit.Test;
/**
* Tests for {@link GenericKeyedObjectPoolFactory}.
@@ -28,15 +31,12 @@ import org.apache.commons.pool.TestKeyed
* @version $Revision$ $Date$
*/
public class TestGenericKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
- public TestGenericKeyedObjectPoolFactory(final String name) {
- super(name);
- }
-
@Override
protected KeyedObjectPoolFactory<Object,Object> makeFactory(final KeyedPoolableObjectFactory<Object,Object> objectFactory) {
return new GenericKeyedObjectPoolFactory<Object,Object>(objectFactory);
}
+ @Test
public void testConstructors() throws Exception {
GenericKeyedObjectPoolFactory<Object,Object> factory = new GenericKeyedObjectPoolFactory<Object,Object>(createObjectFactory());
factory.createPool().close();
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPool.java Wed Oct 13 15:50:30 2010
@@ -17,6 +17,12 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.NoSuchElementException;
import java.util.Random;
@@ -27,6 +33,9 @@ import org.apache.commons.pool.PoolableO
import org.apache.commons.pool.TestBaseObjectPool;
import org.apache.commons.pool.VisitTracker;
import org.apache.commons.pool.VisitTrackerFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Rodney Waldhoff
@@ -35,10 +44,6 @@ import org.apache.commons.pool.VisitTrac
* @version $Revision$ $Date$
*/
public class TestGenericObjectPool extends TestBaseObjectPool {
- public TestGenericObjectPool(String testName) {
- super(testName);
- }
-
@Override
protected ObjectPool<Object> makeEmptyPool(int mincap) {
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(new SimpleFactory());
@@ -57,20 +62,19 @@ public class TestGenericObjectPool exten
return String.valueOf(n);
}
- @Override
- public void setUp() throws Exception {
- super.setUp();
+ @Before
+ public void setUp() {
pool = new GenericObjectPool<Object>(new SimpleFactory());
}
- @Override
+ @After
public void tearDown() throws Exception {
- super.tearDown();
pool.clear();
pool.close();
pool = null;
}
+ @Test
public void testWhenExhaustedGrow() throws Exception {
pool.setMaxActive(1);
pool.setWhenExhaustedAction(WhenExhaustedAction.GROW);
@@ -83,6 +87,7 @@ public class TestGenericObjectPool exten
pool.close();
}
+ @Test
public void testWhenExhaustedFail() throws Exception {
pool.setMaxActive(1);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -99,6 +104,7 @@ public class TestGenericObjectPool exten
pool.close();
}
+ @Test
public void testWhenExhaustedBlock() throws Exception {
pool.setMaxActive(1);
pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
@@ -115,6 +121,7 @@ public class TestGenericObjectPool exten
pool.close();
}
+ @Test
public void testWhenExhaustedBlockInterupt() throws Exception {
pool.setMaxActive(1);
pool.setWhenExhaustedAction(WhenExhaustedAction.BLOCK);
@@ -155,6 +162,7 @@ public class TestGenericObjectPool exten
}
+ @Test
public void testEvictWhileEmpty() throws Exception {
pool.evict();
pool.evict();
@@ -165,6 +173,7 @@ public class TestGenericObjectPool exten
* Tests addObject contention between ensureMinIdle triggered by
* the Evictor with minIdle > 0 and borrowObject.
*/
+ @Test
public void testEvictAddObjects() throws Exception {
SimpleFactory factory = new SimpleFactory();
factory.setMakeLatency(300);
@@ -185,10 +194,12 @@ public class TestGenericObjectPool exten
pool.close();
}
+ @Test
public void testEvictLIFO() throws Exception {
checkEvict(true);
}
+ @Test
public void testEvictFIFO() throws Exception {
checkEvict(false);
}
@@ -225,6 +236,7 @@ public class TestGenericObjectPool exten
*
* JIRA: POOL-86
*/
+ @Test
public void testEvictionOrder() throws Exception {
checkEvictionOrder(false);
checkEvictionOrder(true);
@@ -268,6 +280,7 @@ public class TestGenericObjectPool exten
* Verifies that the evictor visits objects in expected order
* and frequency.
*/
+ @Test
public void testEvictorVisiting() throws Exception {
checkEvictorVisiting(true);
checkEvictorVisiting(false);
@@ -390,6 +403,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testExceptionOnPassivateDuringReturn() throws Exception {
SimpleFactory factory = new SimpleFactory();
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
@@ -400,6 +414,7 @@ public class TestGenericObjectPool exten
pool.close();
}
+ @Test
public void testExceptionOnDestroyDuringBorrow() throws Exception {
SimpleFactory factory = new SimpleFactory();
factory.setThrowExceptionOnDestroy(true);
@@ -417,6 +432,7 @@ public class TestGenericObjectPool exten
assertEquals(0, pool.getNumIdle());
}
+ @Test
public void testExceptionOnDestroyDuringReturn() throws Exception {
SimpleFactory factory = new SimpleFactory();
factory.setThrowExceptionOnDestroy(true);
@@ -430,6 +446,7 @@ public class TestGenericObjectPool exten
assertEquals(0, pool.getNumIdle());
}
+ @Test
public void testExceptionOnActivateDuringBorrow() throws Exception {
SimpleFactory factory = new SimpleFactory();
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(factory);
@@ -459,6 +476,7 @@ public class TestGenericObjectPool exten
assertEquals(0, pool.getNumIdle());
}
+ @Test
public void testNegativeMaxActive() throws Exception {
pool.setMaxActive(-1);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -467,6 +485,7 @@ public class TestGenericObjectPool exten
pool.returnObject(obj);
}
+ @Test
public void testMaxIdle() throws Exception {
pool.setMaxActive(100);
pool.setMaxIdle(8);
@@ -483,6 +502,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testMaxIdleZero() throws Exception {
pool.setMaxActive(100);
pool.setMaxIdle(0);
@@ -499,6 +519,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testMaxActive() throws Exception {
pool.setMaxActive(3);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -514,6 +535,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testTimeoutNoLeak() throws Exception {
pool.setMaxActive(2);
pool.setMaxWait(10);
@@ -533,6 +555,7 @@ public class TestGenericObjectPool exten
obj2 = pool.borrowObject();
}
+ @Test
public void testMaxActiveZero() throws Exception {
pool.setMaxActive(0);
pool.setWhenExhaustedAction(WhenExhaustedAction.FAIL);
@@ -545,6 +568,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testMaxActiveUnderLoad() {
// Config
int numThreads = 199; // And main thread makes a round 200.
@@ -623,6 +647,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testSettersAndGetters() throws Exception {
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(new SimpleFactory());
{
@@ -681,6 +706,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testConstructors() throws Exception {
{
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(new SimpleFactory());
@@ -778,6 +804,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testSetConfig() throws Exception {
GenericObjectPool.Config expected = new GenericObjectPool.Config();
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(new SimpleFactory());
@@ -796,6 +823,7 @@ public class TestGenericObjectPool exten
assertConfiguration(expected,pool);
}
+ @Test
public void testDebugInfo() throws Exception {
GenericObjectPool<Object> pool = new GenericObjectPool<Object>(new SimpleFactory());
pool.setMaxIdle(3);
@@ -806,6 +834,7 @@ public class TestGenericObjectPool exten
assertNotNull(pool.debugInfo());
}
+ @Test
public void testStartAndStopEvictor() throws Exception {
// set up pool without evictor
pool.setMaxIdle(6);
@@ -842,6 +871,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testEvictionWithNegativeNumTests() throws Exception {
// when numTestsPerEvictionRun is negative, it represents a fraction of the idle objects to test
pool.setMaxIdle(6);
@@ -868,6 +898,7 @@ public class TestGenericObjectPool exten
assertEquals("Should be zero idle, found " + pool.getNumIdle(),0,pool.getNumIdle());
}
+ @Test
public void testEviction() throws Exception {
pool.setMaxIdle(500);
pool.setMaxActive(500);
@@ -918,6 +949,7 @@ public class TestGenericObjectPool exten
assertEquals("Should be zero idle, found " + pool.getNumIdle(),0,pool.getNumIdle());
}
+ @Test
public void testEvictionSoftMinIdle() throws Exception {
class TimeTest extends BasePoolableObjectFactory<TimeTest> {
private final long createTime;
@@ -964,6 +996,7 @@ public class TestGenericObjectPool exten
assertEquals("Idle count different than expected.", 0, pool.getNumIdle());
}
+ @Test
public void testMinIdle() throws Exception {
pool.setMaxIdle(500);
pool.setMinIdle(5);
@@ -997,6 +1030,7 @@ public class TestGenericObjectPool exten
assertTrue("Should be 10 idle, found " + pool.getNumIdle(),pool.getNumIdle() == 10);
}
+ @Test
public void testMinIdleMaxActive() throws Exception {
pool.setMaxIdle(500);
pool.setMinIdle(5);
@@ -1069,6 +1103,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testThreaded1() throws Exception {
pool.setMaxActive(15);
pool.setMaxIdle(15);
@@ -1081,6 +1116,7 @@ public class TestGenericObjectPool exten
* has high latency, testOnReturn is set and there is high incidence of
* validation failures.
*/
+ @Test
public void testMaxActiveInvariant() throws Exception {
int maxActive = 15;
SimpleFactory factory = new SimpleFactory();
@@ -1188,6 +1224,7 @@ public class TestGenericObjectPool exten
}
}
+ @Test
public void testFIFO() throws Exception {
pool.setLifo(false);
pool.addObject(); // "0"
@@ -1202,6 +1239,7 @@ public class TestGenericObjectPool exten
assertEquals("new-4", "4", pool.borrowObject());
}
+ @Test
public void testLIFO() throws Exception {
pool.setLifo(true);
pool.addObject(); // "0"
@@ -1216,6 +1254,7 @@ public class TestGenericObjectPool exten
assertEquals("new-4", "4", pool.borrowObject());
}
+ @Test
public void testAddObject() throws Exception {
assertEquals("should be zero idle", 0, pool.getNumIdle());
pool.addObject();
@@ -1427,6 +1466,7 @@ public class TestGenericObjectPool exten
* enough margin for this to work correctly on most (all?) systems but be
* aware of this if you see a failure of this test.
*/
+ @Test
public void testBorrowObjectFairness() {
// Config
int numThreads = 30;
@@ -1472,6 +1512,7 @@ public class TestGenericObjectPool exten
* On first borrow, first object fails validation, second object is OK.
* Subsequent borrows are OK. This was POOL-152.
*/
+ @Test
public void testBrokenFactoryShouldNotBlockPool() {
int maxActive = 1;
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestGenericObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,12 +17,17 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.NoSuchElementException;
import org.apache.commons.pool.MethodCallPoolableObjectFactory;
import org.apache.commons.pool.ObjectPoolFactory;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.TestObjectPoolFactory;
+import org.junit.Test;
/**
* Tests for {@link GenericObjectPoolFactory}.
@@ -31,15 +36,12 @@ import org.apache.commons.pool.TestObjec
* @version $Revision$ $Date$
*/
public class TestGenericObjectPoolFactory extends TestObjectPoolFactory {
- public TestGenericObjectPoolFactory(final String name) {
- super(name);
- }
-
@Override
protected ObjectPoolFactory<Object> makeFactory(final PoolableObjectFactory<Object> objectFactory) throws UnsupportedOperationException {
return new GenericObjectPoolFactory<Object>(objectFactory);
}
+ @Test
public void testConstructors() throws Exception {
GenericObjectPoolFactory<Object> factory = new GenericObjectPoolFactory<Object>(new MethodCallPoolableObjectFactory());
GenericObjectPool<Object> pool;
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftRefOutOfMemory.java Wed Oct 13 15:50:30 2010
@@ -17,28 +17,28 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
-import junit.framework.TestCase;
-
import org.apache.commons.pool.BasePoolableObjectFactory;
import org.apache.commons.pool.PoolableObjectFactory;
+import org.junit.After;
+import org.junit.Test;
/**
* @author Dirk Verbeeck
* @author Sandy McArthur
* @version $Revision$ $Date$
*/
-public class TestSoftRefOutOfMemory extends TestCase {
+public class TestSoftRefOutOfMemory {
private SoftReferenceObjectPool<String> pool;
- public TestSoftRefOutOfMemory(String testName) {
- super(testName);
- }
-
- @Override
+ @After
public void tearDown() throws Exception {
if (pool != null) {
pool.close();
@@ -47,6 +47,7 @@ public class TestSoftRefOutOfMemory exte
System.gc();
}
+ @Test
public void testOutOfMemory() throws Exception {
pool = new SoftReferenceObjectPool<String>(new SmallPoolableObjectFactory());
@@ -78,6 +79,7 @@ public class TestSoftRefOutOfMemory exte
assertEquals(1, pool.getNumIdle());
}
+ @Test
public void testOutOfMemory1000() throws Exception {
pool = new SoftReferenceObjectPool<String>(new SmallPoolableObjectFactory());
@@ -113,6 +115,7 @@ public class TestSoftRefOutOfMemory exte
assertEquals(1, pool.getNumIdle());
}
+ @Test
public void testOutOfMemoryLarge() throws Exception {
pool = new SoftReferenceObjectPool<String>(new LargePoolableObjectFactory(1000000));
@@ -147,6 +150,7 @@ public class TestSoftRefOutOfMemory exte
/**
* Makes sure an {@link OutOfMemoryError} isn't swallowed.
*/
+ @Test
public void testOutOfMemoryError() throws Exception {
pool = new SoftReferenceObjectPool<String>(new BasePoolableObjectFactory<String>() {
@Override
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestSoftReferenceObjectPool.java Wed Oct 13 15:50:30 2010
@@ -27,10 +27,6 @@ import org.apache.commons.pool.TestBaseO
* @version $Revision$ $Date$
*/
public class TestSoftReferenceObjectPool extends TestBaseObjectPool {
- public TestSoftReferenceObjectPool(String testName) {
- super(testName);
- }
-
@Override
protected ObjectPool<Object> makeEmptyPool(int cap) {
return new SoftReferenceObjectPool<Object>(
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPool.java Wed Oct 13 15:50:30 2010
@@ -17,22 +17,24 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
import java.util.HashMap;
import java.util.NoSuchElementException;
import org.apache.commons.pool.KeyedObjectPool;
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.TestBaseKeyedObjectPool;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
/**
* @author Rodney Waldhoff
* @version $Revision$ $Date$
*/
public class TestStackKeyedObjectPool extends TestBaseKeyedObjectPool {
- public TestStackKeyedObjectPool(String testName) {
- super(testName);
- }
-
@Override
protected KeyedObjectPool<Object,Object> makeEmptyPool(int mincapacity) {
StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new SimpleFactory(),mincapacity);
@@ -56,9 +58,8 @@ public class TestStackKeyedObjectPool ex
private StackKeyedObjectPool<String,String> pool = null;
- @Override
+ @Before
public void setUp() throws Exception {
- super.setUp();
pool = new StackKeyedObjectPool<String,String>(
new KeyedPoolableObjectFactory<String,String>() {
int counter = 0;
@@ -72,12 +73,12 @@ public class TestStackKeyedObjectPool ex
}
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() {
pool = null;
}
+ @Test
public void testCloseBug() throws Exception {
{
String obj0 = pool.borrowObject("");
@@ -102,6 +103,7 @@ public class TestStackKeyedObjectPool ex
pool.close();
}
+ @Test
public void testIdleCap() throws Exception {
String[] active = new String[100];
for(int i=0;i<100;i++) {
@@ -121,6 +123,7 @@ public class TestStackKeyedObjectPool ex
* the bottom (oldest) instance in the pool is destroyed to make room for the newly
* returning instance, which is pushed onto the idle object stack.
*/
+ @Test
public void testRemoveOldest() throws Exception {
pool.setMaxSleeping(2);
String obj0 = pool.borrowObject("");
@@ -134,6 +137,7 @@ public class TestStackKeyedObjectPool ex
assertEquals("3", pool.borrowObject("")); // New instance created (0 is gone)
}
+ @Test
public void testVariousConstructors() throws Exception {
{
StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new SimpleFactory());
@@ -150,6 +154,7 @@ public class TestStackKeyedObjectPool ex
}
@Override
+ @Test
public void testToString() throws Exception {
StackKeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(new SimpleFactory());
assertNotNull(pool.toString());
@@ -159,6 +164,7 @@ public class TestStackKeyedObjectPool ex
assertNotNull(pool.toString());
}
+ @Test
public void testBorrowReturnWithSometimesInvalidObjects() throws Exception {
KeyedObjectPool<Object,Object> pool = new StackKeyedObjectPool<Object,Object>(
new KeyedPoolableObjectFactory<Object,Object>() {
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackKeyedObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,9 +17,12 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.pool.KeyedObjectPoolFactory;
import org.apache.commons.pool.KeyedPoolableObjectFactory;
import org.apache.commons.pool.TestKeyedObjectPoolFactory;
+import org.junit.Test;
/**
* Tests for {@link StackKeyedObjectPoolFactory}.
@@ -28,15 +31,12 @@ import org.apache.commons.pool.TestKeyed
* @version $Revision$ $Date$
*/
public class TestStackKeyedObjectPoolFactory extends TestKeyedObjectPoolFactory {
- public TestStackKeyedObjectPoolFactory(final String name) {
- super(name);
- }
-
@Override
protected KeyedObjectPoolFactory<Object,Object> makeFactory(final KeyedPoolableObjectFactory<Object,Object> objectFactory) throws UnsupportedOperationException {
return new StackKeyedObjectPoolFactory<Object,Object>(objectFactory);
}
+ @Test
public void testConstructors() throws Exception {
StackKeyedObjectPoolFactory<Object,Object> factory = new StackKeyedObjectPoolFactory<Object,Object>(createObjectFactory());
StackKeyedObjectPool<Object,Object> pool = (StackKeyedObjectPool<Object,Object>)factory.createPool();
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPool.java Wed Oct 13 15:50:30 2010
@@ -17,6 +17,11 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
@@ -24,6 +29,7 @@ import java.util.NoSuchElementException;
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.TestBaseObjectPool;
+import org.junit.Test;
/**
* @author Rodney Waldhoff
@@ -32,10 +38,6 @@ import org.apache.commons.pool.TestBaseO
* @version $Revision$ $Date$
*/
public class TestStackObjectPool extends TestBaseObjectPool {
- public TestStackObjectPool(String testName) {
- super(testName);
- }
-
@Override
protected ObjectPool<Object> makeEmptyPool(int mincap) {
return new StackObjectPool<Object>(new SimpleFactory());
@@ -51,6 +53,7 @@ public class TestStackObjectPool extends
return String.valueOf(n);
}
+ @Test
public void testIdleCap() throws Exception {
ObjectPool<Object> pool = makeEmptyPool(8);
Object[] active = new Object[100];
@@ -71,6 +74,7 @@ public class TestStackObjectPool extends
* from the pool result in NoSuchElementExceptions and passivation failures
* result in instances not being returned to the pool.
*/
+ @Test
public void testBorrowWithSometimesInvalidObjects() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
factory.setValidateSelectively(true); // Even numbers fail validation
@@ -115,6 +119,7 @@ public class TestStackObjectPool extends
* Verifies that validation and passivation failures returning objects are handled
* properly - instances destroyed and not returned to the pool, but no exceptions propagated.
*/
+ @Test
public void testBorrowReturnWithSometimesInvalidObjects() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, 20);
@@ -137,6 +142,7 @@ public class TestStackObjectPool extends
assertEquals(3,pool.getNumIdle());
}
+ @Test
public void testVariousConstructors() throws Exception {
{
StackObjectPool<Integer> pool = new StackObjectPool<Integer>(null);
@@ -155,6 +161,7 @@ public class TestStackObjectPool extends
/**
* Verify that out of range constructor arguments are ignored.
*/
+ @Test
public void testMaxIdleInitCapacityOutOfRange() throws Exception {
SimpleFactory factory = new SimpleFactory();
StackObjectPool<Object> pool = new StackObjectPool<Object>(factory, -1, 0);
@@ -167,6 +174,7 @@ public class TestStackObjectPool extends
* Verifies that when returning objects cause maxSleeping exceeded, oldest instances
* are destroyed to make room for returning objects.
*/
+ @Test
public void testReturnObjectDiscardOrder() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, 3);
@@ -200,6 +208,7 @@ public class TestStackObjectPool extends
* the caller. Objects that throw on activate are destroyed and if none succeed,
* the caller gets NoSuchElementException.
*/
+ @Test
public void testExceptionOnActivate() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory);
@@ -220,6 +229,7 @@ public class TestStackObjectPool extends
* Verifies that exceptions thrown by factory destroy are swallowed
* by both addObject and returnObject.
*/
+ @Test
public void testExceptionOnDestroy() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, 2);
@@ -243,6 +253,7 @@ public class TestStackObjectPool extends
* Verifies that addObject propagates exceptions thrown by
* factory passivate, but returnObject swallows these.
*/
+ @Test
public void testExceptionOnPassivate() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, 2);
@@ -267,6 +278,7 @@ public class TestStackObjectPool extends
/**
* Verifies that validation exceptions always propagate
*/
+ @Test
public void testExceptionOnValidate() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory, 2);
@@ -305,6 +317,7 @@ public class TestStackObjectPool extends
/**
* Verifies that exceptions thrown by makeObject are propagated.
*/
+ @Test
public void testExceptionOnMake() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
factory.setThrowOnMake(true);
@@ -326,6 +339,7 @@ public class TestStackObjectPool extends
/**
* Verifies NoSuchElementException when the factory returns a null object in borrowObject
*/
+ @Test
public void testMakeNull() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory);
@@ -341,6 +355,7 @@ public class TestStackObjectPool extends
/**
* Verifies that initIdleCapacity is not a hard limit, but maxIdle is.
*/
+ @Test
public void testInitIdleCapacityExceeded() throws Exception {
PoolableObjectFactory<Object> factory = new SimpleFactory();
ObjectPool<Object> pool = new StackObjectPool<Object>(factory, 2, 1);
@@ -359,6 +374,7 @@ public class TestStackObjectPool extends
* are destroyed, add/borrowObject throw IllegalStateException.
*/
@Override
+ @Test
public void testClose() throws Exception {
SelectiveFactory factory = new SelectiveFactory();
ObjectPool<Integer> pool = new StackObjectPool<Integer>(factory);
Modified: commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java?rev=1022153&r1=1022152&r2=1022153&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java (original)
+++ commons/proper/pool/trunk/src/test/org/apache/commons/pool/impl/TestStackObjectPoolFactory.java Wed Oct 13 15:50:30 2010
@@ -17,11 +17,14 @@
package org.apache.commons.pool.impl;
+import static org.junit.Assert.assertEquals;
+
import org.apache.commons.pool.MethodCallPoolableObjectFactory;
import org.apache.commons.pool.ObjectPool;
import org.apache.commons.pool.ObjectPoolFactory;
import org.apache.commons.pool.PoolableObjectFactory;
import org.apache.commons.pool.TestObjectPoolFactory;
+import org.junit.Test;
/**
* Tests for {@link StackObjectPoolFactory}.
@@ -30,15 +33,12 @@ import org.apache.commons.pool.TestObjec
* @version $Revision$ $Date$
*/
public class TestStackObjectPoolFactory extends TestObjectPoolFactory {
- public TestStackObjectPoolFactory(final String name) {
- super(name);
- }
-
@Override
protected ObjectPoolFactory<Object> makeFactory(final PoolableObjectFactory<Object> objectFactory) throws UnsupportedOperationException {
return new StackObjectPoolFactory<Object>(objectFactory);
}
+ @Test
public void testConstructors() throws Exception {
StackObjectPoolFactory<Object> factory = new StackObjectPoolFactory<Object>(new MethodCallPoolableObjectFactory(), 1);
ObjectPool<Object> pool = factory.createPool();