Search in sources :

Example 1 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JobsTest method testNewInput.

@Test
public void testNewInput() {
    RunContext runContext = RunContexts.empty();
    assertSame(runContext, Jobs.newInput().withRunContext(runContext).getRunContext());
    assertEquals("scout-thread", Jobs.newInput().getThreadName());
    assertNull(Jobs.newInput().getRunContext());
}
Also used : RunContext(org.eclipse.scout.rt.platform.context.RunContext) Test(org.junit.Test)

Example 2 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JobCancelTest method testCancelledWithEmptyRunContextAndCancellationOnMonitor.

@Test
public void testCancelledWithEmptyRunContextAndCancellationOnMonitor() {
    final BlockingCountDownLatch setupLatch = new BlockingCountDownLatch(1);
    final BlockingCountDownLatch assertLatch = new BlockingCountDownLatch(1);
    final AtomicBoolean cancelled = new AtomicBoolean();
    // Run test within RunContext to ensure a current RunMonitor
    RunContexts.empty().run(new IRunnable() {

        @Override
        public void run() throws Exception {
            RunContext emptyRunContext = RunContexts.empty();
            Jobs.schedule(new IRunnable() {

                @Override
                public void run() throws Exception {
                    setupLatch.countDownAndBlock();
                    cancelled.set(RunMonitor.CURRENT.get().isCancelled());
                    assertLatch.countDown();
                }
            }, Jobs.newInput().withRunContext(emptyRunContext));
            setupLatch.await();
            emptyRunContext.getRunMonitor().cancel(false);
            setupLatch.unblock();
            assertLatch.await();
            assertTrue("cancellation expected", cancelled.get());
        }
    });
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) BlockingCountDownLatch(org.eclipse.scout.rt.testing.platform.util.BlockingCountDownLatch) RunContext(org.eclipse.scout.rt.platform.context.RunContext) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 3 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JobScheduleTest method testScheduleJobWithCancelledRunMonitor.

@Test
public void testScheduleJobWithCancelledRunMonitor() {
    // setup run context with already cancelled run monitor
    RunContext runContext = RunContexts.empty();
    runContext.getRunMonitor().cancel(true);
    // schedule job
    IFuture<Void> future = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            fail("job must not be executed");
        }
    }, Jobs.newInput().withRunContext(runContext));
    future.awaitDone();
    assertTrue(future.isCancelled());
    // future must not be referenced by job manager
    assertEquals(0, Jobs.getJobManager().getFutures(Jobs.newFutureFilterBuilder().andMatchFuture(future).toFilter()).size());
}
Also used : RunContext(org.eclipse.scout.rt.platform.context.RunContext) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException) PlatformException(org.eclipse.scout.rt.platform.exception.PlatformException) AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) Test(org.junit.Test)

Example 4 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class JaxWsRunContextLookup method lookup.

/**
 * Looks up the {@link RunContext} from the given {@link WebServiceContext}.
 *
 * @return {@link RunContext}, is never <code>null</code>.
 */
public RunContext lookup(final WebServiceContext webServiceContext) {
    final RunContext runContext = lookupRunContext(webServiceContext);
    final Subject subject = lookupSubject(webServiceContext, runContext);
    final String cid = lookupCorrelationId(webServiceContext, runContext);
    final MessageContext messageContext = webServiceContext.getMessageContext();
    final JaxWsImplementorSpecifics implementor = BEANS.get(JaxWsImplementorSpecifics.class);
    HttpServletRequest request = implementor.getServletRequest(messageContext);
    HttpServletResponse response = implementor.getServletResponse(messageContext);
    return runContext.withSubject(subject).withCorrelationId(cid).withThreadLocal(IWebServiceContext.CURRENT, webServiceContext).withThreadLocal(IHttpServletRoundtrip.CURRENT_HTTP_SERVLET_REQUEST, request).withThreadLocal(IHttpServletRoundtrip.CURRENT_HTTP_SERVLET_RESPONSE, response).withDiagnostics(BEANS.get(ServletDiagnosticsProviderFactory.class).getProviders(request, response));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) RunContext(org.eclipse.scout.rt.platform.context.RunContext) MessageContext(javax.xml.ws.handler.MessageContext) Subject(javax.security.auth.Subject) JaxWsImplementorSpecifics(org.eclipse.scout.rt.server.jaxws.implementor.JaxWsImplementorSpecifics)

Example 5 with RunContext

use of org.eclipse.scout.rt.platform.context.RunContext in project scout.rt by eclipse.

the class AbstractHealthCheckServlet method doGet.

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    disableCaching(req, resp);
    RunContext context;
    try {
        context = execCreateRunContext();
        if (context == null) {
            throw new IllegalArgumentException("context must not be null");
        }
    } catch (Throwable t) {
        LOG.error("Creating RunContext failed", t);
        throw BEANS.get(ServletExceptionTranslator.class).translate(t);
    }
    try {
        doChecks(context, req, resp);
    } catch (Throwable t) {
        LOG.error("HealthChecking crashed", t);
        throw BEANS.get(ServletExceptionTranslator.class).translate(t);
    }
}
Also used : RunContext(org.eclipse.scout.rt.platform.context.RunContext)

Aggregations

RunContext (org.eclipse.scout.rt.platform.context.RunContext)14 Test (org.junit.Test)8 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)6 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)5 Subject (javax.security.auth.Subject)3 Locale (java.util.Locale)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 PlatformException (org.eclipse.scout.rt.platform.exception.PlatformException)2 UserAgent (org.eclipse.scout.rt.shared.ui.UserAgent)2 HashSet (java.util.HashSet)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 MessageContext (javax.xml.ws.handler.MessageContext)1 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 ClientRunContext (org.eclipse.scout.rt.client.context.ClientRunContext)1 IDesktop (org.eclipse.scout.rt.client.ui.desktop.IDesktop)1 ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)1 IFilter (org.eclipse.scout.rt.platform.filter.IFilter)1 IBlockingCondition (org.eclipse.scout.rt.platform.job.IBlockingCondition)1 IFuture (org.eclipse.scout.rt.platform.job.IFuture)1