use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testWithNullExceptionHandlerAndSwallow.
@Test
public void testWithNullExceptionHandlerAndSwallow() throws Exception {
final RuntimeException exception = new RuntimeException("expected JUnit test exception");
JobInput jobInput = Jobs.newInput().withExceptionHandling(null, true);
CallableChain<String> chain = new CallableChain<>();
chain.add(new ExceptionProcessor<String>(jobInput));
chain.call(new Callable<String>() {
@Override
public String call() throws Exception {
throw exception;
}
});
verify(m_exceptionHandler, never()).handle(eq(exception));
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testWithCustomExceptionHandler.
@Test
public void testWithCustomExceptionHandler() throws Exception {
final RuntimeException exception = new RuntimeException("expected JUnit test exception");
final AtomicReference<Throwable> error = new AtomicReference<>();
JobInput jobInput = Jobs.newInput().withExceptionHandling(new ExceptionHandler() {
@Override
public void handle(Throwable t) {
error.set(t);
}
}, true);
CallableChain<String> chain = new CallableChain<>();
chain.add(new ExceptionProcessor<String>(jobInput));
chain.call(new Callable<String>() {
@Override
public String call() throws Exception {
throw exception;
}
});
assertSame(exception, error.get());
verify(m_exceptionHandler, never()).handle(eq(exception));
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class JobManagerChainTest method testCallableChain.
@Test
public void testCallableChain() throws Exception {
CallableChain<Object> chain = new CallableChain<Object>();
new JobManager().interceptCallableChain(chain, mock(JobFutureTask.class), mock(RunMonitor.class), mock(JobInput.class));
Iterator<IChainable> chainIterator = chain.values().iterator();
// 1. CallableChainExceptionHandler
IChainable c = chainIterator.next();
assertEquals(CallableChainExceptionHandler.class, c.getClass());
// 2. ThreadLocalProcessor for IFuture.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(IFuture.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 3. ThreadLocalProcessor for RunMonitor.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(RunMonitor.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 4. ThreadNameDecorator
c = (IChainable) chainIterator.next();
if (Platform.get().inDevelopmentMode()) {
assertEquals(DevelopmentThreadNameDecorator.class, c.getClass());
} else {
assertEquals(ThreadNameDecorator.class, c.getClass());
}
// 5. JobNameContextValueProvider (MDC)
c = (IChainable) chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.job.name", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 6. RunContextRunner
c = (IChainable) chainIterator.next();
assertEquals(RunContextRunner.class, c.getClass());
// 7. ExceptionProcessor
c = (IChainable) chainIterator.next();
assertEquals(ExceptionProcessor.class, c.getClass());
assertFalse(chainIterator.hasNext());
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testRequiresNewWithoutExistingTransactionAndSuccess.
@Test
public void testRequiresNewWithoutExistingTransactionAndSuccess() throws Exception {
final Holder<ITransaction> actualTransaction = new Holder<>();
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRES_NEW));
Object result = chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
actualTransaction.setValue(ITransaction.CURRENT.get());
return "result";
}
});
// verify
assertSame(m_transaction, actualTransaction.getValue());
assertEquals("result", result);
verify(m_transaction, times(1)).release();
InOrder inOrder = Mockito.inOrder(m_transaction);
inOrder.verify(m_transaction, times(1)).commitPhase1();
inOrder.verify(m_transaction, times(1)).commitPhase2();
inOrder.verify(m_transaction, never()).rollback();
inOrder.verify(m_transaction, times(1)).release();
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testRequiresNewWithExistingTransactionAndSuccess.
@Test
public void testRequiresNewWithExistingTransactionAndSuccess() throws Exception {
ITransaction callingTransaction = mock(ITransaction.class);
final Holder<ITransaction> actualTransaction = new Holder<>();
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(callingTransaction).withTransactionScope(TransactionScope.REQUIRES_NEW));
Object result = chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
actualTransaction.setValue(ITransaction.CURRENT.get());
return "result";
}
});
// verify
assertSame(m_transaction, actualTransaction.getValue());
assertEquals("result", result);
verifyZeroInteractions(callingTransaction);
verify(m_transaction, times(1)).release();
InOrder inOrder = Mockito.inOrder(m_transaction);
inOrder.verify(m_transaction, times(1)).commitPhase1();
inOrder.verify(m_transaction, times(1)).commitPhase2();
inOrder.verify(m_transaction, never()).rollback();
inOrder.verify(m_transaction, times(1)).release();
}
Aggregations