/** * Tests that the previous session id is kept when all memcached nodes fail. * * @throws Throwable */ @Test( enabled = true ) public void testAllMemcachedNodesFailure() throws Throwable { _tomcat1.getManager().setSticky( true ); // we had a situation where no session was created, so let's take some break so that everything's up again Thread.sleep( 200 ); final String sid1 = makeRequest( _httpClient, _portTomcat1, null ); assertNotNull( sid1, "No session created." ); /* shutdown all memcached nodes */ _daemon1.stop(); _daemon2.stop(); _daemon3.stop(); // wait a little bit Thread.sleep( 200 ); final String sid2 = makeRequest( _httpClient, _portTomcat1, sid1 ); assertEquals( sid1, sid2, "SessionId changed." ); assertNotNull( getSessions().get( sid1 ), "Session "+ sid1 +" not existing." ); final Session session = _tomcat1.getManager().findSession( sid2 ); assertFalse( session.getNoteNames().hasNext(), "Some notes are set: " + toArray( session.getNoteNames() ) ); }
final Session session = _tomcat1.getManager().findSession( sid2 ); assertNotNull( session, "Session not found by new id " + sid2 ); assertFalse( session.getNoteNames().hasNext(), "Some notes are set: " + toArray( session.getNoteNames() ) );
final Session session = _tomcat1.getManager().findSession( sid2 ); assertFalse( session.getNoteNames().hasNext(), "Some notes are set: " + toArray( session.getNoteNames() ) );
/** * Test for issue #38: * Notify HttpSessionActivationListeners when loading a session from memcached * @throws Exception */ @Test( enabled = true ) public void testHttpSessionActivationListenersNotifiedOnLoadWithoutJvmRoute() throws Exception { _tomcat1.stop(); _tomcat2.stop(); _tomcat1 = startTomcat( TC_PORT_1, null ); _tomcat2 = startTomcat( TC_PORT_2, null ); final SessionManager manager1 = _tomcat1.getManager(); final SessionManager manager2 = _tomcat2.getManager(); final SessionIdFormat format = new SessionIdFormat(); final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId(); assertNull( format.extractJvmRoute( sessionId1 ) ); final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 ); session.setAttribute( "listener", new RecordingSessionActivationListener() ); get( _httpClient, TC_PORT_1, sessionId1 ); final String sessionId2 = get( _httpClient, TC_PORT_2, sessionId1 ).getSessionId(); assertEquals( sessionId2, sessionId1 ); final MemcachedBackupSession loaded = (MemcachedBackupSession) manager2.findSession( sessionId2 ); assertNotNull( loaded ); final RecordingSessionActivationListener listener = (RecordingSessionActivationListener) loaded.getAttribute( "listener" ); assertNotNull( listener ); final String notifiedSessionId = listener.getSessionDidActivate(); assertEquals( notifiedSessionId, sessionId2 ); }
/** * Test for issue #38: * Notify HttpSessionActivationListeners when loading a session from memcached * @throws Exception */ @Test( enabled = true ) public void testHttpSessionActivationListenersNotifiedOnLoadWithJvmRoute() throws Exception { final SessionManager manager1 = _tomcat1.getManager(); final SessionManager manager2 = _tomcat2.getManager(); final SessionIdFormat format = new SessionIdFormat(); final String sessionId1 = get( _httpClient, TC_PORT_1, null ).getSessionId(); assertEquals( format.extractJvmRoute( sessionId1 ), JVM_ROUTE_1 ); final MemcachedBackupSession session = (MemcachedBackupSession) manager1.findSession( sessionId1 ); session.setAttribute( "listener", new RecordingSessionActivationListener() ); get( _httpClient, TC_PORT_1, sessionId1 ); final String sessionId2 = get( _httpClient, TC_PORT_2, sessionId1 ).getSessionId(); assertEquals( format.stripJvmRoute( sessionId2 ), format.stripJvmRoute( sessionId1 ) ); assertEquals( format.extractJvmRoute( sessionId2 ), JVM_ROUTE_2 ); final MemcachedBackupSession loaded = (MemcachedBackupSession) manager2.findSession( sessionId2 ); assertNotNull( loaded ); final RecordingSessionActivationListener listener = (RecordingSessionActivationListener) loaded.getAttribute( "listener" ); assertNotNull( listener ); final String notifiedSessionId = listener.getSessionDidActivate(); assertEquals( notifiedSessionId, sessionId2 ); }