use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testTransactionMemberSuccess.
@Test
public void testTransactionMemberSuccess() throws Exception {
final ITransactionMember txMember = mock(ITransactionMember.class);
when(txMember.getMemberId()).thenReturn("abc");
when(txMember.needsCommit()).thenReturn(true);
when(txMember.commitPhase1()).thenReturn(true);
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRES_NEW).withTransactionMembers(Arrays.asList(txMember)));
chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
assertSame(txMember, ITransaction.CURRENT.get().getMember("abc"));
return null;
}
});
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();
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class TransactionProcessorTest method testRequiredWithoutExistingTransactionAndSuccess.
@Test
public void testRequiredWithoutExistingTransactionAndSuccess() throws Exception {
final Holder<ITransaction> actualTransaction = new Holder<>();
CallableChain<Object> chain = new CallableChain<>();
chain.add(new TransactionProcessor<Object>().withCallerTransaction(null).withTransactionScope(TransactionScope.REQUIRED));
Object result = chain.call(new Callable<Object>() {
@Override
public Object call() throws Exception {
actualTransaction.setValue(ITransaction.CURRENT.get());
return "result";
}
});
// verify
assertEquals("result", result);
assertSame(m_transaction, actualTransaction.getValue());
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 ThreadLocalProcessorTest method test.
@Test
public void test() throws Exception {
final StringHolder actualValue = new StringHolder();
THREAD_LOCAL.set("ORIG");
CallableChain<Void> callableChain = new CallableChain<>();
callableChain.add(new ThreadLocalProcessor<>(THREAD_LOCAL, "ABC"));
callableChain.call(new Callable<Void>() {
@Override
public Void call() throws Exception {
actualValue.setValue(THREAD_LOCAL.get());
return null;
}
});
assertEquals("ABC", actualValue.getValue());
assertEquals("ORIG", THREAD_LOCAL.get());
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ServerRunContextChainTest method testCallableChain.
/**
* Tests the correct order of interceptors in {@link ServerRunContext}.
*/
@Test
public void testCallableChain() throws Exception {
CallableChain<Object> chain = new ServerRunContext() {
@Override
protected <RESULT> CallableChain<RESULT> createCallableChain() {
// overwrite to be accessible in test
return super.createCallableChain();
}
}.createCallableChain();
Iterator<IChainable> chainIterator = chain.values().iterator();
// 1. ThreadLocalProcessor for RunContext.CURRENT
IChainable c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(RunContext.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 2. ThreadLocalProcessor for CorrelationId.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(CorrelationId.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 3. ThreadLocalProcessor for RunMonitor.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(RunMonitor.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 4. SubjectProcessor
c = (IChainable) chainIterator.next();
assertEquals(SubjectProcessor.class, c.getClass());
// 5. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("subject.principal.name", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 6. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.correlation.id", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 7. ThreadLocalProcessor for NlsLocale.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(NlsLocale.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 8. ThreadLocalProcessor for PropertyMap.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(PropertyMap.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 9. ThreadLocalProcessor for ISession.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(ISession.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 10. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.user.name", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 11. DiagnosticContextValueProcessor
c = chainIterator.next();
assertEquals(DiagnosticContextValueProcessor.class, c.getClass());
assertEquals("scout.session.id", ((DiagnosticContextValueProcessor) c).getMdcKey());
// 12. ThreadLocalProcessor for ISession.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(UserAgent.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 13. ThreadLocalProcessor for ClientNodeId.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(IClientNodeId.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 14. ThreadLocalProcessor for TransactionalClientNotificationCollector.CURRENT
c = chainIterator.next();
assertEquals(ThreadLocalProcessor.class, c.getClass());
assertSame(ClientNotificationCollector.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
// 15. TransactionProcessor
c = chainIterator.next();
assertEquals(TransactionProcessor.class, c.getClass());
assertFalse(chainIterator.hasNext());
}
use of org.eclipse.scout.rt.platform.chain.callable.CallableChain in project scout.rt by eclipse.
the class ExceptionProcessorTest method testWithSwallow.
@Test
public void testWithSwallow() throws Exception {
final RuntimeException exception = new RuntimeException("expected JUnit test exception");
JobInput jobInput = Jobs.newInput().withExceptionHandling(BEANS.get(ExceptionHandler.class), 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, times(1)).handle(eq(exception));
verifyNoMoreInteractions(m_exceptionHandler);
}
Aggregations