use of org.eclipse.scout.rt.testing.server.TestHttpSession in project scout.rt by eclipse.
the class ServerSessionCacheTest method testDestroyCalledOnUnbind.
/**
* When the {@link HttpSession} is invalidated and unbound, the destructionCallback should be called.
*/
@Test
public void testDestroyCalledOnUnbind() {
TestHttpSession httpSession = new TestHttpSession();
IServerSessionLifecycleHandler lifecycleSpy = spy(new FixedServerSessionLifecycleHandler());
BEANS.get(ServerSessionCache.class).getOrCreate(lifecycleSpy, httpSession);
httpSession.invalidate();
verify(lifecycleSpy).destroy(Mockito.any(IServerSession.class));
}
use of org.eclipse.scout.rt.testing.server.TestHttpSession in project scout.rt by eclipse.
the class ServerSessionCacheTest method testDestroyWithMultipleHttpSessions.
/**
* If there are multiple HTTP sessions, and one gets invalidated, the scout session should not be destroyed.
*/
@Test
public void testDestroyWithMultipleHttpSessions() {
TestHttpSession httpSession1 = new TestHttpSession();
TestHttpSession httpSession2 = new TestHttpSession();
ServerSessionCache cache = BEANS.get(ServerSessionCache.class);
IServerSessionLifecycleHandler lifecycleSpy = spy(new FixedServerSessionLifecycleHandler());
cache.getOrCreate(lifecycleSpy, httpSession1);
cache.getOrCreate(lifecycleSpy, httpSession2);
httpSession1.invalidate();
verify(lifecycleSpy, Mockito.times(0)).destroy(Mockito.any(IServerSession.class));
}
use of org.eclipse.scout.rt.testing.server.TestHttpSession in project scout.rt by eclipse.
the class ServerSessionCacheTest method testParallelRequestsWithdifferentIds.
@Test
public void testParallelRequestsWithdifferentIds() {
final TestHttpSession httpSession1 = new TestHttpSession();
final TestHttpSession httpSession2 = new TestHttpSession();
final ServerSessionCache cache = BEANS.get(ServerSessionCache.class);
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
final IServerSessionLifecycleHandler handler1 = new TestServerSessionLifecycleHandler("id1") {
@Override
public IServerSession create() {
bc.waitFor(1, TimeUnit.SECONDS);
return super.create();
}
};
final IServerSessionLifecycleHandler handler2 = new TestServerSessionLifecycleHandler("id2") {
@Override
public IServerSession create() {
bc.setBlocking(false);
return super.create();
}
};
IFuture<IServerSession> f1 = Jobs.schedule(new Callable<IServerSession>() {
@Override
public IServerSession call() throws Exception {
return cache.getOrCreate(handler1, httpSession1);
}
}, Jobs.newInput());
IFuture<IServerSession> f2 = Jobs.schedule(new Callable<IServerSession>() {
@Override
public IServerSession call() throws Exception {
return cache.getOrCreate(handler2, httpSession2);
}
}, Jobs.newInput());
IServerSession session2 = f2.awaitDoneAndGet();
IServerSession session1 = f1.awaitDoneAndGet();
assertNotNull(session2);
assertNotNull(session1);
assertNotSame(session1, session2);
}
use of org.eclipse.scout.rt.testing.server.TestHttpSession 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);
}
use of org.eclipse.scout.rt.testing.server.TestHttpSession in project scout.rt by eclipse.
the class ServerSessionCacheTest method testMultipleHttpSessionsMultipleSessionIds.
/**
* If there are multiple HTTP sessions, and multiple sessionIds, the sessions should be different.
*/
@Test
public void testMultipleHttpSessionsMultipleSessionIds() {
TestHttpSession httpSession1 = new TestHttpSession();
TestHttpSession httpSession2 = new TestHttpSession();
IServerSessionLifecycleHandler handler1 = new TestServerSessionLifecycleHandler("id1");
IServerSessionLifecycleHandler handler2 = new TestServerSessionLifecycleHandler("id2");
IServerSession session1 = BEANS.get(ServerSessionCache.class).getOrCreate(handler1, httpSession1);
IServerSession session2 = BEANS.get(ServerSessionCache.class).getOrCreate(handler2, httpSession2);
assertNotSame(session1, session2);
}
Aggregations