use of org.apache.tomcat.unittest.TesterHost in project tomcat70 by apache.
the class TestPersistentManager method testBug62175.
@Test
public void testBug62175() throws Exception {
final PersistentManager manager = new PersistentManager();
final AtomicInteger sessionExpireCounter = new AtomicInteger();
Store mockStore = EasyMock.createNiceMock(Store.class);
EasyMock.expect(mockStore.load(EasyMock.anyString())).andAnswer(new IAnswer<Session>() {
@Override
public Session answer() throws Throwable {
return timedOutSession(manager, sessionExpireCounter);
}
}).anyTimes();
EasyMock.replay(mockStore);
manager.setStore(mockStore);
Host host = new TesterHost();
final RequestCachingSessionListener requestCachingSessionListener = new RequestCachingSessionListener();
final Context context = new TesterContext() {
@Override
public Object[] getApplicationLifecycleListeners() {
return new Object[] { requestCachingSessionListener };
}
@Override
public Manager getManager() {
return manager;
}
};
context.setParent(host);
Request req = new Request();
req.setContext(context);
req.setRequestedSessionId("invalidSession");
HttpServletRequest request = new RequestFacade(req);
requestCachingSessionListener.request = request;
manager.setContainer(context);
manager.start();
Assert.assertNull(request.getSession(false));
EasyMock.verify(mockStore);
Assert.assertEquals(1, sessionExpireCounter.get());
}
use of org.apache.tomcat.unittest.TesterHost in project tomcat70 by apache.
the class TestPersistentManager method testMinIdleSwap.
@Test
public void testMinIdleSwap() throws Exception {
PersistentManager manager = new PersistentManager();
manager.setStore(new TesterStore());
Host host = new TesterHost();
Context context = new TesterContext();
context.setParent(host);
manager.setContainer(context);
manager.setMaxActiveSessions(2);
manager.setMinIdleSwap(0);
manager.start();
// Create the maximum number of sessions
manager.createSession(null);
manager.createSession(null);
// Given the minIdleSwap settings, this should swap one out to get below
// the limit
manager.processPersistenceChecks();
Assert.assertEquals(1, manager.getActiveSessions());
Assert.assertEquals(2, manager.getActiveSessionsFull());
manager.createSession(null);
Assert.assertEquals(2, manager.getActiveSessions());
Assert.assertEquals(3, manager.getActiveSessionsFull());
}
use of org.apache.tomcat.unittest.TesterHost in project tomcat by apache.
the class TestPersistentManager method testMinIdleSwap.
@Test
public void testMinIdleSwap() throws Exception {
PersistentManager manager = new PersistentManager();
manager.setStore(new TesterStore());
Host host = new TesterHost();
Context context = new TesterContext();
context.setParent(host);
manager.setContext(context);
manager.setMaxActiveSessions(2);
manager.setMinIdleSwap(0);
manager.start();
// Create the maximum number of sessions
manager.createSession(null);
manager.createSession(null);
// Given the minIdleSwap settings, this should swap one out to get below
// the limit
manager.processPersistenceChecks();
Assert.assertEquals(1, manager.getActiveSessions());
Assert.assertEquals(2, manager.getActiveSessionsFull());
manager.createSession(null);
Assert.assertEquals(2, manager.getActiveSessions());
Assert.assertEquals(3, manager.getActiveSessionsFull());
}
use of org.apache.tomcat.unittest.TesterHost in project tomcat by apache.
the class TestPersistentManager method testBug62175.
@Test
public void testBug62175() throws Exception {
PersistentManager manager = new PersistentManager();
AtomicInteger sessionExpireCounter = new AtomicInteger();
Store mockStore = EasyMock.createNiceMock(Store.class);
EasyMock.expect(mockStore.load(EasyMock.anyString())).andAnswer(new IAnswer<Session>() {
@Override
public Session answer() throws Throwable {
return timedOutSession(manager, sessionExpireCounter);
}
}).anyTimes();
EasyMock.replay(mockStore);
manager.setStore(mockStore);
Host host = new TesterHost();
RequestCachingSessionListener requestCachingSessionListener = new RequestCachingSessionListener();
Context context = new TesterContext() {
@Override
public Object[] getApplicationLifecycleListeners() {
return new Object[] { requestCachingSessionListener };
}
@Override
public Manager getManager() {
return manager;
}
};
context.setParent(host);
Connector connector = EasyMock.createNiceMock(Connector.class);
Request req = new Request(connector) {
@Override
public Context getContext() {
return context;
}
};
req.setRequestedSessionId("invalidSession");
HttpServletRequest request = new RequestFacade(req);
EasyMock.replay(connector);
requestCachingSessionListener.request = request;
manager.setContext(context);
manager.start();
Assert.assertNull(request.getSession(false));
Assert.assertEquals(1, sessionExpireCounter.get());
}
Aggregations