}
public void testClosingSuspendedConnectionsInDifferentContext() throws Exception {
if (log.isDebugEnabled()) { log.debug("*** getting TM"); }
BitronixTransactionManager tm = TransactionManagerServices.getTransactionManager();
if (log.isDebugEnabled()) { log.debug("*** before begin"); }
tm.begin();
XAPool pool1 = getPool(poolingDataSource1);
assertEquals(POOL_SIZE, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** getting connection from DS1"); }
Connection connection1 = poolingDataSource1.getConnection();
connection1.createStatement();
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** suspending"); }
Transaction t1 = tm.suspend();
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** starting 2nd tx"); }
tm.begin();
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** closing connection 1 too eagerly within another context"); }
try {
// TODO: the ConnectionHandler 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());
}
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** committing 2nd tx"); }
tm.commit();
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** resuming"); }
tm.resume(t1);
assertEquals(POOL_SIZE -1, pool1.inPoolSize());
if (log.isDebugEnabled()) { log.debug("*** committing"); }
tm.commit();
if (log.isDebugEnabled()) { log.debug("*** TX is done"); }
if (log.isDebugEnabled()) { log.debug("*** closing connection 1"); }
connection1.close();