Search in sources :

Example 51 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class RunContextChainInterceptorTest method testInterception.

@Test
public void testInterception() {
    BEANS.get(RunContext.class).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            m_activityLog.add(2);
        }
    });
    Assert.assertEquals("1,2,3", CollectionUtility.format(m_activityLog, ","));
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 52 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class RunContextChainInterceptorTest method testAsyncCallWithThreadLocal.

@Test
public void testAsyncCallWithThreadLocal() {
    String backup = COLOR_TL.get();
    String backupNotInRunctontext = TL_NOT_IN_RUNCONTEXT.get();
    try {
        TL_NOT_IN_RUNCONTEXT.set("red");
        COLOR_TL.set("blue");
        Jobs.schedule(new IRunnable() {

            @Override
            public void run() throws Exception {
                Assert.assertNull(TL_NOT_IN_RUNCONTEXT.get());
                Assert.assertEquals("blue", COLOR_TL.get());
            }
        }, Jobs.newInput().withRunContext(RunContexts.copyCurrent())).awaitDone();
    } finally {
        COLOR_TL.set(backup);
        TL_NOT_IN_RUNCONTEXT.set(backupNotInRunctontext);
    }
    BEANS.get(RunContext.class).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            m_activityLog.add(2);
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Test(org.junit.Test)

Example 53 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class RunContextTest method testCopyLocale.

@Test
public void testCopyLocale() {
    RunContexts.empty().withLocale(null).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertNull(RunContexts.copyCurrent().getLocale());
            assertNull(NlsLocale.CURRENT.get());
        }
    });
    RunContexts.empty().withLocale(Locale.CANADA_FRENCH).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(Locale.CANADA_FRENCH, NlsLocale.CURRENT.get());
            assertEquals(Locale.CANADA_FRENCH, RunContexts.copyCurrent().getLocale());
            assertEquals(Locale.KOREAN, RunContexts.copyCurrent().withLocale(Locale.KOREAN).getLocale());
            // Change Locale directly via 'thread-local'
            NlsLocale.CURRENT.set(Locale.ITALY);
            assertEquals(Locale.ITALY, RunContexts.copyCurrent().getLocale());
            RunContexts.copyCurrent().run(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertEquals(Locale.ITALY, NlsLocale.get());
                }
            });
            // Test copy via 'RunContexts.copyCurrent'
            Jobs.schedule(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertEquals(Locale.ITALY, NlsLocale.get());
                }
            }, Jobs.newInput().withRunContext(RunContexts.copyCurrent())).awaitDoneAndGet();
            // Test copy via direct 'RunContext.copy'
            assertEquals(Locale.CANADA_FRENCH, RunContext.CURRENT.get().copy().getLocale());
            Jobs.schedule(new IRunnable() {

                @Override
                public void run() throws Exception {
                    assertEquals(Locale.CANADA_FRENCH, NlsLocale.get());
                    assertEquals(Locale.CANADA_FRENCH, RunContexts.copyCurrent().getLocale());
                }
            }, Jobs.newInput().withRunContext(RunContext.CURRENT.get().copy())).awaitDoneAndGet();
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 54 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class RunContextTest method testTransactionMember_TxRequired_TxPresent.

@Test(expected = AssertionException.class)
public void testTransactionMember_TxRequired_TxPresent() {
    final ITransactionMember txMember = mock(ITransactionMember.class);
    RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            RunContexts.copyCurrent().withTransactionScope(TransactionScope.REQUIRED).withTransactionMember(txMember).run(mock(IRunnable.class));
        }
    });
}
Also used : 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 55 with IRunnable

use of org.eclipse.scout.rt.platform.util.concurrent.IRunnable in project scout.rt by eclipse.

the class RunContextTest method testCopyCurrent_TransactionScope.

@Test
public void testCopyCurrent_TransactionScope() {
    RunContexts.empty().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(TransactionScope.REQUIRED, RunContexts.copyCurrent().getTransactionScope());
        }
    });
    RunContexts.empty().withTransactionScope(TransactionScope.REQUIRES_NEW).run(new IRunnable() {

        @Override
        public void run() throws Exception {
            assertEquals(TransactionScope.REQUIRED, RunContexts.copyCurrent().getTransactionScope());
        }
    });
}
Also used : IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)260 Test (org.junit.Test)210 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)82 BlockingCountDownLatch (org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch)68 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)40 ArrayList (java.util.ArrayList)36 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)32 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)26 TimedOutError (org.eclipse.scout.rt.platform.util.concurrent.TimedOutError)21 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)20 IExecutionSemaphore (org.eclipse.scout.rt.platform.job.IExecutionSemaphore)20 ThreadInterruptedError (org.eclipse.scout.rt.platform.util.concurrent.ThreadInterruptedError)20 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)19 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)17 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)13 Times (org.eclipse.scout.rt.testing.platform.runner.Times)12 AtomicReference (java.util.concurrent.atomic.AtomicReference)11 IFuture (org.eclipse.scout.rt.platform.job.IFuture)10 IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)10 JMSException (javax.jms.JMSException)9