### Question:
SessionManager { synchronized OperationFuture getAndCreateSessionIfNotExist(HttpServletRequest request, Supplier<OperationFuture> operation, int step) { HttpSession session = request.getSession(); SessionInfo info = _inProgressSessions.get(session); String requestString = toRequestString(request); if (info != null) { LOG.info("Found existing session {}", session); info.ensureSameRequest(requestString, request.getParameterMap()); if (step < info.numFutures()) { return info.future(step); } else if (step == info.numFutures()) { LOG.info("Adding new future to existing session {}.", session); OperationFuture future = operation.get(); info.addFuture(future); return future; } else { throw new IllegalArgumentException(String.format("There are %d steps in the session. Cannot add step %d.", info.numFutures(), step)); } } else { if (step > 0) { throw new IllegalArgumentException(String.format("There are no step in the session. Cannot add step %d.", step)); } if (_inProgressSessions.size() >= _capacity) { _sessionCreationFailureMeter.mark(); throw new RuntimeException("There are already " + _inProgressSessions.size() + " active sessions, which " + "has reached the servlet capacity."); } LOG.info("Created session for {}", session); info = new SessionInfo(requestString, request.getParameterMap(), ParameterUtils.endPoint(request)); OperationFuture future = operation.get(); info.addFuture(future); _inProgressSessions.put(session, info); return future; } } SessionManager(int capacity,
                 long sessionExpiryMs,
                 Time time,
                 MetricRegistry dropwizardMetricRegistry,
                 Map<EndPoint, Timer> successfulRequestExecutionTimer); void close();  }### Answer:
@Test public void testMultipleOperationRequest() { TestContext context = prepareRequests(false, 1); SessionManager sessionManager = new SessionManager(1, 1000, context.time(), new MetricRegistry(), null); HttpServletRequest request = context.request(0); OperationFuture future1 = new OperationFuture("future1"); OperationFuture future2 = new OperationFuture("future2"); for (int i = 0; i < 2; i++) { OperationFuture firstFuture = sessionManager.getAndCreateSessionIfNotExist(request, () -> future1, 0); assertSame(firstFuture, future1); future1.complete(new PauseSamplingResult(null)); OperationFuture secondFuture = sessionManager.getAndCreateSessionIfNotExist(request, () -> future2, 1); assertSame(secondFuture, future2); future2.complete(new ResumeSamplingResult(null)); } }
@Test (expected = IllegalArgumentException.class) public void testSkipStep() { TestContext context = prepareRequests(false, 1); SessionManager sessionManager = new SessionManager(1, 1000, context.time(), new MetricRegistry(), null); HttpServletRequest request = context.request(0); sessionManager.getAndCreateSessionIfNotExist(request, () -> null, 1); }