Search in sources :

Example 6 with IllegalTransactionStateException

use of org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException in project mule by mulesoft.

the class TransactionCoordinationTestCase method testBindTransactionWithAlreadyBound.

@Test
public void testBindTransactionWithAlreadyBound() throws Exception {
    assertThat(tc.getTransaction(), nullValue());
    Transaction tx = mock(Transaction.class);
    tc.bindTransaction(tx);
    assertEquals(tx, tc.getTransaction());
    try {
        Transaction tx2 = mock(Transaction.class);
        tc.bindTransaction(tx2);
        fail();
    } catch (IllegalTransactionStateException e) {
    // expected
    }
    tc.unbindTransaction(tx);
}
Also used : TestTransaction(org.mule.tck.testmodels.mule.TestTransaction) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 7 with IllegalTransactionStateException

use of org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException in project mule by mulesoft.

the class ValidateTransactionalStateInterceptorTestCase method testTransactionalState.

@Test
public void testTransactionalState() throws Exception {
    boolean shouldThrowException = resultMap.get(hasTransactionInContext).get(transactionConfig);
    Exception thrownException = null;
    CoreEvent result = null;
    if (hasTransactionInContext) {
        TransactionCoordination.getInstance().bindTransaction(mockTransaction);
    }
    ValidateTransactionalStateInterceptor<CoreEvent> interceptor = new ValidateTransactionalStateInterceptor<>(new ExecuteCallbackInterceptor<CoreEvent>(), transactionConfig, false);
    try {
        result = interceptor.execute(() -> mockMuleEvent, new ExecutionContext());
    } catch (IllegalTransactionStateException e) {
        thrownException = e;
    }
    if (shouldThrowException) {
        assertThat(thrownException, notNullValue());
        assertThat(thrownException, instanceOf(IllegalTransactionStateException.class));
    } else {
        assertThat(result, is(mockMuleEvent));
    }
}
Also used : CoreEvent(org.mule.runtime.core.api.event.CoreEvent) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException) IllegalTransactionStateException(org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Aggregations

IllegalTransactionStateException (org.mule.runtime.core.privileged.transaction.xa.IllegalTransactionStateException)7 Test (org.junit.Test)2 DelegateTransaction (org.mule.runtime.core.internal.processor.DelegateTransaction)2 SmallTest (org.mule.tck.size.SmallTest)2 HeuristicRollbackException (javax.transaction.HeuristicRollbackException)1 InvalidTransactionException (javax.transaction.InvalidTransactionException)1 RollbackException (javax.transaction.RollbackException)1 SystemException (javax.transaction.SystemException)1 XAException (javax.transaction.xa.XAException)1 XAResource (javax.transaction.xa.XAResource)1 TransactionNotification (org.mule.runtime.api.notification.TransactionNotification)1 MuleXaObject (org.mule.runtime.api.tx.MuleXaObject)1 TransactionException (org.mule.runtime.api.tx.TransactionException)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 TransactionRollbackException (org.mule.runtime.core.api.transaction.TransactionRollbackException)1 TransactionStatusException (org.mule.runtime.core.api.transaction.TransactionStatusException)1 TestTransaction (org.mule.tck.testmodels.mule.TestTransaction)1