Context { public void writeAndFlush(final ResponseMessage message) { writeAndFlush(message.getStatus().getCode(), message); } Context(final RequestMessage requestMessage, final ChannelHandlerContext ctx,
                   final Settings settings, final GraphManager graphManager,
                   final GremlinExecutor gremlinExecutor, final ScheduledExecutorService scheduledExecutorService); ScheduledExecutorService getScheduledExecutorService(); RequestMessage getRequestMessage(); ChannelHandlerContext getChannelHandlerContext(); Settings getSettings(); GraphManager getGraphManager(); GremlinExecutor getGremlinExecutor(); void writeAndFlush(final ResponseMessage message); void writeAndFlush(final ResponseStatusCode code, final Object responseMessage);  }
@Test public void shouldAllowMultipleNonFinalResponses() { writeInvoker.apply(context, ResponseStatusCode.AUTHENTICATE); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); writeInvoker.apply(context, ResponseStatusCode.PARTIAL_CONTENT); Mockito.verify(ctx, Mockito.times(2)).writeAndFlush(Mockito.any()); writeInvoker.apply(context, ResponseStatusCode.PARTIAL_CONTENT); Mockito.verify(ctx, Mockito.times(3)).writeAndFlush(Mockito.any()); }
@Test public void shouldAllowAtMostOneFinalResponse() { writeInvoker.apply(context, ResponseStatusCode.AUTHENTICATE); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); writeInvoker.apply(context, ResponseStatusCode.SUCCESS); Mockito.verify(ctx, Mockito.times(2)).writeAndFlush(Mockito.any()); writeInvoker.apply(context, ResponseStatusCode.SERVER_ERROR_TIMEOUT); assertTrue(recordingAppender.logContainsAny(".*" + request.getRequestId() + ".*")); assertTrue(recordingAppender.logContainsAny(".*" + ResponseStatusCode.SERVER_ERROR_TIMEOUT + "$")); Mockito.verify(ctx, Mockito.times(2)).writeAndFlush(Mockito.any()); }
@Test public void shouldNotAllowNonFinalMessagesAfterFinalResponse() { writeInvoker.apply(context, ResponseStatusCode.SERVER_ERROR_TIMEOUT); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); writeInvoker.apply(context, ResponseStatusCode.PARTIAL_CONTENT); assertTrue(recordingAppender.logContainsAny(".*" + request.getRequestId() + ".*")); assertTrue(recordingAppender.logContainsAny(".*" + ResponseStatusCode.PARTIAL_CONTENT + "$")); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); }
@Test public void shouldReleaseIgnoredFrames() { writeInvoker.apply(context, ResponseStatusCode.SERVER_ERROR_TIMEOUT); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); Frame frame = Mockito.mock(Frame.class); context.writeAndFlush(ResponseStatusCode.SUCCESS, frame); assertTrue(recordingAppender.logContainsAny(".*" + request.getRequestId() + ".*")); assertTrue(recordingAppender.logContainsAny(".*" + ResponseStatusCode.SUCCESS + "$")); Mockito.verify(ctx, Mockito.times(1)).writeAndFlush(Mockito.any()); Mockito.verify(frame, Mockito.times(1)).tryRelease(); }