Search in sources :

Example 1 with TesterHost

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());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Request(org.apache.catalina.connector.Request) HttpServletRequest(javax.servlet.http.HttpServletRequest) Store(org.apache.catalina.Store) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) RequestFacade(org.apache.catalina.connector.RequestFacade) HttpServletRequest(javax.servlet.http.HttpServletRequest) IAnswer(org.easymock.IAnswer) TesterHost(org.apache.tomcat.unittest.TesterHost) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Example 2 with TesterHost

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());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) TesterHost(org.apache.tomcat.unittest.TesterHost) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Example 3 with TesterHost

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());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) TesterHost(org.apache.tomcat.unittest.TesterHost) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Example 4 with TesterHost

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());
}
Also used : Context(org.apache.catalina.Context) TesterContext(org.apache.tomcat.unittest.TesterContext) Connector(org.apache.catalina.connector.Connector) Request(org.apache.catalina.connector.Request) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) Store(org.apache.catalina.Store) TesterHost(org.apache.tomcat.unittest.TesterHost) Host(org.apache.catalina.Host) RequestFacade(org.apache.catalina.connector.RequestFacade) HttpServletRequest(jakarta.servlet.http.HttpServletRequest) IAnswer(org.easymock.IAnswer) TesterHost(org.apache.tomcat.unittest.TesterHost) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TesterContext(org.apache.tomcat.unittest.TesterContext) Test(org.junit.Test)

Aggregations

Context (org.apache.catalina.Context)4 Host (org.apache.catalina.Host)4 TesterContext (org.apache.tomcat.unittest.TesterContext)4 TesterHost (org.apache.tomcat.unittest.TesterHost)4 Test (org.junit.Test)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Store (org.apache.catalina.Store)2 Request (org.apache.catalina.connector.Request)2 RequestFacade (org.apache.catalina.connector.RequestFacade)2 IAnswer (org.easymock.IAnswer)2 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 Connector (org.apache.catalina.connector.Connector)1