assertEquals(DATASOURCE1_NAME, ((ConnectionQueuedEvent) orderedEvents.get(i++)).getPooledConnectionImpl().getPoolingDataSource().getUniqueName());
}
public void testClosingSuspendedConnections() throws Exception {
if (log.isDebugEnabled()) log.debug("*** getting TM");
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
if (log.isDebugEnabled()) log.debug("*** before begin");
tm.begin();
if (log.isDebugEnabled()) log.debug("*** getting connection from DS1");
Connection connection1 = poolingDataSource1.getConnection();
connection1.createStatement();
assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());
if (log.isDebugEnabled()) log.debug("*** suspending");
Transaction t1 = tm.suspend();
assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());
if (log.isDebugEnabled()) log.debug("*** closing connection 1 too eagerly");
try {
// TODO: the TM tries to 'veto' the connection close here like the old pool did.
// Instead, close the resource immediately or defer its release.
connection1.close();
fail("successfully closed a connection participating in a global transaction, this should never be allowed");
} catch (SQLException ex) {
assertEquals("cannot close a resource when its XAResource is taking part in an unfinished global transaction", ex.getCause().getMessage());
}
assertFalse(connection1.isClosed());
assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());
if (log.isDebugEnabled()) log.debug("*** resuming");
tm.resume(t1);
assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());
if (log.isDebugEnabled()) log.debug("*** committing");
tm.commit();
if (log.isDebugEnabled()) log.debug("*** TX is done");
assertEquals(POOL_SIZE -1, getPool(poolingDataSource1).inPoolSize());
if (log.isDebugEnabled()) log.debug("*** closing connection 1");