Search in sources :

Example 16 with MuleTransactionConfig

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

the class TransactionalExecutionTemplateTestCase method testActionNoneAndTxForRollback.

@Test
public void testActionNoneAndTxForRollback() throws Exception {
    when(mockTransaction.isRollbackOnly()).thenReturn(true);
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction, never()).commit();
    verify(mockTransaction, never()).rollback();
}
Also used : MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 17 with MuleTransactionConfig

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

the class TransactionalExecutionTemplateTestCase method testActionNoneAndWithExternalTransactionWithTx.

@Test
public void testActionNoneAndWithExternalTransactionWithTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
    config.setInteractWithExternal(true);
    mockExternalTransactionFactory = mock(ExternalTransactionAwareTransactionFactory.class);
    config.setFactory(mockExternalTransactionFactory);
    Transaction externalTransaction = mock(Transaction.class);
    when(mockExternalTransactionFactory.joinExternalTransaction(mockMuleContext)).thenReturn(externalTransaction);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    Object result = executionTemplate.execute(getEmptyTransactionCallback());
    assertThat(result, is(RETURN_VALUE));
    verify(mockTransaction, never()).rollback();
    verify(mockTransaction, never()).commit();
    assertThat(TransactionCoordination.getInstance().getTransaction(), IsNull.<Object>notNullValue());
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) Transaction(org.mule.runtime.core.api.transaction.Transaction) 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 18 with MuleTransactionConfig

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

the class TransactionalExecutionTemplateTestCase method testActionAlwaysBeginAndCommitTxAndCommitNewTx.

@Test
public void testActionAlwaysBeginAndCommitTxAndCommitNewTx() throws Exception {
    expectedException.expect(IllegalTransactionStateException.class);
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_ALWAYS_BEGIN);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    config.setFactory(new TestTransactionFactory(mockNewTransaction));
    executionTemplate.execute(getEmptyTransactionCallback());
}
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 19 with MuleTransactionConfig

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

the class TransactionalExecutionTemplateTestCase method testActionNeverAndTx.

@Test(expected = IllegalTransactionStateException.class)
public void testActionNeverAndTx() throws Exception {
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NEVER);
    ExecutionTemplate executionTemplate = createExecutionTemplate(config);
    executionTemplate.execute(getEmptyTransactionCallback());
}
Also used : MuleTransactionConfig(org.mule.runtime.core.api.transaction.MuleTransactionConfig) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 20 with MuleTransactionConfig

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

the class TransactionalExecutionTemplateTestCase method testActionNoneAndXaTx.

@Test
public void testActionNoneAndXaTx() throws Exception {
    mockTransaction.setXA(true);
    TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    MuleTransactionConfig config = new MuleTransactionConfig(TransactionConfig.ACTION_NONE);
    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();
}
Also used : 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