Search in sources :

Example 1 with XaTransaction

use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.

the class XaTransactionTestCase method recognizeDifferentWrappersOfSameResource.

@Test
public void recognizeDifferentWrappersOfSameResource() throws Exception {
    XaTransaction xaTransaction = new XaTransaction(mockMuleContext);
    Object resourceFactory = new Object();
    Object resource = new Object();
    when(mockXaResourceFactoryHolder1.getHoldObject()).thenReturn(resourceFactory);
    when(mockXaResourceFactoryHolder2.getHoldObject()).thenReturn(resourceFactory);
    xaTransaction.bindResource(mockXaResourceFactoryHolder1, resource);
    assertThat(xaTransaction.hasResource(mockXaResourceFactoryHolder1), is(true));
    assertThat(xaTransaction.hasResource(mockXaResourceFactoryHolder2), is(true));
    assertThat(xaTransaction.getResource(mockXaResourceFactoryHolder2), is(resource));
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 2 with XaTransaction

use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.

the class XaTransactionTestCase method setsTransactionTimeoutOnBegin.

@Test
public void setsTransactionTimeoutOnBegin() throws Exception {
    final int timeoutMillis = 5000;
    final int timeoutSecs = timeoutMillis / 1000;
    XaTransaction xaTransaction = new XaTransaction(mockMuleContext);
    xaTransaction.setTimeout(timeoutMillis);
    xaTransaction.begin();
    final InOrder inOrder = inOrder(mockTransactionManager);
    inOrder.verify(mockTransactionManager).setTransactionTimeout(timeoutSecs);
    inOrder.verify(mockTransactionManager).begin();
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) InOrder(org.mockito.InOrder) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 3 with XaTransaction

use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.

the class XaTransactionTestCase method isRollbackOnly.

@Test
public void isRollbackOnly() throws Exception {
    javax.transaction.Transaction tx = mock(javax.transaction.Transaction.class);
    when(tx.getStatus()).thenReturn(Transaction.STATUS_ACTIVE).thenReturn(Transaction.STATUS_COMMITTED).thenReturn(Transaction.STATUS_MARKED_ROLLBACK).thenReturn(Transaction.STATUS_ROLLEDBACK).thenReturn(Transaction.STATUS_ROLLING_BACK);
    when(mockTransactionManager.getTransaction()).thenReturn(tx);
    XaTransaction xaTransaction = new XaTransaction(mockMuleContext);
    xaTransaction.begin();
    assertFalse(xaTransaction.isRollbackOnly());
    assertFalse(xaTransaction.isRollbackOnly());
    assertTrue(xaTransaction.isRollbackOnly());
    assertTrue(xaTransaction.isRollbackOnly());
    assertTrue(xaTransaction.isRollbackOnly());
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 4 with XaTransaction

use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.

the class XAExtensionTransactionalResource method enlist.

/**
 * {@inheritDoc}
 */
@Override
public boolean enlist() throws TransactionException {
    XaTransaction transaction = getTransaction();
    synchronized (this) {
        if (!isEnlisted()) {
            final XAResource xaResource = getConnection().getXAResource();
            boolean wasAbleToEnlist = transaction.enlistResource(xaResource);
            if (wasAbleToEnlist) {
                enlistedXAResource = xaResource;
            }
        }
    }
    return isEnlisted();
}
Also used : XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) XAResource(javax.transaction.xa.XAResource)

Example 5 with XaTransaction

use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.

the class XaTransactionFactory method joinExternalTransaction.

/**
 * Create a Mule transaction that represents a transaction started outside of Mule
 */
public Transaction joinExternalTransaction(MuleContext muleContext) throws TransactionException {
    try {
        TransactionManager txManager = muleContext.getTransactionManager();
        if (txManager.getTransaction() == null) {
            return null;
        }
        XaTransaction xat = new ExternalXaTransaction(muleContext);
        xat.begin();
        return xat;
    } catch (Exception e) {
        throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
    }
}
Also used : ExternalXaTransaction(org.mule.runtime.core.internal.transaction.ExternalXaTransaction) XaTransaction(org.mule.runtime.core.privileged.transaction.XaTransaction) TransactionException(org.mule.runtime.api.tx.TransactionException) TransactionManager(javax.transaction.TransactionManager) ExternalXaTransaction(org.mule.runtime.core.internal.transaction.ExternalXaTransaction) TransactionException(org.mule.runtime.api.tx.TransactionException)

Aggregations

XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)9 Test (org.junit.Test)6 SmallTest (org.mule.tck.size.SmallTest)4 TransactionManager (javax.transaction.TransactionManager)2 TransactionException (org.mule.runtime.api.tx.TransactionException)2 ExternalXaTransaction (org.mule.runtime.core.internal.transaction.ExternalXaTransaction)2 Transaction (javax.transaction.Transaction)1 XAResource (javax.transaction.xa.XAResource)1 InOrder (org.mockito.InOrder)1 ConnectionProvider (org.mule.runtime.api.connection.ConnectionProvider)1 TransactionConfig (org.mule.runtime.core.api.transaction.TransactionConfig)1 XATransactionalConnection (org.mule.runtime.extension.api.connectivity.XATransactionalConnection)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 ExecutionContextAdapter (org.mule.runtime.module.extension.api.runtime.privileged.ExecutionContextAdapter)1 XAExtensionTransactionalResource (org.mule.runtime.module.extension.internal.runtime.transaction.XAExtensionTransactionalResource)1