@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.warn("Exception in connection from " + getRemoteAddress(ctx.channel()), cause); requestHandler.exceptionCaught(cause); responseHandler.exceptionCaught(cause); ctx.close(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.warn("Exception in connection from " + getRemoteAddress(ctx.channel()), cause); requestHandler.exceptionCaught(cause); responseHandler.exceptionCaught(cause); ctx.close(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.warn("Exception in connection from " + getRemoteAddress(ctx.channel()), cause); requestHandler.exceptionCaught(cause); responseHandler.exceptionCaught(cause); ctx.close(); }
@Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { logger.warn("Exception in connection from " + getRemoteAddress(ctx.channel()), cause); requestHandler.exceptionCaught(cause); responseHandler.exceptionCaught(cause); ctx.close(); }
@Test public void failOutstandingStreamCallbackOnException() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.exceptionCaught(new IOException("Oops!")); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); } }
@Test public void failOutstandingStreamCallbackOnException() throws Exception { Channel c = new LocalChannel(); c.pipeline().addLast(TransportFrameDecoder.HANDLER_NAME, new TransportFrameDecoder()); TransportResponseHandler handler = new TransportResponseHandler(c); StreamCallback cb = mock(StreamCallback.class); handler.addStreamCallback("stream-1", cb); handler.exceptionCaught(new IOException("Oops!")); verify(cb).onFailure(eq("stream-1"), isA(IOException.class)); } }
@Test public void clearAllOutstandingRequests() throws Exception { TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel()); ChunkReceivedCallback callback = mock(ChunkReceivedCallback.class); handler.addFetchRequest(new StreamChunkId(1, 0), callback); handler.addFetchRequest(new StreamChunkId(1, 1), callback); handler.addFetchRequest(new StreamChunkId(1, 2), callback); assertEquals(3, handler.numOutstandingRequests()); handler.handle(new ChunkFetchSuccess(new StreamChunkId(1, 0), new TestManagedBuffer(12))); handler.exceptionCaught(new Exception("duh duh duhhhh")); // should fail both b2 and b3 verify(callback, times(1)).onSuccess(eq(0), any()); verify(callback, times(1)).onFailure(eq(1), any()); verify(callback, times(1)).onFailure(eq(2), any()); assertEquals(0, handler.numOutstandingRequests()); }
@Test public void clearAllOutstandingRequests() throws Exception { TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel()); ChunkReceivedCallback callback = mock(ChunkReceivedCallback.class); handler.addFetchRequest(new StreamChunkId(1, 0), callback); handler.addFetchRequest(new StreamChunkId(1, 1), callback); handler.addFetchRequest(new StreamChunkId(1, 2), callback); assertEquals(3, handler.numOutstandingRequests()); handler.handle(new ChunkFetchSuccess(new StreamChunkId(1, 0), new TestManagedBuffer(12))); handler.exceptionCaught(new Exception("duh duh duhhhh")); // should fail both b2 and b3 verify(callback, times(1)).onSuccess(eq(0), any()); verify(callback, times(1)).onFailure(eq(1), any()); verify(callback, times(1)).onFailure(eq(2), any()); assertEquals(0, handler.numOutstandingRequests()); }