public void testReleaseSessions() { addSession("handle", "id", 1); addSession("handle2", "id2", 1); addSession("handle3", "id3", 1); assertEquals(3, info.getNumberOfSessions()); info.removeSessions(); assertEquals(0, info.getNumberOfSessions()); addSession("handle", "id", 1); addSession("handle2", "id2", 2); info.removeSession("id2"); assertEquals(1, info.getNumberOfSessions()); assertNull(info.getSessionIdForPortlet("handle2")); assertEquals("id", info.getSessionIdForPortlet("handle")); info.removeSessionForPortlet("handle"); assertEquals(0, info.getNumberOfSessions()); assertNull(info.getSessionIdForPortlet("handle")); try { info.removeSessionForPortlet("handle"); fail("Session for portlet 'handle' should have already been released!"); } catch (IllegalArgumentException expected) { // expected } }
public void testSessionForPortlet() throws Exception { String handle = "handle"; String handle2 = "handle2"; String sid = "id"; String sid2 = "id2"; assertNull(info.getSessionIdForPortlet(handle)); assertEquals(0, info.getNumberOfSessions()); addSession(handle, sid, 1); addSession(handle2, sid2, 3); assertNull(info.getSessionIdForPortlet("unknown")); assertEquals(sid, info.getSessionIdForPortlet(handle)); assertEquals(2, info.getNumberOfSessions()); Thread.sleep(SLEEP_TIME); assertNull(info.getSessionIdForPortlet(handle)); assertEquals(sid2, info.getSessionIdForPortlet(handle2)); assertEquals(1, info.getNumberOfSessions()); info.removeSessionForPortlet(handle2); assertEquals(0, info.getNumberOfSessions()); }