Search in sources :

Example 6 with CallableChain

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));
}
Also used : JobInput(org.eclipse.scout.rt.platform.job.JobInput) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) Test(org.junit.Test)

Example 7 with CallableChain

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));
}
Also used : CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AtomicReference(java.util.concurrent.atomic.AtomicReference) JobInput(org.eclipse.scout.rt.platform.job.JobInput) ExceptionHandler(org.eclipse.scout.rt.platform.exception.ExceptionHandler) Test(org.junit.Test)

Example 8 with CallableChain

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());
}
Also used : JobInput(org.eclipse.scout.rt.platform.job.JobInput) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) RunMonitor(org.eclipse.scout.rt.platform.context.RunMonitor) IChainable(org.eclipse.scout.rt.platform.chain.IChainable) Test(org.junit.Test)

Example 9 with CallableChain

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();
}
Also used : InOrder(org.mockito.InOrder) Holder(org.eclipse.scout.rt.platform.holders.Holder) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 10 with CallableChain

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();
}
Also used : InOrder(org.mockito.InOrder) Holder(org.eclipse.scout.rt.platform.holders.Holder) CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Aggregations

CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)17 Test (org.junit.Test)16 JobInput (org.eclipse.scout.rt.platform.job.JobInput)7 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)6 InOrder (org.mockito.InOrder)6 IChainable (org.eclipse.scout.rt.platform.chain.IChainable)3 Holder (org.eclipse.scout.rt.platform.holders.Holder)3 ExceptionHandler (org.eclipse.scout.rt.platform.exception.ExceptionHandler)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 RunMonitor (org.eclipse.scout.rt.platform.context.RunMonitor)1 StringHolder (org.eclipse.scout.rt.platform.holders.StringHolder)1 DiagnosticContextValueProcessor (org.eclipse.scout.rt.platform.logger.DiagnosticContextValueProcessor)1 SubjectProcessor (org.eclipse.scout.rt.platform.security.SubjectProcessor)1 TransactionProcessor (org.eclipse.scout.rt.platform.transaction.TransactionProcessor)1 ThreadLocalProcessor (org.eclipse.scout.rt.platform.util.ThreadLocalProcessor)1