Search in sources :

Example 1 with ServerVMClientUserTransaction

use of org.jboss.tm.usertx.client.ServerVMClientUserTransaction in project narayana by jbosstm.

the class TestUTSerializability method svmUTTest.

@Test
public void svmUTTest() throws NamingException {
    InitialContext context = new InitialContext(null);
    // ensure the transaction manager is available via JNDI
    JNDIManager.bindJTATransactionManagerImplementation(context);
    ServerVMClientUserTransaction ut = ServerVMClientUserTransaction.getSingleton();
    // validate that ut can be bound to a JNDI context
    context.rebind("ut", ut);
    // validate that the instance that was bound is the same as the ServerVMClientUserTransaction singleton
    Object boundUT = context.lookup("ut");
    assertNotNull(boundUT);
    assertTrue(boundUT instanceof ServerVMClientUserTransaction);
    assertEquals(ut, boundUT);
}
Also used : ServerVMClientUserTransaction(org.jboss.tm.usertx.client.ServerVMClientUserTransaction) InitialContext(javax.naming.InitialContext) Test(org.junit.Test)

Example 2 with ServerVMClientUserTransaction

use of org.jboss.tm.usertx.client.ServerVMClientUserTransaction in project narayana by jbosstm.

the class TransactionListenerRegistryTest method runTxn.

private EnumSet<EventType> runTxn(TransactionManager tm) throws SystemException, TransactionTypeNotSupported, NotSupportedException, HeuristicRollbackException, HeuristicMixedException, RollbackException {
    ServerVMClientUserTransaction userTransaction = new ServerVMClientUserTransaction(tm);
    TransactionListenerRegistry listenerRegistration = (TransactionListenerRegistry) tm;
    final EnumSet<EventType> log = EnumSet.noneOf(EventType.class);
    TransactionListener listener = new TransactionListener() {

        @Override
        public void onEvent(TransactionEvent transactionEvent) {
            Iterator<EventType> events = transactionEvent.getTypes().iterator();
            while (events.hasNext()) {
                EventType e = events.next();
                log.add(e);
                System.out.printf("TransactionEvent: %s%n", e);
            }
        }
    };
    // clean the thread
    tm.suspend();
    userTransaction.begin();
    listenerRegistration.addListener(tm.getTransaction(), listener, EnumSet.allOf(EventType.class));
    userTransaction.commit();
    return log;
}
Also used : ServerVMClientUserTransaction(org.jboss.tm.usertx.client.ServerVMClientUserTransaction)

Example 3 with ServerVMClientUserTransaction

use of org.jboss.tm.usertx.client.ServerVMClientUserTransaction in project narayana by jbosstm.

the class SPIUnitTest method initJTS.

public static void initJTS() throws Exception {
    initORB();
    JTAEnvironmentBean jtaEnvironmentBean = jtaPropertyManager.getJTAEnvironmentBean();
    jtaEnvironmentBean.setTransactionManagerClassName(com.arjuna.ats.jbossatx.jts.TransactionManagerDelegate.class.getName());
    JNDIManager.bindJTATransactionManagerImplementation(initialContext);
    jtaEnvironmentBean.setTransactionSynchronizationRegistryClassName(com.arjuna.ats.internal.jta.transaction.jts.TransactionSynchronizationRegistryImple.class.getName());
    JNDIManager.bindJTATransactionSynchronizationRegistryImplementation(initialContext);
    final com.arjuna.ats.jbossatx.jts.TransactionManagerService service = new com.arjuna.ats.jbossatx.jts.TransactionManagerService();
    final ServerVMClientUserTransaction userTransaction = new ServerVMClientUserTransaction(service.getTransactionManager());
    jtaEnvironmentBean.setUserTransaction(userTransaction);
    JNDIManager.bindJTAUserTransactionImplementation(initialContext);
    UserTransactionRegistry userTransactionRegistry = new UserTransactionRegistry();
    userTransactionRegistry.addProvider(userTransaction);
}
Also used : ServerVMClientUserTransaction(org.jboss.tm.usertx.client.ServerVMClientUserTransaction) JTAEnvironmentBean(com.arjuna.ats.jta.common.JTAEnvironmentBean) UserTransactionRegistry(org.jboss.tm.usertx.UserTransactionRegistry) javax.transaction(javax.transaction)

