### Question:
HttpPipelineHandler extends SimpleChannelInboundHandler<LiveHttpRequest> { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { eventProcessor.submit(new ChannelExceptionEvent(ctx, cause)); } private  HttpPipelineHandler(Builder builder, RequestTracker tracker); @Override void channelActive(ChannelHandlerContext ctx); @Override void channelInactive(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause);  }### Answer:
@Test public void requestTimeoutExceptionOccursInAcceptingRequestsStateAndTcpConnectionRemainsActive() throws Exception { RuntimeException cause = new RequestTimeoutException("timeout occurred"); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(REQUEST_TIMEOUT, cause); verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(null)); verify(responseWriter).write(response(REQUEST_TIMEOUT) .header(CONTENT_LENGTH, 15) .header(CONNECTION, "close") .build()); }
@Test public void tooLongFrameExceptionOccursInIdleStateAndTcpConnectionRemainsActive() throws Exception { setupHandlerTo(WAITING_FOR_RESPONSE); RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new TooLongFrameException("too long frame"))); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(REQUEST_ENTITY_TOO_LARGE, cause); verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request)); verify(responseWriter).write(response(REQUEST_ENTITY_TOO_LARGE) .header(CONTENT_LENGTH, 24) .header(CONNECTION, "close") .build()); }
@Test public void badRequestExceptionExceptionOccursInIdleStateAndTcpConnectionRemainsActive() throws Exception { setupHandlerTo(WAITING_FOR_RESPONSE); RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new RuntimeException("random bad request failure"))); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(BAD_REQUEST, cause); verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request)); verify(responseWriter).write(response(BAD_REQUEST) .header(CONTENT_LENGTH, 11) .header(CONNECTION, "close") .build()); }
@Test public void requestTimeoutExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive() throws Exception { setupHandlerTo(WAITING_FOR_RESPONSE); RuntimeException cause = new RequestTimeoutException("timeout occurred"); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(REQUEST_TIMEOUT, cause); responseWriter.write(response(REQUEST_TIMEOUT).build()); }
@Test public void tooLongFrameExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive() throws Exception { setupHandlerTo(WAITING_FOR_RESPONSE); RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new TooLongFrameException("too long frame"))); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(REQUEST_ENTITY_TOO_LARGE, cause); responseWriter.write(response(REQUEST_ENTITY_TOO_LARGE).build()); }
@Test public void badRequestExceptionExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive() throws Exception { setupHandlerTo(WAITING_FOR_RESPONSE); RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new RuntimeException("random bad request failure"))); handler.exceptionCaught(ctx, cause); verify(errorListener).proxyErrorOccurred(BAD_REQUEST, cause); responseWriter.write(response(BAD_REQUEST).build()); }