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, ","));
}
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);
}
});
}
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();
}
});
}
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));
}
});
}
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());
}
});
}
Aggregations