_currentRequest = currentRequest; _msmContext = _sessionBackupService.getManager().getContext();
@BeforeMethod public void setUp() throws Exception { _service = mock( MemcachedSessionService.class ); _request = mock( Request.class ); _response = mock( Response.class ); final Context _contextContainer = mock(Context.class); final Host _hostContainer = mock(Host.class); final SessionManager _manager = mock(SessionManager.class); when(_service.getManager()).thenReturn(_manager); when(_manager.getContext()).thenReturn(_contextContainer); when(_contextContainer.getParent()).thenReturn(_hostContainer); when(_contextContainer.getPath()).thenReturn("/"); _sessionTrackerValve = createSessionTrackerValve(); _nextValve = mock( Valve.class ); _sessionTrackerValve.setNext( _nextValve ); _sessionTrackerValve.setContainer(_hostContainer); when(_request.getRequestURI()).thenReturn( "/someRequest"); when(_request.getMethod()).thenReturn("GET"); when(_request.getQueryString()).thenReturn(null); when(_request.getContext()).thenReturn(_contextContainer); when(_request.getNote(eq(RequestTrackingHostValve.REQUEST_PROCESSED))).thenReturn(Boolean.TRUE); when(_request.getNote(eq(RequestTrackingHostValve.SESSION_ID_CHANGED))).thenReturn(Boolean.FALSE); }
@Override public BackupResult call() throws Exception { final MemcachedBackupSession session3 = _service.findSession(session.getId()); assertSame(session3, session2); assertEquals(session3.getRefCount(), 2); // let the other thread proceed (or wait) barrier.await(); // and wait again so that the other thread can do some work barrier.await(); final Future<BackupResult> result = _service.backupSession(session.getId(), false, "unused"); _service.getTrackingHostValve().resetRequestThreadLocal(); assertEquals(result.get().getStatus(), BackupResultStatus.SUCCESS); // The session should be released now and no longer stored assertFalse(_service.getManager().getSessionsInternal().containsKey(session.getId())); // just some double checking on expectations... assertEquals(session2.getRefCount(), 0); return result.get(); }
_service.getManager().changeSessionId( session );
assertFalse(_service.getManager().getSessionsInternal().containsKey(session.getId())); assertEquals(result.get().getStatus(), BackupResultStatus.SKIPPED); assertTrue(_service.getManager().getSessionsInternal().containsKey(session.getId()));
_currentRequest = currentRequest; _msmContext = _sessionBackupService.getManager().getContext();