// Create, then begin a transaction
TransactionContext transactionState1 = executor1.submit( new Callable<TransactionContext>() {
@Override
public TransactionContext call() throws Exception {
ITransactionManager txMnger = new TransactionManager();
ITransaction tx = txMnger.getNewTransaction();
tx.begin();
return txMnger.getTransactionContext();
}
}).get();
assertNotNull(transactionState1);
assertNotNull(transactionState1.getTransactionId());
// Later, a method in the same thread stack should be able to deal with the same transaction context
TransactionContext transactionState2 = executor1.submit( new Callable<TransactionContext>() {
@Override
public TransactionContext call() throws Exception {
ITransactionManager txMnger = new TransactionManager();
return txMnger.getTransactionContext();
}
}).get();
assertNotNull(transactionState2);
assertNotNull(transactionState2.getTransactionId());
assertEquals(transactionState1.getTransactionId(), transactionState2.getTransactionId());
// The transaction in a thread must not be viewable from another thread
ExecutorService executor2 = Executors.newSingleThreadScheduledExecutor();
TransactionContext transactionState3 = executor2.submit( new Callable<TransactionContext>() {
@Override
public TransactionContext call() throws Exception {
ITransactionManager txMnger = new TransactionManager();
return txMnger.getTransactionContext();
}
}).get();
assertNull (transactionState3);
transactionState3 = executor2.submit( new Callable<TransactionContext>() {
@Override
public TransactionContext call() throws Exception {
ITransactionManager txMnger = new TransactionManager();
ITransaction tx = txMnger.getNewTransaction();
tx.begin();
return txMnger.getTransactionContext();
}
}).get();
assertNotNull (transactionState3);