Search in sources :

Example 16 with CallableChain

use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.

the class TransactionProcessorTest method testTransactionMemberFailed.

@Test
public void testTransactionMemberFailed() throws Exception {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    when(txMember.getMemberId()).thenReturn("abc");
    when(txMember.needsCommit()).thenReturn(true);
    when(txMember.commitPhase1()).thenReturn(true);
    CallableChain<Object> chain = new CallableChain<>();
    chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMembers(Arrays.asList(txMember)));
    try {
        chain.call(new Callable<Object>() {

            @Override
            public Object call() throws Exception {
                assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
                throw new RuntimeException("JUnit exception");
            }
        });
        fail("exception expected");
    } catch (RuntimeException e) {
    // NOOP
    }
    InOrder inOrder = Mockito.inOrder(txMember);
    inOrder.verify(txMember, never()).commitPhase1();
    inOrder.verify(txMember, never()).commitPhase2();
    inOrder.verify(txMember, times(1)).rollback();
    inOrder.verify(txMember, times(1)).release();
}
Also used : InOrder(org.mockito.InOrder) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 17 with CallableChain

use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.

the class TransactionProcessorTest method testTransactionMember_REQUIRED_TxNotPresent.

@Test
public void testTransactionMember_REQUIRED_TxNotPresent() throws Exception {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    when(txMember.getMemberId()).thenReturn("abc");
    when(txMember.needsCommit()).thenReturn(true);
    when(txMember.commitPhase1()).thenReturn(true);
    CallableChain<Object> chain = new CallableChain<>();
    chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRED).withTransactionMembers(Arrays.asList(txMember)));
    chain.call(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
            return null;
        }
    });
    InOrder inOrder = Mockito.inOrder(txMember);
    inOrder.verify(txMember, times(1)).commitPhase1();
    inOrder.verify(txMember, times(1)).commitPhase2();
    inOrder.verify(txMember, never()).rollback();
    inOrder.verify(txMember, times(1)).release();
}
Also used : InOrder(org.mockito.InOrder) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)17 Test (org.junit.Test)16 JobInput (org.eclipse.scout.rt.platform.job.JobInput)7 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)6 InOrder (org.mockito.InOrder)6 IChainable (org.eclipse.scout.rt.platform.chain.IChainable)3 Holder (org.eclipse.scout.rt.platform.holders.Holder)3 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RunMonitor (org.eclipse.scout.rt.platform.context.RunMonitor)1 StringHolder (org.eclipse.scout.rt.platform.holders.StringHolder)1 DiagnosticContextValueProcessor (org.eclipse.scout.rt.platform.logger.DiagnosticContextValueProcessor)1 SubjectProcessor (org.eclipse.scout.rt.platform.security.SubjectProcessor)1 TransactionProcessor (org.eclipse.scout.rt.platform.transaction.TransactionProcessor)1 ThreadLocalProcessor (org.eclipse.scout.rt.platform.util.ThreadLocalProcessor)1