use of org.apache.tomcat.unittest.TesterContext 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.TesterContext in project tomcat by apache.
the class TestResponse method doTestSendRedirect.
private void doTestSendRedirect(String input, String expectedLocation) throws Exception {
// Set-up.
// Note: Not sufficient for testing relative -> absolute
Connector connector = new Connector();
org.apache.coyote.Response cResponse = new org.apache.coyote.Response();
Response response = new Response();
response.setCoyoteResponse(cResponse);
Request request = new Request(connector);
org.apache.coyote.Request cRequest = new org.apache.coyote.Request();
request.setCoyoteRequest(cRequest);
Context context = new TesterContext();
request.getMappingData().context = context;
response.setRequest(request);
// Do test
response.sendRedirect(input);
String location = response.getHeader("Location");
Assert.assertEquals(expectedLocation, location);
}
use of org.apache.tomcat.unittest.TesterContext in project tomcat by apache.
the class TestAsyncContextImpl method testAsyncListenerSupplyRequestResponse.
@Test
public void testAsyncListenerSupplyRequestResponse() {
final ServletRequest servletRequest = EasyMock.createMock(ServletRequest.class);
final ServletResponse servletResponse = EasyMock.createMock(ServletResponse.class);
final AsyncListener listener = new AsyncListener() {
@Override
public void onTimeout(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onStartAsync(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onError(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
@Override
public void onComplete(AsyncEvent event) throws IOException {
checkRequestResponse(event);
}
private void checkRequestResponse(AsyncEvent event) {
Assert.assertEquals(servletRequest, event.getSuppliedRequest());
Assert.assertEquals(servletResponse, event.getSuppliedResponse());
}
};
final Context context = new TesterContext();
final Response response = new Response();
final Request request = new Request(null);
request.setCoyoteRequest(new org.apache.coyote.Request());
request.getMappingData().context = context;
final AsyncContextImpl ac = new AsyncContextImpl(request);
ac.addListener(listener, servletRequest, servletResponse);
ac.setStarted(context, request, response, true);
ac.addListener(listener, servletRequest, servletResponse);
ac.setErrorState(new Exception(), true);
ac.fireOnComplete();
}
use of org.apache.tomcat.unittest.TesterContext 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.TesterContext 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