assertTrue("Expected TransactionContext to report inactive", !TransactionContext.getContext().isActive());
}
public void testTransactionIndependence() throws Exception {
ContainerTransactionContext transactionContext1 = new ContainerTransactionContext(transactionManager);
TransactionContext.setContext(transactionContext1);
transactionContext1.begin();
ConnectionInfo connectionInfo1 = makeConnectionInfo();
transactionCachingInterceptor.getConnection(connectionInfo1);
obtainedConnectionInfo = null;
//start a second transaction
transactionContext1.suspend();
ContainerTransactionContext transactionContext2 = new ContainerTransactionContext(transactionManager);
TransactionContext.setContext(transactionContext2);
transactionContext2.begin();
ConnectionInfo connectionInfo2 = makeConnectionInfo();
transactionCachingInterceptor.getConnection(connectionInfo2);
assertTrue("Expected to get a second connection", obtainedConnectionInfo != null);
assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
assertTrue("Expected different ManagedConnectionInfo in each ConnectionInfos",
connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
connectionInfo2.getManagedConnectionInfo() == transactionContext2.getManagedConnectionInfo(transactionCachingInterceptor));
//commit 2nd transaction, see if connection returned.
//we didn't create any handles, so the "ManagedConnection" should be returned.
assertTrue("Expected TransactionContext to report active", transactionContext2.isActive());
transactionContext2.commit();
assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
assertTrue("Expected TransactionContext to report inactive", !transactionContext2.isActive());
returnedConnectionInfo = null;
//resume first transaction
transactionContext1.resume();
transactionContext1.commit();
assertTrue("Expected connection to be returned", returnedConnectionInfo != null);