Search in sources :

Example 1 with MuleTransactionConfig

use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionNeverAndNoTx.

@Test
public void testActionNeverAndNoTx() throws Exception {
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NEVER);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
}
Also used : MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with MuleTransactionConfig

use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionNoneAndWithExternalTransactionWithNoTx.

@Test
public void testActionNoneAndWithExternalTransactionWithNoTx() throws Exception {
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
    config.setInteractWithExternal(true);
    mockExternalTransactionFactory = mock(ExternalTransactionAwareTransactionFactory.class);
    config.setFactory(mockExternalTransactionFactory);
    when(mockExternalTransactionFactory.joinExternalTransaction(mockMuleContext)).thenAnswer(invocationOnMock -> {
        TransactionCoordination.getInstance().bindTransaction(mockTransaction);
        return mockTransaction;
    });
    mockTransaction.setXA(true);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction).suspend();
    verify(mockTransaction).resume();
    verify(mockTransaction, never()).commit();
    verify(mockTransaction, never()).rollback();
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}
Also used : MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) ExternalTransactionAwareTransactionFactory(org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 3 with MuleTransactionConfig

use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndSuspendXaTxAndCommitNewTx.

@Test
public void testActionAlwaysBeginAndSuspendXaTxAndCommitNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    mockTransaction.setXA(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockNewTransaction).commit();
    verify(mockNewTransaction, never()).rollback();
    verify(mockTransaction).suspend();
    verify(mockTransaction).resume();
    verify(mockTransaction, never()).commit();
    verify(mockTransaction, never()).rollback();
    assertThat((TestTransaction) TransactionCoordination.getInstance().getTransaction(), is(mockTransaction));
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 4 with MuleTransactionConfig

use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionJoinIfPossibleAndNoTx.

@Test
public void testActionJoinIfPossibleAndNoTx() throws Exception {
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_JOIN_IF_POSSIBLE);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}
Also used : MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with MuleTransactionConfig

use of org.mule.runtime.core.api.transaction.MuleTransactionConfig in project mule by mulesoft.

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndRollbackTxAndCommitNewTx.

@Test(expected = IllegalTransactionStateException.class)
public void testActionAlwaysBeginAndRollbackTxAndCommitNewTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    when(mockTransaction.isRollbackOnly()).thenReturn(true);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction).rollback();
    verify(mockNewTransaction).commit();
    verify(mockTransaction, never()).commit();
    verify(mockNewTransaction, never()).rollback();
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>nullValue());
}
Also used : TestTransactionFactory(org.mule.tck.testmodels.mule.TestTransactionFactory) MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

MuleTransactionConfig (org.mule.runtime.core.api.transaction.MuleTransactionConfig)28 Test (org.junit.Test)23 SmallTest (org.mule.tck.size.SmallTest)20 TestTransactionFactory (org.mule.tck.testmodels.mule.TestTransactionFactory)7 TransactionalExecutionTemplate (org.mule.runtime.core.api.execution.TransactionalExecutionTemplate)4 ExecutionCallback (org.mule.runtime.core.api.execution.ExecutionCallback)3 ExecutionTemplate (org.mule.runtime.core.api.execution.ExecutionTemplate)3 TransactionConfig (org.mule.runtime.core.api.transaction.TransactionConfig)3 XaTransactionFactory (org.mule.runtime.core.privileged.transaction.xa.XaTransactionFactory)3 Transaction (javax.transaction.Transaction)2 ExternalTransactionAwareTransactionFactory (org.mule.runtime.core.api.transaction.ExternalTransactionAwareTransactionFactory)2 XaTransaction (org.mule.runtime.core.privileged.transaction.XaTransaction)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 DefaultMuleException (org.mule.runtime.api.exception.DefaultMuleException)1 MuleException (org.mule.runtime.api.exception.MuleException)1 SchedulerBusyException (org.mule.runtime.api.scheduler.SchedulerBusyException)1 TransactionType (org.mule.runtime.api.tx.TransactionType)1 MuleContext (org.mule.runtime.core.api.MuleContext)1 FlowConstruct (org.mule.runtime.core.api.construct.FlowConstruct)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1