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));
}
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());
}
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));
}
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());
}
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());
}
Aggregations