org.apache.commons.dbcp
Class TestConnectionPool

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.apache.commons.dbcp.TestConnectionPool
All Implemented Interfaces:
junit.framework.Test
Direct Known Subclasses:
TestBasicDataSource, TestJOCLed, TestManagedDataSource, TestManual, TestPerUserPoolDataSource, TestPoolingDataSource, TestSharedPoolDataSource

public abstract class TestConnectionPool
extends junit.framework.TestCase

Base test suite for DBCP pools.

Version:
$Revision: 1023401 $ $Date: 2010-10-16 21:54:24 -0400 (Sat, 16 Oct 2010) $
Author:
Rodney Waldhoff, Sean C. Sullivan, John McNally, Dirk Verbeeck

Nested Class Summary
protected  class TestConnectionPool.PoolTest
           
 
Field Summary
protected  Stack connections
          Connections opened during the course of a test
 
Constructor Summary
TestConnectionPool(String testName)
           
 
Method Summary
protected  void assertBackPointers(Connection conn, Statement statement)
           
protected abstract  Connection getConnection()
           
protected  int getMaxActive()
           
protected  long getMaxWait()
           
protected  String getUsername(Connection conn)
           
protected  boolean isClosed(ResultSet resultSet)
           
protected  boolean isClosed(Statement statement)
           
protected  void multipleThreads(int holdTime, boolean expectError, boolean loopOnce, long maxWait)
          Launches a group of 2 * getMaxActive() threads, each of which will attempt to obtain a connection from the pool, hold it for ms, and then return it to the pool.
protected  Connection newConnection()
          Acquire a connection and push it onto the connections stack
 void tearDown()
           
 void testAutoCommitBehavior()
           
 void testBackPointers()
           
 void testCanCloseCallableStatementTwice()
           
 void testCanCloseConnectionTwice()
          Verify the close method can be called multiple times on a single connection without an exception being thrown.
 void testCanClosePreparedStatementTwice()
           
 void testCanCloseResultSetTwice()
           
 void testCanCloseStatementTwice()
           
 void testClearWarnings()
           
 void testClosing()
           
 void testConnectionsAreDistinct()
           
 void testHashCode()
           
 void testHashing()
          DBCP-128: BasicDataSource.getConnection() Connections don't work as hashtable keys
 void testIsClosed()
           
 void testMaxActive()
           
 void testNoRsetClose()
           
 void testOpening()
           
 void testPooling()
           
 void testPrepareStatementOptions()
           
 void testRepeatedBorrowAndReturn()
           
 void testSimple()
           
 void testSimple2()
           
 void testThreaded()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, runTest, setName, setUp, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

connections

protected Stack connections
Connections opened during the course of a test

Constructor Detail

TestConnectionPool

public TestConnectionPool(String testName)
Method Detail

tearDown

public void tearDown()
              throws Exception
Overrides:
tearDown in class junit.framework.TestCase
Throws:
Exception

getConnection

protected abstract Connection getConnection()
                                     throws Exception
Throws:
Exception

getMaxActive

protected int getMaxActive()

getMaxWait

protected long getMaxWait()

newConnection

protected Connection newConnection()
                            throws Exception
Acquire a connection and push it onto the connections stack

Throws:
Exception

getUsername

protected String getUsername(Connection conn)
                      throws SQLException
Throws:
SQLException

testClearWarnings

public void testClearWarnings()
                       throws Exception
Throws:
Exception

testIsClosed

public void testIsClosed()
                  throws Exception
Throws:
Exception

testCanCloseConnectionTwice

public void testCanCloseConnectionTwice()
                                 throws Exception
Verify the close method can be called multiple times on a single connection without an exception being thrown.

Throws:
Exception

testCanCloseStatementTwice

public void testCanCloseStatementTwice()
                                throws Exception
Throws:
Exception

testCanClosePreparedStatementTwice

public void testCanClosePreparedStatementTwice()
                                        throws Exception
Throws:
Exception

testCanCloseCallableStatementTwice

public void testCanCloseCallableStatementTwice()
                                        throws Exception
Throws:
Exception

testCanCloseResultSetTwice

public void testCanCloseResultSetTwice()
                                throws Exception
Throws:
Exception

testBackPointers

public void testBackPointers()
                      throws Exception
Throws:
Exception

assertBackPointers

protected void assertBackPointers(Connection conn,
                                  Statement statement)
                           throws SQLException
Throws:
SQLException

testSimple

public void testSimple()
                throws Exception
Throws:
Exception

testRepeatedBorrowAndReturn

public void testRepeatedBorrowAndReturn()
                                 throws Exception
Throws:
Exception

testSimple2

public void testSimple2()
                 throws Exception
Throws:
Exception

testPooling

public void testPooling()
                 throws Exception
Throws:
Exception

testAutoCommitBehavior

public void testAutoCommitBehavior()
                            throws Exception
Throws:
Exception

testConnectionsAreDistinct

public void testConnectionsAreDistinct()
                                throws Exception
Throws:
Exception
See Also:
"http://issues.apache.org/bugzilla/show_bug.cgi?id=12400"

testOpening

public void testOpening()
                 throws Exception
Throws:
Exception

testClosing

public void testClosing()
                 throws Exception
Throws:
Exception

testMaxActive

public void testMaxActive()
                   throws Exception
Throws:
Exception

testHashing

public void testHashing()
                 throws Exception
DBCP-128: BasicDataSource.getConnection() Connections don't work as hashtable keys

Throws:
Exception

testThreaded

public void testThreaded()

testPrepareStatementOptions

public void testPrepareStatementOptions()
                                 throws Exception
Throws:
Exception

testNoRsetClose

public void testNoRsetClose()
                     throws Exception
Throws:
Exception

testHashCode

public void testHashCode()
                  throws Exception
Throws:
Exception

isClosed

protected boolean isClosed(Statement statement)

isClosed

protected boolean isClosed(ResultSet resultSet)

multipleThreads

protected void multipleThreads(int holdTime,
                               boolean expectError,
                               boolean loopOnce,
                               long maxWait)
                        throws Exception
Launches a group of 2 * getMaxActive() threads, each of which will attempt to obtain a connection from the pool, hold it for ms, and then return it to the pool. If is false, threads will continue this process indefinitely. If is true, exactly 1/2 of the threads are expected to either throw exceptions or fail to complete. If is false, all threads are expected to complete successfully.

Parameters:
holdTime - time in ms that a thread holds a connection before returning it to the pool
expectError - whether or not an error is expected
loopOnce - whether threads should complete the borrow - hold - return cycle only once, or loop indefinitely
maxWait - passed in by client - has no impact on the test itself, but does get reported
Throws:
Exception


Copyright © 2001-2010 The Apache Software Foundation. All Rights Reserved.