@Test public void testCreateSessionAndPassivate() throws IOException, LifecycleException, ClassNotFoundException { // Setup Tomcat instance Tomcat tomcat = getTomcatInstance(); // No file system docBase required StandardContext ctx = (StandardContext) tomcat.addContext("", null); ctx.setDistributable(true); Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet()); ctx.addServletMapping("/dummy", "DummyServlet"); PersistentManager manager = new PersistentManager(); TesterStore store = new TesterStore(); manager.setStore(store); manager.setMaxIdleBackup(0); ctx.setManager(manager); ctx.addValve(new PersistentValve()); tomcat.start(); Assert.assertEquals("No active sessions", manager.getActiveSessions(), 0); Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty()); String sessionId = getUrl( "http://localhost:" + getPort() + "/dummy?no_create_session=false").toString(); Assert.assertNotNull("Session is stored", store.load(sessionId)); Assert.assertEquals("All sessions are passivated", manager.getActiveSessions(), 0); Assert.assertTrue("One session was created", !manager.getSessionIdsFull().isEmpty()); }
@Test public void noSessionCreate_57637() throws IOException, LifecycleException { // Setup Tomcat instance Tomcat tomcat = getTomcatInstance(); // No file system docBase required StandardContext ctx = (StandardContext) tomcat.addContext("", null); ctx.setDistributable(true); Tomcat.addServlet(ctx, "DummyServlet", new DummyServlet()); ctx.addServletMapping("/dummy", "DummyServlet"); PersistentManager manager = new PersistentManager(); TesterStore store = new TesterStore(); manager.setStore(store); manager.setMaxIdleBackup(0); ctx.setManager(manager); ctx.addValve(new PersistentValve()); tomcat.start(); Assert.assertEquals(manager.getActiveSessions(), 0); Assert.assertTrue("No sessions managed", manager.getSessionIdsFull().isEmpty()); Assert.assertEquals( "NO_SESSION", getUrl( "http://localhost:" + getPort() + "/dummy?no_create_session=true").toString()); Assert.assertEquals(manager.getActiveSessions(), 0); Assert.assertTrue("No sessions where created", manager.getSessionIdsFull().isEmpty()); }