SessionManager implements Closeable { public void switchSessionId(RepositoryBackedSession session) { switchSessionId(session, null); } SessionManager(ExecutorFacade executors, SessionFactory factory, SessionRepository repository,
      SessionTracking tracking, SessionNotifier notifier, SessionConfiguration configuration, ClassLoader classLoader); RepositoryBackedSession fetchSession(String sessionId, boolean updateTimestamp); RepositoryBackedSession getSession(RequestWithSession request, boolean create,
      SessionTracking.IdAndSource forceId); void propagateSession(RequestWithSession request, ResponseWithSessionId response); void delete(String sessionId, boolean expired); void requestFinished(); Future<?> submit(String timer, Runnable task); ScheduledFuture<?> schedule(String timer, Runnable task, long period); void deleteAsync(final String sessionId, final boolean expired); SessionRepository getRepository(); SessionNotifier getNotifier(); void invokeCommit(RepositoryBackedSession session); SessionConfiguration getConfiguration(); ClassLoader getSessionClassLoader(); SerializerDeserializer getSerializerDeserializer(); void invalidationConflict(RepositoryBackedSession session, boolean onExpiry); MetricRegistry getMetrics(); String encodeUrl(RequestWithSession request, String url); void reset(); @Override void close(); void switchSessionId(RepositoryBackedSession session); void switchSessionId(RepositoryBackedSession session, String forceId); @Override String toString(); void remove(SessionData sessionData); boolean isConnected();  }
@Test public void testSessionSwitch() { RepositoryBackedSession session = mock(RepositoryBackedSession.class); SessionData sessionData = mock(SessionData.class); when(sessionData.getId()).thenReturn("45"); when(tracking.newId()).thenReturn("47"); when(session.getSessionData()).thenReturn(sessionData); sessionManager.switchSessionId(session); verify(sessionData).isIdChanged(); verify(sessionData).setNewSessionId(any(String.class)); verify(repository).sessionIdChange(sessionData); verify(notifier).sessionIdChanged(session, sessionData.getOldSessionId()); assertEquals("Session id in Logging MDC is wrong", "47", MDC.get(configuration.getLoggingMdcKey())); }
@Test public void testPreventDoubleSessionSwitch() { RepositoryBackedSession session = mock(RepositoryBackedSession.class); SessionData sessionData = mock(SessionData.class); when(session.getSessionData()).thenReturn(sessionData); when(sessionData.isIdChanged()).thenReturn(true); sessionManager.switchSessionId(session); verify(sessionData).isIdChanged(); verify(sessionData, never()).setNewSessionId(any(String.class)); verify(repository, never()).sessionIdChange(sessionData); verify(notifier, never()).sessionIdChanged(session, sessionData.getOldSessionId()); }