use of org.mule.runtime.core.api.transaction.Transaction in project mule by mulesoft.
the class AsyncDelegateMessageProcessorTestCase method processWithTx.
@Test
public void processWithTx() throws Exception {
Transaction transaction = new TestTransaction(muleContext);
TransactionCoordination.getInstance().bindTransaction(transaction);
try {
CoreEvent request = testEvent();
CoreEvent result = process(messageProcessor, request);
// Wait until processor in async is executed to allow assertions on sensed event
asyncEntryLatch.countDown();
assertThat(latch.await(LOCK_TIMEOUT, MILLISECONDS), is(true));
assertTargetEvent(request);
assertResponse(result);
} finally {
TransactionCoordination.getInstance().unbindTransaction(transaction);
}
}
use of org.mule.runtime.core.api.transaction.Transaction in project mule by mulesoft.
the class BeginAndResolveTransactionInterceptor method execute.
@Override
public T execute(ExecutionCallback<T> callback, ExecutionContext executionContext) throws Exception {
byte action = transactionConfig.getAction();
int timeout = transactionConfig.getTimeout();
boolean resolveStartedTransaction = false;
Transaction tx = TransactionCoordination.getInstance().getTransaction();
if (action == TransactionConfig.ACTION_ALWAYS_BEGIN || (action == TransactionConfig.ACTION_BEGIN_OR_JOIN && tx == null)) {
if (logger.isDebugEnabled()) {
logger.debug("Beginning transaction");
}
executionContext.markTransactionStart();
tx = transactionConfig.getFactory().beginTransaction(muleContext);
// Timeout is a traversal attribute of all Transaction implementations.
// Setting it up here for all of them rather than in every implementation.
tx.setTimeout(timeout);
resolveStartedTransaction = true;
if (logger.isDebugEnabled()) {
logger.debug("Transaction successfully started: " + tx);
}
}
T result;
try {
result = next.execute(callback, executionContext);
resolveTransactionIfRequired(resolveStartedTransaction);
return result;
} catch (MessagingException e) {
if (processOnException) {
resolveTransactionIfRequired(resolveStartedTransaction || mustResolveAnyTransaction);
}
throw e;
}
}
use of org.mule.runtime.core.api.transaction.Transaction in project mule by mulesoft.
the class ResolvePreviousTransactionInterceptor method execute.
@Override
public T execute(ExecutionCallback<T> callback, ExecutionContext executionContext) throws Exception {
byte action = transactionConfig.getAction();
Transaction transactionBeforeTemplate = TransactionCoordination.getInstance().getTransaction();
if ((action == TransactionConfig.ACTION_NONE || action == TransactionConfig.ACTION_ALWAYS_BEGIN) && transactionBeforeTemplate != null) {
if (logger.isDebugEnabled()) {
logger.debug(action + ", " + "current TX: " + transactionBeforeTemplate);
}
resolveTransaction();
}
return next.execute(callback, executionContext);
}
use of org.mule.runtime.core.api.transaction.Transaction in project mule by mulesoft.
the class PetStoreRetryPolicyProviderConnectionTestCase method createTransactionMock.
private Transaction createTransactionMock() throws TransactionException {
Transaction transaction = mock(Transaction.class);
doAnswer((invocationOnMock -> {
TransactionCoordination.getInstance().bindTransaction(transaction);
return null;
})).when(transaction).begin();
return transaction;
}
use of org.mule.runtime.core.api.transaction.Transaction in project mule by mulesoft.
the class OnErrorContinueHandlerTestCase method before.
@Override
@Before
public void before() throws Exception {
super.before();
Transaction currentTransaction = TransactionCoordination.getInstance().getTransaction();
if (currentTransaction != null) {
TransactionCoordination.getInstance().unbindTransaction(currentTransaction);
}
onErrorContinueHandler = new OnErrorContinueHandler();
onErrorContinueHandler.setAnnotations(getFlowComponentLocationAnnotations(flow.getName()));
onErrorContinueHandler.setMuleContext(muleContext);
onErrorContinueHandler.setNotificationFirer(mock(NotificationDispatcher.class));
}
Aggregations