Search in sources :

Example 1 with SessionStoreTestForm

use of org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm in project scout.rt by eclipse.

the class UiSessionTest method doTestLogoutWithBlockingModelDisposal.

/**
 * Tests that session invalidation still works even if the model is blocking during its disposal. Especially the
 * {@link HttpSessionBindingListener#valueUnbound(javax.servlet.http.HttpSessionBindingEvent)} method is expected not
 * to be blocked by the {@link SessionStore} (the method is invoked by the servlet container and blocking its thread
 * could interfere with the application server itself, for example when a background thread is cleaning up timed out
 * sessions).
 */
protected void doTestLogoutWithBlockingModelDisposal(final CloseAction openFormCloseAction, boolean expectFormFinallyCompleted, boolean expectSessionActiveAfterwards) throws InterruptedException {
    // create new UI session along with client client and HTTP sessions
    UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
    final HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
    IClientSession clientSession = uiSession.getClientSession();
    assertFalse(uiSession.isDisposed());
    // register ui session in session store
    final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
    sessionStore.registerUiSession(uiSession);
    assertThat(sessionStore, is(instanceOf(HttpSessionBindingListener.class)));
    // create and start test form in a model job
    SessionStoreTestForm form = ModelJobs.schedule(new Callable<SessionStoreTestForm>() {

        @Override
        public SessionStoreTestForm call() throws Exception {
            SessionStoreTestForm f = new SessionStoreTestForm(openFormCloseAction);
            f.start();
            return f;
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true))).awaitDoneAndGet(1, TimeUnit.SECONDS);
    // schedule a job that emulates servlet container that performs session invalidation on session timeout
    IFuture<Void> appServerSessionTimeoutFuture = Jobs.schedule(new IRunnable() {

        @Override
        public void run() throws Exception {
            httpSession.invalidate();
        }
    }, Jobs.newInput().withName("simulate session timeout").withExecutionTrigger(Jobs.newExecutionTrigger().withStartIn(200, TimeUnit.MILLISECONDS)));
    // perform logout on UI session that stops the client session and disposes all model objects.
    uiSession.logout();
    assertTrue(uiSession.isDisposed());
    if (expectFormFinallyCompleted) {
        form.awaitDoFinallyCompleted(1, TimeUnit.SECONDS);
    } else {
        BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
    }
    appServerSessionTimeoutFuture.awaitDone(3, TimeUnit.SECONDS);
    assertTrue(appServerSessionTimeoutFuture.isDone());
    if (expectFormFinallyCompleted) {
        assertTrue(form.isFinallyCompleted());
        BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
    } else {
        assertFalse(form.isFinallyCompleted());
        // The model job was canceled by the SessionStore. Hence we cannot use UiJobs.awaitModelJobs().
        // We still sleep some time
        SleepUtil.sleepSafe(200, TimeUnit.MILLISECONDS);
    }
    assertEquals(expectSessionActiveAfterwards, clientSession.isActive());
}
Also used : HttpSession(javax.servlet.http.HttpSession) IRunnable(org.eclipse.scout.rt.platform.util.concurrent.IRunnable) Callable(java.util.concurrent.Callable) IClientSession(org.eclipse.scout.rt.client.IClientSession) SessionStoreTestForm(org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)

Example 2 with SessionStoreTestForm

use of org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm in project scout.rt by eclipse.

the class UiSessionTest method doTestSessionTimeoutWithBlockingModelDisposal.

/**
 * Checks the same problematic as {@link #doTestLogoutWithBlockingModelDisposal(CloseAction, boolean, boolean)} except
 * that there is no {@link UiSession#logout()}, but only a {@link HttpSession#invalidate()}, invoked by the servlet
 * container due to session timeout.
 */
protected void doTestSessionTimeoutWithBlockingModelDisposal(final CloseAction openFormCloseAction, boolean expectFormFinallyCompleted, boolean expectSessionActiveAfterwards) throws InterruptedException {
    // create new UI session along with client client and HTTP sessions
    UiSession uiSession = (UiSession) JsonTestUtility.createAndInitializeUiSession();
    final HttpSession httpSession = UiSessionTestUtility.getHttpSession(uiSession);
    IClientSession clientSession = uiSession.getClientSession();
    assertFalse(uiSession.isDisposed());
    // register ui session in session store
    final ISessionStore sessionStore = BEANS.get(HttpSessionHelper.class).getSessionStore(httpSession);
    sessionStore.registerUiSession(uiSession);
    assertThat(sessionStore, is(instanceOf(HttpSessionBindingListener.class)));
    // create and start test form in a model job
    SessionStoreTestForm form = ModelJobs.schedule(new Callable<SessionStoreTestForm>() {

        @Override
        public SessionStoreTestForm call() throws Exception {
            SessionStoreTestForm f = new SessionStoreTestForm(openFormCloseAction);
            f.start();
            return f;
        }
    }, ModelJobs.newInput(ClientRunContexts.empty().withSession(clientSession, true))).awaitDoneAndGet(1, TimeUnit.SECONDS);
    // invalidate HTTP session
    httpSession.invalidate();
    if (expectFormFinallyCompleted) {
        form.awaitDoFinallyCompleted(1, TimeUnit.SECONDS);
        assertTrue(form.isFinallyCompleted());
        BEANS.get(UiJobs.class).awaitModelJobs(clientSession, JUnitExceptionHandler.class);
    } else {
        assertFalse(form.isFinallyCompleted());
        // We still sleep some time
        for (int i = 0; i < 10; i++) {
            SleepUtil.sleepSafe(200, TimeUnit.MILLISECONDS);
            if (expectSessionActiveAfterwards == clientSession.isActive()) {
                break;
            }
        }
    }
    assertTrue(uiSession.isDisposed());
    assertEquals(expectSessionActiveAfterwards, clientSession.isActive());
}
Also used : HttpSession(javax.servlet.http.HttpSession) IClientSession(org.eclipse.scout.rt.client.IClientSession) SessionStoreTestForm(org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm) Callable(java.util.concurrent.Callable)

Aggregations

Callable (java.util.concurrent.Callable)2 HttpSession (javax.servlet.http.HttpSession)2 IClientSession (org.eclipse.scout.rt.client.IClientSession)2 SessionStoreTestForm (org.eclipse.scout.rt.ui.html.fixtures.SessionStoreTestForm)2 IRunnable (org.eclipse.scout.rt.platform.util.concurrent.IRunnable)1