public final class PooledConnectionRegressionTest extends BaseTestCase
"Each call to PooledConnection.getConnection() must return a newly constructed Connection object that exhibits the default Connection behavior. Only the most recent Connection object produced from a particular PooledConnection is open. An existing Connection object is automatically closed, if the getConnection() method of its associated Pooled-Connection is called again, before it has been explicitly closed by the application. This gives the application server a way to 'take away' a Connection from the application if it wishes, and give it out to someone else. This capability will not likely be used frequently in practice."
"When the application calls Connection.close(), an event is triggered that tells the connection pool it can recycle the physical database connection. In other words, the event signals the connection pool that the PooledConnection object which originally produced the Connection object generating the event can be put back in the connection pool."
"A Connection-EventListener will also be notified when a fatal error occurs, so that it can make a note not to put a bad PooledConnection object back in the cache when the application finishes using it. When an error occurs, the ConnectionEventListener is notified by the JDBC driver, just before the driver throws an SQLException to the application to notify it of the same error. Note that automatic closing of a Connection object as discussed in the previous section does not generate a connection close event."
The JDBC 3.0 specification states the same in other words:"The Connection.close method closes the logical handle, but the physical connection is maintained. The connection pool manager is notified that the underlying PooledConnection object is now available for reuse. If the application attempts to reuse the logical handle, the Connection implementation throws an SQLException."
"For a given PooledConnection object, only the most recently produced logical Connection object will be valid. Any previously existing Connection object is automatically closed when the associated PooledConnection.getConnection method is called. Listeners (connection pool managers) are not notified in this case. This gives the application server a way to take a connection away from a client. This is an unlikely scenario but may be useful if the application server is trying to force an orderly shutdown."
"A connection pool manager shuts down a physical connection by calling the method PooledConnection.close. This method is typically called only in certain circumstances: when the application server is undergoing an orderly shutdown, when the connection cache is being reinitialized, or when the application server receives an event indicating that an unrecoverable error has occurred on the connection."
Even though the specification isn't clear about it, I think it is no use generating a close event when calling the method PooledConnection.close(), even if a logical Connection is open for this PooledConnection, bc the PooledConnection will obviously not be returned to the pool.| Modifier and Type | Class and Description |
|---|---|
protected class |
PooledConnectionRegressionTest.ConnectionListener
Listener for PooledConnection events.
|
BaseTestCase.MockConnectionConfiguration| Modifier and Type | Field and Description |
|---|---|
protected int |
closeEventCount |
protected int |
connectionErrorEventCount |
private javax.sql.ConnectionPoolDataSource |
cpds |
conn, dbClass, dbName, dbUrl, isOpenSSL, mainConnectionUrl, pstmt, rs, serverVersion, stmt, timeZoneFreeDbUrl| Constructor and Description |
|---|
PooledConnectionRegressionTest() |
| Modifier and Type | Method and Description |
|---|---|
private void |
checkConnectionReturnedToPool(ConnectionWrapper cw) |
private void |
checkReallyClosedConnection(ConnectionWrapper cw) |
void |
setUp()
Set up test case before a test is run.
|
void |
tearDown()
After the test is run.
|
void |
testBug35489()
Tests fix for BUG#35489 - Prepared statements from pooled connections cause NPE when closed() under JDBC4
|
void |
testBug7136()
Tests fix for BUG#7136 ...
|
void |
testCloseEvent()
Test the nb of closeEvents generated by a PooledConnection.
|
void |
testConnectionReclaim()
Test the nb of closeEvents generated when a Connection is reclaimed.
|
void |
testConnectionWrapperMethods() |
void |
testPacketTooLargeException()
Tests that PacketTooLargeException doesn't clober the connection.
|
appendRequiredProperties, assertByteArrayEquals, assertConnectionsHistory, assertEqualsFSAware, assertNonSecureConnection, assertResultSetLength, assertResultSetsEqual, assertSecureConnection, assertSecureConnection, assertSessionStatusEquals, assertThrows, assertThrows, assertThrows, assertThrows, cleanupTempFiles, createDatabase, createDatabase, createFunction, createFunction, createProcedure, createProcedure, createSchemaObject, createSchemaObject, createTable, createTable, createTable, createTable, createUser, createUser, createView, createView, currentTimeMillis, dropDatabase, dropDatabase, dropFunction, dropFunction, dropProcedure, dropProcedure, dropSchemaObject, dropSchemaObject, dropTable, dropTable, dropUser, dropUser, dropView, dropView, fillPrimitiveDefaults, getConnectionWithProps, getConnectionWithProps, getConnectionWithProps, getConnectionWithProps, getEncodedHostFromTestsuiteUrl, getEncodedHostPortPairFromTestsuiteUrl, getFailoverConnection, getFailoverConnection, getHostFreePropertiesFromTestsuiteUrl, getHostFreePropertiesFromTestsuiteUrl, getHostFromTestsuiteUrl, getInstanceNumber, getLoadBalancedConnection, getLoadBalancedConnection, getLoadBalancedConnection, getMysqlVariable, getMysqlVariable, getNewConnection, getNoDbUrl, getPort, getPortFreeHostname, getPortFromTestsuiteUrl, getPropertiesFromTestsuiteUrl, getPropertiesFromUrl, getRowCount, getSingleIndexedValueWithQuery, getSingleIndexedValueWithQuery, getSingleValue, getSingleValueWithQuery, getSourceReplicaReplicationConnection, getSourceReplicaReplicationConnection, getSourceReplicaUrl, getSourceReplicaUrl, getUnreliableFailoverConnection, getUnreliableFailoverConnection, getUnreliableLoadBalancedConnection, getUnreliableLoadBalancedConnection, getUnreliableMultiHostConnection, getUnreliableReplicationConnection, getUnreliableReplicationConnection, getUnreliableReplicationConnection, isClassAvailable, isCommunityEdition, isEnterpriseEdition, isMysqlRunningLocally, isRunningOnJRockit, isServerRunningOnWindows, isSysPropDefined, logDebug, newTempBinaryFile, randomString, removeHostRelatedProps, removeSqlMode, runLongTests, setUpBase, supportsLoadLocalInfile, supportsTestCachingSha2PasswordKeys, supportsTestCertificates, supportsTestSha256PasswordKeys, supportsTimeZoneNames, supportsTLSv1_2, tearDownBase, versionMeetsMinimum, versionMeetsMinimumprivate javax.sql.ConnectionPoolDataSource cpds
protected int closeEventCount
protected int connectionErrorEventCount
@BeforeEach
public void setUp()
throws java.lang.Exception
java.lang.Exception@AfterEach
public void tearDown()
throws java.lang.Exception
java.lang.Exception@Test
public void testBug7136()
throws java.lang.Exception
java.lang.Exception@Test
public void testConnectionReclaim()
throws java.lang.Exception
java.lang.Exception@Test
public void testPacketTooLargeException()
throws java.lang.Exception
java.lang.Exception@Test
public void testCloseEvent()
throws java.lang.Exception
java.lang.Exception@Test
public void testBug35489()
throws java.lang.Exception
java.lang.Exception@Test
public void testConnectionWrapperMethods()
throws java.lang.Exception
java.lang.Exceptionprivate void checkConnectionReturnedToPool(ConnectionWrapper cw) throws java.lang.Exception
java.lang.Exceptionprivate void checkReallyClosedConnection(ConnectionWrapper cw) throws java.lang.Exception
java.lang.Exception