Search in sources :

Example 1 with IChainable

use of org.eclipse.scout.rt.platform.chain.IChainable in project scout.rt by eclipse.

the class RunContextChainTest method testCallableChain.

/**
 * Tests the correct order of interceptors in {@link RunContext}.
 */
@Test
public void testCallableChain() throws Exception {
    CallableChain<Object> chain = new RunContext().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. TransactionProcessor
    c = chainIterator.next();
    assertEquals(TransactionProcessor.class, c.getClass());
    assertFalse(chainIterator.hasNext());
}
Also used : IChainable(org.eclipse.scout.rt.platform.chain.IChainable) Test(org.junit.Test)

Example 2 with IChainable

use of org.eclipse.scout.rt.platform.chain.IChainable in project scout.rt by eclipse.

the class ClientRunContextChainTest method testCallableChain.

/**
 * Tests the correct order of interceptors in {@link ClientRunContext}.
 */
@Test
public void testCallableChain() throws Exception {
    CallableChain<Object> chain = new ClientRunContext() {

        @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 UserAgent.CURRENT
    c = chainIterator.next();
    assertEquals(ThreadLocalProcessor.class, c.getClass());
    assertSame(UserAgent.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
    // 13. ThreadLocalProcessor for IDesktop.CURRENT
    c = chainIterator.next();
    assertEquals(ThreadLocalProcessor.class, c.getClass());
    assertSame(IDesktop.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
    // 14. ThreadLocalProcessor for IOutline.CURRENT
    c = chainIterator.next();
    assertEquals(ThreadLocalProcessor.class, c.getClass());
    assertSame(IOutline.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
    // 15. ThreadLocalProcessor for IForm.CURRENT
    c = chainIterator.next();
    assertEquals(ThreadLocalProcessor.class, c.getClass());
    assertSame(IForm.CURRENT, ((ThreadLocalProcessor) c).getThreadLocal());
    // 16. TransactionProcessor
    c = chainIterator.next();
    assertEquals(TransactionProcessor.class, c.getClass());
    assertFalse(chainIterator.hasNext());
}
Also used : CallableChain(org.eclipse.scout.rt.platform.chain.callable.CallableChain) IChainable(org.eclipse.scout.rt.platform.chain.IChainable) Test(org.junit.Test)

Example 3 with IChainable

use of org.eclipse.scout.rt.platform.chain.IChainable 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 4 with IChainable

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

Aggregations

IChainable (org.eclipse.scout.rt.platform.chain.IChainable)4 Test (org.junit.Test)4 CallableChain (org.eclipse.scout.rt.platform.chain.callable.CallableChain)3 RunMonitor (org.eclipse.scout.rt.platform.context.RunMonitor)1 JobInput (org.eclipse.scout.rt.platform.job.JobInput)1