Examples of ITransactionManager


Examples of com.alu.e3.common.transaction.ITransactionManager

public class TestTransactionManagement {

  @Test
  public void testTransactionInCurrentThread() throws Exception {
    ITransactionManager txMnger = new TransactionManager();
    assertNull(txMnger.getTransactionContext());

    // create, begin, commit, end
    ITransaction tx = txMnger.getNewTransaction();
    assertNotNull(tx);

    // Not transaction id until the transaction has begun
    assertNull(tx.getTransactionId());
    // Not transaction context until the transaction has begun
    assertNull(txMnger.getTransactionContext());


    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.end();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // create, begin, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // begin, commit, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());
  }
View Full Code Here

Examples of com.alu.e3.common.transaction.ITransactionManager

    // 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);
    assertTrue(transactionState1.getTransactionId() != transactionState3.getTransactionId());
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.