Search in sources :

Example 6 with ITransactionMember

use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.

the class RunContextTest method testTransactionMember_TxRequiresNew.

@Test
public void testTransactionMember_TxRequiresNew() {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    when(txMember.getMemberId()).thenReturn("abc");
    when(txMember.needsCommit()).thenReturn(true);
    when(txMember.commitPhase1()).thenReturn(true);
    RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMember(txMember).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
        }
    });
    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) ITransactionMember(org.eclipse.scout.rt.platform.transaction.ITransactionMember) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 7 with ITransactionMember

use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.

the class RunContextTest method testCopyCurrent_TransactionMember.

@Test
public void testCopyCurrent_TransactionMember() {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    when(txMember.getMemberId()).thenReturn("txMember");
    RunContexts.empty().withTransactionMember(txMember).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            final ITransaction tx = ITransaction.CURRENT.get();
            assertNotNull(tx);
            assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
            RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRED).run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertSame(tx, ITransaction.CURRENT.get());
                    assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
                }
            });
            RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertNotSame(tx, ITransaction.CURRENT.get());
                    assertNull(ITransaction.CURRENT.get().getMember("txMember"));
                }
            });
            RunContexts.copyCurrent().withTransactionScope(TransactionScope.MANDATORY).run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertSame(tx, ITransaction.CURRENT.get());
                    assertSame(txMember, ITransaction.CURRENT.get().getMember("txMember"));
                }
            });
        }
    });
}
Also used : ITransaction(org.eclipse.scout.rt.platform.transaction.ITransaction) ITransactionMember(org.eclipse.scout.rt.platform.transaction.ITransactionMember) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 8 with ITransactionMember

use of org.eclipse.scout.rt.platform.transaction.ITransactionMember in project scout.rt by eclipse.

the class RunContextTest method testTransactionMember_TxRequired_TxNotPresent.

@Test
public void testTransactionMember_TxRequired_TxNotPresent() {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    when(txMember.getMemberId()).thenReturn("abc");
    when(txMember.needsCommit()).thenReturn(true);
    when(txMember.commitPhase1()).thenReturn(true);
    RunContexts.empty().withTransactionScope(TransactionScope.REQUIRED).withTransactionMember(txMember).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
        }
    });
    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) ITransactionMember(org.eclipse.scout.rt.platform.transaction.ITransactionMember) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

ITransactionMember (org.eclipse.scout.rt.platform.transaction.ITransactionMember)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)5 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)5 Test (org.junit.Test)5 ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)4 AbstractSqlTransactionMember (org.eclipse.scout.rt.server.jdbc.AbstractSqlTransactionMember)2 InOrder (org.mockito.InOrder)2 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 Subject (javax.security.auth.Subject)1 CallInfo (org.eclipse.scout.rt.server.admin.inspector.info.CallInfo)1