Search in sources :

Example 36 with ITransaction

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

the class RunContextTest method testCopyCurrent_Transaction.

@Test
public void testCopyCurrent_Transaction() {
    final ITransaction tx = mock(ITransaction.class);
    RunContexts.empty().withTransaction(tx).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(tx, RunContexts.copyCurrent().getTransaction());
        }
    });
    RunContexts.empty().withTransaction(null).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertNotNull(ITransaction.CURRENT.get());
            assertNotNull(RunContexts.copyCurrent().getTransaction());
            assertNull(RunContext.CURRENT.get().getTransaction());
            RunContexts.copyCurrent().run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertNotNull(ITransaction.CURRENT.get());
                }
            });
        }
    });
    RunContexts.empty().withTransaction(tx).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertSame(tx, ITransaction.CURRENT.get());
            assertSame(tx, RunContexts.copyCurrent().getTransaction());
            assertSame(tx, RunContext.CURRENT.get().getTransaction());
            RunContexts.copyCurrent().run(new IRunnable() {

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

Example 37 with ITransaction

use of org.eclipse.scout.rt.platform.transaction.ITransaction 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)

Aggregations

ITransaction (org.eclipse.scout.rt.platform.transaction.ITransaction)37 Test (org.junit.Test)20 ISession (org.eclipse.scout.rt.shared.ISession)13 HashMap (java.util.HashMap)7 ITransactionMember (org.eclipse.scout.rt.platform.transaction.ITransactionMember)5 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)5 JUnitServerSession1 (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerDifferentSessionTest.JUnitServerSession1)4 JUnitServerSession (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerDifferentSubjectTest.JUnitServerSession)4 JUnitServerSession (org.eclipse.scout.rt.testing.server.runner.ServerTestRunnerSameSessionTest.JUnitServerSession)4 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)3 AfterClass (org.junit.AfterClass)3 BeforeClass (org.junit.BeforeClass)3 InvocationHandler (java.lang.reflect.InvocationHandler)2 Method (java.lang.reflect.Method)2 WebMethod (javax.jws.WebMethod)2 BooleanHolder (org.eclipse.scout.rt.platform.holders.BooleanHolder)2 Holder (org.eclipse.scout.rt.platform.holders.Holder)2 IServerSession (org.eclipse.scout.rt.server.IServerSession)2 AbstractSqlTransactionMember (org.eclipse.scout.rt.server.jdbc.AbstractSqlTransactionMember)2 Connection (java.sql.Connection)1