Java Code Examples for org.apache.catalina.Context#setParent()

The following examples show how to use org.apache.catalina.Context#setParent() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestPersistentManager.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
@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());
}
 
Example 2
Source File: TestPersistentManager.java    From tomcatsrc with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example 3
Source File: RedisStoreTest.java    From session-managers with Apache License 2.0 5 votes vote down vote up
@Before
public void setupManager() {
    Context context = new StandardContext();
    Host host = new StandardHost();

    this.manager.setContext(context);
    context.setName("test-context-name");
    context.setParent(host);
    host.setName("test-host-name");
}
 
Example 4
Source File: TestPersistentManager.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
@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() {
        @Override
        public Context getContext() {
            return context;
        }
    };
    req.setRequestedSessionId("invalidSession");
    HttpServletRequest request = new RequestFacade(req);
    requestCachingSessionListener.request = request;

    manager.setContext(context);

    manager.start();

    Assert.assertNull(request.getSession(false));
    Assert.assertEquals(1, sessionExpireCounter.get());

}