You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/07/24 23:25:16 UTC
svn commit: r1506726 -
/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
Author: markt
Date: Wed Jul 24 21:25:16 2013
New Revision: 1506726
URL: http://svn.apache.org/r1506726
Log:
Switch test to use same constructor as main code.
Modified:
commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
Modified: commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java?rev=1506726&r1=1506725&r2=1506726&view=diff
==============================================================================
--- commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java (original)
+++ commons/proper/dbcp/trunk/src/test/org/apache/commons/dbcp2/datasources/TestCPDSConnectionFactory.java Wed Jul 24 21:25:16 2013
@@ -5,9 +5,9 @@
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -34,9 +34,9 @@ import org.apache.commons.pool2.impl.Gen
* @version $Revision$ $Date$
*/
public class TestCPDSConnectionFactory extends TestCase {
-
+
protected ConnectionPoolDataSourceProxy cpds = null;
-
+
public TestCPDSConnectionFactory(String testName) {
super(testName);
}
@@ -54,10 +54,10 @@ public class TestCPDSConnectionFactory e
delegate.setUser("username");
delegate.setPassword("password");
}
-
+
/**
* JIRA DBCP-216
- *
+ *
* Check PoolableConnection close triggered by destroy is handled
* properly. PooledConnectionProxy (dubiously) fires connectionClosed
* when PooledConnection itself is closed.
@@ -79,62 +79,62 @@ public class TestCPDSConnectionFactory e
conn3.close(); // Return to pool will trigger destroy -> close sequence
assertEquals(2, ds.getNumIdle("username", "password"));
}
-
+
/**
* JIRA DBCP-216
- *
+ *
* Verify that pool counters are maintained properly and listeners are
* cleaned up when a PooledConnection throws a connectionError event.
*/
public void testConnectionErrorCleanup() throws Exception {
// Setup factory
- CPDSConnectionFactory factory =
- new CPDSConnectionFactory(cpds, null, "username", "password");
+ CPDSConnectionFactory factory =
+ new CPDSConnectionFactory(cpds, null, false, "username", "password");
GenericObjectPool pool = new GenericObjectPool(factory);
factory.setPool(pool);
-
+
// Checkout a pair of connections
- PooledConnection pcon1 =
+ PooledConnection pcon1 =
((PooledConnectionAndInfo) pool.borrowObject())
.getPooledConnection();
Connection con1 = pcon1.getConnection();
- PooledConnection pcon2 =
+ PooledConnection pcon2 =
((PooledConnectionAndInfo) pool.borrowObject())
.getPooledConnection();
assertEquals(2, pool.getNumActive());
assertEquals(0, pool.getNumIdle());
-
+
// Verify listening
PooledConnectionProxy pc = (PooledConnectionProxy) pcon1;
assertTrue(pc.getListeners().contains(factory));
-
+
// Throw connectionError event
pc.throwConnectionError();
-
+
// Active count should be reduced by 1 and no idle increase
assertEquals(1, pool.getNumActive());
assertEquals(0, pool.getNumIdle());
-
+
// Throw another one - should be ignored
pc.throwConnectionError();
assertEquals(1, pool.getNumActive());
assertEquals(0, pool.getNumIdle());
-
- // Ask for another connection
- PooledConnection pcon3 =
+
+ // Ask for another connection
+ PooledConnection pcon3 =
((PooledConnectionAndInfo) pool.borrowObject())
.getPooledConnection();
assertTrue(!pcon3.equals(pcon1)); // better not get baddie back
assertTrue(!pc.getListeners().contains(factory)); // verify cleanup
assertEquals(2, pool.getNumActive());
assertEquals(0, pool.getNumIdle());
-
+
// Return good connections back to pool
pcon2.getConnection().close();
pcon3.getConnection().close();
assertEquals(2, pool.getNumIdle());
assertEquals(0, pool.getNumActive());
-
+
// Verify pc is closed
try {
pc.getConnection();
@@ -142,12 +142,12 @@ public class TestCPDSConnectionFactory e
} catch (SQLException ex) {
// expected
}
-
+
// Back from the dead - ignore the ghost!
con1.close();
assertEquals(2, pool.getNumIdle());
assertEquals(0, pool.getNumActive());
-
+
// Clear pool
factory.getPool().clear();
assertEquals(0, pool.getNumIdle());