Search in sources :

Example 1 with AbstractServerSession

use of org.eclipse.scout.rt.server.AbstractServerSession in project scout.rt by eclipse.

the class ServerSessionCacheTest method testParallelRequestsWithSameIds.

@Test
public void testParallelRequestsWithSameIds() {
    final TestHttpSession httpSession1 = new TestHttpSession();
    final TestHttpSession httpSession2 = new TestHttpSession();
    final ServerSessionCache cache = BEANS.get(ServerSessionCache.class);
    final IServerSessionLifecycleHandler sessionSupplier1 = new IServerSessionLifecycleHandler() {

        @Override
        public IServerSession create() {
            return new AbstractServerSession(true) {

                private static final long serialVersionUID = 1L;
            };
        }

        @Override
        public void destroy(IServerSession session) {
        }

        @Override
        public String getId() {
            return "id1";
        }
    };
    final IServerSessionLifecycleHandler sessionSupplier2 = new IServerSessionLifecycleHandler() {

        @Override
        public IServerSession create() {
            return new AbstractServerSession(true) {

                private static final long serialVersionUID = 1L;
            };
        }

        @Override
        public void destroy(IServerSession session) {
        }

        @Override
        public String getId() {
            return "id1";
        }
    };
    IFuture<IServerSession> f1 = Jobs.schedule(new Callable<IServerSession>() {

        @Override
        public IServerSession call() throws Exception {
            return cache.getOrCreate(sessionSupplier1, httpSession1);
        }
    }, Jobs.newInput());
    IFuture<IServerSession> f2 = Jobs.schedule(new Callable<IServerSession>() {

        @Override
        public IServerSession call() throws Exception {
            return cache.getOrCreate(sessionSupplier2, httpSession2);
        }
    }, Jobs.newInput());
    IServerSession session2 = f2.awaitDoneAndGet();
    IServerSession session1 = f1.awaitDoneAndGet();
    assertSame(session1, session2);
}
Also used : AbstractServerSession(org.eclipse.scout.rt.server.AbstractServerSession) IServerSession(org.eclipse.scout.rt.server.IServerSession) TestHttpSession(org.eclipse.scout.rt.testing.server.TestHttpSession) Test(org.junit.Test)

Aggregations

AbstractServerSession (org.eclipse.scout.rt.server.AbstractServerSession)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1 TestHttpSession (org.eclipse.scout.rt.testing.server.TestHttpSession)1 Test (org.junit.Test)1