@Before
 public void setup() {
   nioLogger =
       new NioLogger(
           "NONE"); // Changing this might affect assertions around number of mock method
                    // invocations
   sessionManager = new IoSessionManager();
   sessionManager.setMaxTimeToWaitForRequestCompletion(5000);
   sessionManager.setNioLogger(nioLogger);
   cougarProtocol = CougarProtocol.getServerInstance(nioLogger, 5000, 10000, null, false, false);
   TransportCommandProcessor<SocketTransportCommand> processor =
       new SocketTransportCommandProcessor();
   serverHandler = mock(ExecutionVenueServerHandler.class);
   when(serverHandler.getOutstandingRequests()).thenReturn(0l);
 }
  @Test
  public void testSuspendAndDisconnectMessagesAreWrittenForV2Sessions() {
    final IoSession ioSession = newSession(V2);

    sessionManager.shutdownSessions(singleton(ioSession), cougarProtocol, serverHandler);

    verify(ioSession).write(isA(SuspendMessage.class));
    verify(ioSession).write(isA(DisconnectMessage.class));
  }
  @Test
  public void testSessionsAreClosedOnlyAfterOutstandingRequestsAreServed() {
    final IoSession ioSession = newSession(V2);
    ExecutionVenueServerHandler serverHandler = mock(ExecutionVenueServerHandler.class);
    when(serverHandler.getOutstandingRequests()).thenReturn(2l, 1l, 0l); // Counting down

    sessionManager.shutdownSessions(singleton(ioSession), cougarProtocol, serverHandler);

    final InOrder inOrder = inOrder(ioSession, serverHandler);
    inOrder.verify(ioSession).write(isA(SuspendMessage.class));
    inOrder.verify(serverHandler, times(3)).getOutstandingRequests();
    inOrder.verify(ioSession).write(isA(DisconnectMessage.class));
  }