use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.
the class IsTransactedTestCase method testIsTransacted.
@Test
public void testIsTransacted() throws Exception {
MuleTransactionConfig cfg = new MuleTransactionConfig();
TestTransaction testTx = new TestTransaction(mockMuleContext());
cfg.setAction(TransactionConfig.ACTION_NEVER);
assertFalse(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_NEVER);
assertFalse(cfg.isTransacted());
cfg.setFactory(new TransactedFactory());
cfg.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
assertTrue(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_ALWAYS_JOIN);
assertTrue(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_BEGIN_OR_JOIN);
assertTrue(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().bindTransaction(testTx);
assertTrue(cfg.isTransacted());
TransactionCoordination.getInstance().unbindTransaction(testTx);
cfg.setAction(TransactionConfig.ACTION_INDIFFERENT);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().bindTransaction(testTx);
assertTrue(cfg.isTransacted());
TransactionCoordination.getInstance().unbindTransaction(testTx);
cfg.setFactory(new NonTransactedFactory());
cfg.setAction(TransactionConfig.ACTION_ALWAYS_BEGIN);
assertFalse(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_ALWAYS_JOIN);
assertFalse(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_BEGIN_OR_JOIN);
assertFalse(cfg.isTransacted());
cfg.setAction(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().bindTransaction(testTx);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().unbindTransaction(testTx);
cfg.setAction(TransactionConfig.ACTION_INDIFFERENT);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().bindTransaction(testTx);
assertFalse(cfg.isTransacted());
TransactionCoordination.getInstance().unbindTransaction(testTx);
}
use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.
the class DirectProcessingStrategyTestCase method tx.
@Override
@Description("Regardless of processor type, when the DirectProcessingStrategy is configured, the pipeline is executed " + "synchronously in a caller thread.")
public void tx() throws Exception {
flow = flowBuilder.get().processors(cpuLightProcessor, cpuIntensiveProcessor, blockingProcessor).build();
flow.initialise();
flow.start();
TransactionCoordination.getInstance().bindTransaction(new TestTransaction(muleContext));
processFlow(testEvent());
assertSynchronous(1);
}
use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.
the class ReactorProcessingStrategyTestCase method tx.
@Override
@Description("When the ReactorProcessingStrategy is configured and a transaction is active processing fails with an error")
public void tx() throws Exception {
flow = flowBuilder.get().processors(cpuLightProcessor, cpuIntensiveProcessor, blockingProcessor).build();
flow.initialise();
flow.start();
TransactionCoordination.getInstance().bindTransaction(new TestTransaction(muleContext));
expectedException.expect(MessagingException.class);
expectedException.expectCause(instanceOf(DefaultMuleException.class));
expectedException.expectCause(hasMessage(equalTo(TRANSACTIONAL_ERROR_MESSAGE)));
processFlow(testEvent());
}
use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.
the class TransactionAwareProactorStreamProcessingStrategyTestCase method tx.
@Override
@Description("Unlike with the MultiReactorProcessingStrategy, the TransactionAwareWorkQueueProcessingStrategy does not fail if a transaction " + "is active, but rather executes these events synchronously in the caller thread transparently.")
public void tx() throws Exception {
flow = flowBuilder.get().processors(cpuLightProcessor, cpuIntensiveProcessor, blockingProcessor).build();
flow.initialise();
flow.start();
TransactionCoordination.getInstance().bindTransaction(new TestTransaction(muleContext));
processFlow(testEvent());
assertThat(threads, hasSize(equalTo(1)));
assertThat(threads, not(hasItem(startsWith(CPU_LIGHT))));
assertThat(threads, not(hasItem(startsWith(IO))));
assertThat(threads, not(hasItem(startsWith(CPU_INTENSIVE))));
assertThat(threads, not(hasItem(startsWith(CUSTOM))));
}
use of org.mule.tck.testmodels.mule.TestTransaction 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);
}
}
Aggregations