Search in sources :

Example 11 with TestTransaction

use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.

the class TransactionAwareWorkQueueProcessingStrategyTestCase method tx.

@Test
@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) Test(org.junit.Test)

Example 12 with TestTransaction

use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.

the class TransactionAwareWorkQueueStreamProcessingStrategyTestCase 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 13 with TestTransaction

use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.

the class WorkQueueProcessingStrategyTestCase method tx.

@Override
@Description("When the WorkQueueProcessingStrategy 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 14 with TestTransaction

use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.

the class TransactionCoordinationTestCase method testCommitCurrentTransactionWithSuspendedTransaction.

@Test
public void testCommitCurrentTransactionWithSuspendedTransaction() throws Exception {
    assertThat(tc.getTransaction(), nullValue());
    TestTransaction xaTx = spy(new TestTransaction(muleContext));
    xaTx.setXA(true);
    Transaction tx = spy(new TestTransaction(muleContext));
    tc.bindTransaction(xaTx);
    tc.suspendCurrentTransaction();
    tc.bindTransaction(tx);
    tc.commitCurrentTransaction();
    tc.resumeSuspendedTransaction();
    assertThat((TestTransaction) tc.getTransaction(), is(xaTx));
    verify(xaTx, times(1)).suspend();
    verify(xaTx, times(1)).resume();
    verify(tx, times(1)).commit();
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 15 with TestTransaction

use of org.mule.tck.testmodels.mule.TestTransaction in project mule by mulesoft.

the class TransactionCoordinationTestCase method testResolveTransactionForCommit.

@Test
public void testResolveTransactionForCommit() throws Exception {
    assertThat(tc.getTransaction(), nullValue());
    TestTransaction tx = spy(new TestTransaction(muleContext));
    tx.setXA(true);
    tc.bindTransaction(tx);
    tc.resolveTransaction();
    assertThat(tc.getTransaction(), nullValue());
    verify(tx, times(1)).commit();
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

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