@Override public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { HttpProcessingState state = getStateAndCreateIfNeeded(ctx, cause); finalizeChannelPipeline(ctx, null, state, cause); return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof LastOutboundMessage) { Exception ex = new Exception("Manually created exception to be used for diagnostic stack trace"); HttpProcessingState state = getStateAndCreateIfNeeded(ctx, ex); finalizeChannelPipeline(ctx, msg, state, ex); } return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof LastOutboundMessage) { Exception ex = new Exception("Manually created exception to be used for diagnostic stack trace"); HttpProcessingState state = getStateAndCreateIfNeeded(ctx, ex); finalizeChannelPipeline(ctx, msg, state, ex); } return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT; }
@Override public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { HttpProcessingState state = getStateAndCreateIfNeeded(ctx, cause); finalizeChannelPipeline(ctx, null, state, cause); return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT; }
@Test public void getStateAndCreateIfNeeded_uses_state_from_ctx_if_available() { // expect assertThat(handler.getStateAndCreateIfNeeded(ctxMock, null), is(state)); }
@Test public void getStateAndCreateIfNeeded_creates_new_state_if_ctx_state_is_null() { // given doReturn(null).when(stateAttributeMock).get(); // when HttpProcessingState result = handler.getStateAndCreateIfNeeded(ctxMock, null); // then assertThat(result, notNullValue()); assertThat(result, not(state)); verify(stateAttributeMock).set(result); }
@Test public void doExceptionCaught_gets_state_from_getStateAndCreateIfNeeded_method_and_then_calls_finalizeChannelPipeline_and_then_returns_DO_NOT_FIRE_CONTINUE_EVENT() throws Exception { // given ChannelPipelineFinalizerHandler handlerSpy = spy(handler); Exception cause = new Exception("intentional test exception"); state.setResponseWriterFinalChunkChannelFuture(mock(ChannelFuture.class)); // when PipelineContinuationBehavior result = handlerSpy.doExceptionCaught(ctxMock, cause); // then verify(handlerSpy).getStateAndCreateIfNeeded(ctxMock, cause); verify(handlerSpy).finalizeChannelPipeline(ctxMock, null, state, cause); assertThat(result, is(PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT)); }