assertTrue("Expected TransactionContext to report inactive", !transactionContext.isActive());
}
public void testGetUnshareableConnectionsInTransaction() throws Exception {
TransactionContext transactionContext = transactionContextManager.newContainerTransactionContext();
ConnectionInfo connectionInfo1 = makeConnectionInfo();
connectionInfo1.setUnshareable(true);
transactionCachingInterceptor.getConnection(connectionInfo1);
assertTrue("Expected to get an initial connection", obtainedConnectionInfo != null);
assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
assertTrue("Expected different ManagedConnectionInfo in the TransactionContext as was returned",
connectionInfo1.getManagedConnectionInfo()
!= getSharedManagedConnectionInfo(transactionContext));
//2nd is shared, modelling a call into another ejb
obtainedConnectionInfo = null;
ConnectionInfo connectionInfo2 = makeConnectionInfo();
transactionCachingInterceptor.getConnection(connectionInfo2);
assertTrue("Expected to get a second connection", obtainedConnectionInfo != null);
assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
assertTrue("Expected the same ManagedConnectionInfo in both ConnectionInfos",
connectionInfo1.getManagedConnectionInfo() != connectionInfo2.getManagedConnectionInfo());
assertTrue("Expected the same ManagedConnectionInfo in the TransactionContext as was returned",
connectionInfo2.getManagedConnectionInfo() == getSharedManagedConnectionInfo(transactionContext));
//3rd is unshared, modelling a call into a third ejb
obtainedConnectionInfo = null;
ConnectionInfo connectionInfo3 = makeConnectionInfo();
connectionInfo3.setUnshareable(true);
transactionCachingInterceptor.getConnection(connectionInfo3);
assertTrue("Expected to get a third connection", obtainedConnectionInfo != null);
assertTrue("Expected nothing returned yet", returnedConnectionInfo == null);
assertTrue("Expected different ManagedConnectionInfo in both unshared ConnectionInfos",
connectionInfo1.getManagedConnectionInfo() != connectionInfo3.getManagedConnectionInfo());
assertTrue("Expected different ManagedConnectionInfo in the TransactionContext as was returned",
connectionInfo3.getManagedConnectionInfo() != getSharedManagedConnectionInfo(transactionContext));
//commit, see if connection returned.
//we didn't create any handles, so the "ManagedConnection" should be returned.
assertTrue("Expected TransactionContext to report active", transactionContext.isActive());
transactionContext.commit();
assertTrue("Expected connection to be returned", returnedConnectionInfo != null);
assertTrue("Expected TransactionContext to report inactive", !transactionContext.isActive());
}