### Question:
RequestTrackingContextValve extends ValveBase { @Override public void invoke( final Request request, final Response response ) throws IOException, ServletException { final Object processRequest = request.getNote(RequestTrackingHostValve.REQUEST_PROCESS); if(processRequest != Boolean.TRUE) { request.setNote(INVOKED, Boolean.TRUE); try { getNext().invoke( request, response ); } finally { request.setNote(RequestTrackingHostValve.REQUEST_PROCESSED, Boolean.TRUE); } } else { boolean sessionIdChanged = false; try { request.setNote(INVOKED, Boolean.TRUE); sessionIdChanged = changeRequestedSessionId( request, response ); getNext().invoke( request, response ); } finally { request.setNote(RequestTrackingHostValve.REQUEST_PROCESSED, Boolean.TRUE); request.setNote(RequestTrackingHostValve.SESSION_ID_CHANGED, Boolean.valueOf(sessionIdChanged)); } } } RequestTrackingContextValve( @Nonnull final String sessionCookieName,
            @Nonnull final MemcachedSessionService sessionBackupService ); boolean wasInvokedWith(final Request currentRequest); @Override void invoke( final Request request, final Response response );  }### Answer:
@Test public final void testRequestIsMarkedAsProcessed() throws IOException, ServletException { _sessionTrackerValve.invoke( _request, _response ); verify(_request).setNote(eq(RequestTrackingHostValve.REQUEST_PROCESSED), eq(Boolean.TRUE)); }
@Test public final void testChangeSessionIdForRelocatedSession() throws IOException, ServletException { final String sessionId = "bar"; final String newSessionId = "newId"; when( _request.getRequestedSessionId() ).thenReturn( sessionId ); when( _service.changeSessionIdOnMemcachedFailover( eq( sessionId ) ) ).thenReturn( newSessionId ); _sessionTrackerValve.invoke( _request, _response ); verify( _request ).changeSessionId( eq( newSessionId ) ); verify(_request).setNote(eq(RequestTrackingHostValve.SESSION_ID_CHANGED), eq(Boolean.TRUE)); }