Search in sources :

Example 6 with TestTransaction

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);
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Test(org.junit.Test)

Example 7 with TestTransaction

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);
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Description(io.qameta.allure.Description)

Example 8 with TestTransaction

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());
}
Also used : DefaultMuleException(org.mule.runtime.api.exception.DefaultMuleException) TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Description(io.qameta.allure.Description)

Example 9 with TestTransaction

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))));
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Description(io.qameta.allure.Description)

Example 10 with TestTransaction

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);
    }
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Transaction(org.mule.runtime.core.api.transaction.Transaction) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Test(org.junit.Test)

Aggregations

TestTransaction (org.mule.tck.testmodels.mule.TestTransaction)18 Test (org.junit.Test)12 SmallTest (org.mule.tck.size.SmallTest)9 Description (io.qameta.allure.Description)7 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)3 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 Transaction (org.mule.runtime.core.api.transaction.Transaction)1