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));
}
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();
}
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());
}
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();
}
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);
}
}
Aggregations