Example 4 with ServerVMClientUserTransaction

use of org.jboss.tm.usertx.client.ServerVMClientUserTransaction in project narayana by jbosstm.

the class TransactionListenerRegistryTest method test.

@Test
public void test() throws SystemException, NotSupportedException, RollbackException, TransactionTypeNotSupported, InterruptedException, InvalidTransactionException, HeuristicRollbackException, HeuristicMixedException {
    TransactionManager tm = new TransactionManagerDelegate();
    ServerVMClientUserTransaction userTransaction = new ServerVMClientUserTransaction(tm);
    userTransaction.setTransactionTimeout(1);
    for (CompletionType completionType : CompletionType.values()) {
        TransactionListenerRegistry listenerRegistration = (TransactionListenerRegistry) tm;
        userTransaction.begin();
        // The TSR for interposed synchronizations
        final TransactionSynchronizationRegistry tsr = new TransactionSynchronizationRegistryImple();
        final TxListener listener = new TxListener(listenerRegistration);
        if (completionType != CompletionType.CMTSUSPEND) {
            tsr.registerInterposedSynchronization(listener);
        } else {
            tm.getTransaction().registerSynchronization(listener);
        }
        listenerRegistration.addListener(tm.getTransaction(), listener, EnumSet.allOf(EventType.class));
        if (completionType == CompletionType.CMTSUSPEND) {
            Transaction suspended = tm.suspend();
            Thread.sleep(2000);
            assertTrue(listener.shouldDisassoc());
            tm.resume(suspended);
        } else {
            Thread.sleep(2000);
            assertFalse(listener.shouldDisassoc());
        }
        assertTrue(listener.singleCallAC());
        assertTrue(Status.STATUS_ROLLEDBACK == userTransaction.getStatus());
        // https://community.jboss.org/thread/92489
        if (completionType == CompletionType.BMTCOMMIT) {
            try {
                userTransaction.commit();
                fail("Should not have been able to commit");
            } catch (RollbackException e) {
            }
        } else if (completionType == CompletionType.BMTROLLBACK) {
            userTransaction.rollback();
        } else if (completionType == CompletionType.CMT) {
            // This is possible in CMT mode
            // If they did check the status, it is still expected that a CMT
            // calls suspend at least when a tx is marked as completed to
            // clear
            // it from the thread
            tm.suspend();
        }
        assertTrue(listener.singleCallAC());
        if (completionType == CompletionType.CMTSUSPEND) {
            assertFalse(listener.shouldDisassoc());
        } else {
            assertTrue(listener.shouldDisassoc());
        }
        assertTrue(listener.isClosed());
    }
}
Also used : ServerVMClientUserTransaction(org.jboss.tm.usertx.client.ServerVMClientUserTransaction) TransactionSynchronizationRegistryImple(com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple) TransactionManagerDelegate(com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate) Transaction(javax.transaction.Transaction) ServerVMClientUserTransaction(org.jboss.tm.usertx.client.ServerVMClientUserTransaction) TransactionManager(javax.transaction.TransactionManager) TransactionSynchronizationRegistry(javax.transaction.TransactionSynchronizationRegistry) TxListener(com.arjuna.ats.jta.distributed.spi.TxListener) HeuristicRollbackException(javax.transaction.HeuristicRollbackException) RollbackException(javax.transaction.RollbackException) Test(org.junit.Test)

Aggregations

ServerVMClientUserTransaction (org.jboss.tm.usertx.client.ServerVMClientUserTransaction)4 Test (org.junit.Test)2 TransactionSynchronizationRegistryImple (com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionSynchronizationRegistryImple)1 TransactionManagerDelegate (com.arjuna.ats.jbossatx.jta.TransactionManagerDelegate)1 JTAEnvironmentBean (com.arjuna.ats.jta.common.JTAEnvironmentBean)1 TxListener (com.arjuna.ats.jta.distributed.spi.TxListener)1 InitialContext (javax.naming.InitialContext)1 javax.transaction (javax.transaction)1 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 RollbackException (javax.transaction.RollbackException)1 Transaction (javax.transaction.Transaction)1 TransactionManager (javax.transaction.TransactionManager)1 TransactionSynchronizationRegistry (javax.transaction.TransactionSynchronizationRegistry)1 UserTransactionRegistry (org.jboss.tm.usertx.UserTransactionRegistry)1