use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.
the class XaTransactionFactory method beginTransaction.
public Transaction beginTransaction(MuleContext muleContext) throws TransactionException {
try {
XaTransaction xat = new XaTransaction(muleContext);
xat.setTimeout(timeout);
xat.begin();
return xat;
} catch (Exception e) {
throw new TransactionException(CoreMessages.cannotStartTransaction("XA"), e);
}
}
use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.
the class ExtensionConnectionSupplierTestCase method xaTransaction.
@Test
public void xaTransaction() throws Exception {
muleContext.setTransactionManager(mock(TransactionManager.class, RETURNS_DEEP_STUBS));
XaTransaction transaction = spy(new XaTransaction(muleContext));
XATransactionalConnection connection = mock(XATransactionalConnection.class, RETURNS_DEEP_STUBS);
Object config = new Object();
ExecutionContextAdapter operationContext = mock(ExecutionContextAdapter.class, RETURNS_DEEP_STUBS);
ConnectionProvider connectionProvider = mock(ConnectionProvider.class);
ConfigurationInstance configurationInstance = mock(ConfigurationInstance.class);
when(configurationInstance.getConnectionProvider()).thenReturn(of(connectionProvider));
when(operationContext.getConfiguration()).thenReturn(of(configurationInstance));
when(configurationInstance.getValue()).thenReturn(config);
when(connectionProvider.connect()).thenReturn(connection);
TransactionConfig transactionConfig = mock(TransactionConfig.class);
when(transactionConfig.getAction()).thenReturn(ACTION_ALWAYS_JOIN);
when(transactionConfig.isTransacted()).thenReturn(true);
when(operationContext.getTransactionConfig()).thenReturn(of(transactionConfig));
connectionManager.bind(config, connectionProvider);
TransactionCoordination.getInstance().bindTransaction(transaction);
adapter.getConnection(operationContext);
verify(transaction).bindResource(any(), any(XAExtensionTransactionalResource.class));
}
use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.
the class AbstractTxThreadAssociationTestCase method testXaTransactionTermination.
/**
* This is a former XaTransactionTestCase.
*
* @throws Exception in case of any error
*/
@Test
public void testXaTransactionTermination() throws Exception {
muleContext.setTransactionManager(tm);
assertNull("There should be no current transaction associated.", tm.getTransaction());
// don't wait for ages, has to be set before TX is begun
tm.setTransactionTimeout(TRANSACTION_TIMEOUT_SECONDS);
XaTransaction muleTx = new XaTransaction(muleContext);
assertFalse(muleTx.isBegun());
assertEquals(Status.STATUS_NO_TRANSACTION, muleTx.getStatus());
muleTx.begin();
assertTrue(muleTx.isBegun());
muleTx.commit();
Transaction jtaTx = tm.getTransaction();
assertNull("Committing via TX Manager should have disassociated TX from the current thread.", jtaTx);
assertEquals(Status.STATUS_NO_TRANSACTION, muleTx.getStatus());
}
use of org.mule.runtime.core.privileged.transaction.XaTransaction in project mule by mulesoft.
the class XaTransactionTestCase method setTxTimeoutWhenEnlistingResource.
@Test
public void setTxTimeoutWhenEnlistingResource() throws Exception {
javax.transaction.Transaction tx = mock(javax.transaction.Transaction.class);
when(mockTransactionManager.getTransaction()).thenReturn(tx);
XaTransaction xaTransaction = new XaTransaction(mockMuleContext);
int timeoutValue = 1500;
int timeoutValueInSeconds = 1500 / 1000;
xaTransaction.setTimeout(timeoutValue);
xaTransaction.begin();
xaTransaction.enlistResource(mockXaResource);
verify(mockXaResource).setTransactionTimeout(timeoutValueInSeconds);
}
Aggregations