@Override void handleFailure(String errorMsg, Throwable cause) { handler.removeFetchRequest(streamChunkId); callback.onFailure(chunkIndex, new IOException(errorMsg, cause)); } };
@Override void handleFailure(String errorMsg, Throwable cause) { handler.removeFetchRequest(streamChunkId); callback.onFailure(chunkIndex, new IOException(errorMsg, cause)); } };
/** * Fire the failure callback for all outstanding requests. This is called when we have an * uncaught exception or pre-mature connection termination. */ private void failOutstandingRequests(Throwable cause) { for (Map.Entry<StreamChunkId, ChunkReceivedCallback> entry : outstandingFetches.entrySet()) { entry.getValue().onFailure(entry.getKey().chunkIndex, cause); } for (Map.Entry<Long, RpcResponseCallback> entry : outstandingRpcs.entrySet()) { entry.getValue().onFailure(cause); } // It's OK if new fetches appear, as they will fail immediately. outstandingFetches.clear(); outstandingRpcs.clear(); }
for (Map.Entry<StreamChunkId, ChunkReceivedCallback> entry : outstandingFetches.entrySet()) { try { entry.getValue().onFailure(entry.getKey().chunkIndex, cause); } catch (Exception e) { logger.warn("ChunkReceivedCallback.onFailure throws exception", e);
for (Map.Entry<StreamChunkId, ChunkReceivedCallback> entry : outstandingFetches.entrySet()) { try { entry.getValue().onFailure(entry.getKey().chunkIndex, cause); } catch (Exception e) { logger.warn("ChunkReceivedCallback.onFailure throws exception", e);
for (Map.Entry<StreamChunkId, ChunkReceivedCallback> entry : outstandingFetches.entrySet()) { try { entry.getValue().onFailure(entry.getKey().chunkIndex, cause); } catch (Exception e) { logger.warn("ChunkReceivedCallback.onFailure throws exception", e);
@Override public void operationComplete(ChannelFuture future) throws Exception { if (future.isSuccess()) { if (isTraceEnabled) { long timeTaken = System.currentTimeMillis() - startTime; logger.trace("Sending request {} to {} took {} ms", streamChunkId, getRemoteAddress(channel), timeTaken); } } else { String errorMsg = String.format("Failed to send request %s to %s: %s", streamChunkId, getRemoteAddress(channel), future.cause()); logger.error(errorMsg, future.cause()); handler.removeFetchRequest(streamChunkId); channel.close(); try { callback.onFailure(chunkIndex, new IOException(errorMsg, future.cause())); } catch (Exception e) { logger.error("Uncaught exception in RPC response callback handler!", e); } } } });
channel.close(); try { callback.onFailure(chunkIndex, new IOException(errorMsg, future.cause())); } catch (Exception e) { logger.error("Uncaught exception in RPC response callback handler!", e);
} else { outstandingFetches.remove(resp.streamChunkId); listener.onFailure(resp.streamChunkId.chunkIndex, new ChunkFetchFailureException( "Failure while fetching " + resp.streamChunkId + ": " + resp.errorString));
} else { outstandingFetches.remove(resp.streamChunkId); listener.onFailure(resp.streamChunkId.chunkIndex, new ChunkFetchFailureException( "Failure while fetching " + resp.streamChunkId + ": " + resp.errorString));
} else { outstandingFetches.remove(resp.streamChunkId); listener.onFailure(resp.streamChunkId.chunkIndex, new ChunkFetchFailureException( "Failure while fetching " + resp.streamChunkId + ": " + resp.errorString));
verify(callback, never()).onFailure(anyInt(), any(Throwable.class));
verify(callback, never()).onFailure(anyInt(), any(Throwable.class));
callback.onSuccess(myChunkIndex, result); } else { callback.onFailure(myChunkIndex, new RuntimeException("Failed " + myChunkIndex));
callback.onSuccess(myChunkIndex, result); } else { callback.onFailure(myChunkIndex, new RuntimeException("Failed " + myChunkIndex));
callback.onSuccess(myChunkIndex, result); } else { callback.onFailure(myChunkIndex, new RuntimeException("Failed " + myChunkIndex));
@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()); }
@Test public void handleFailedFetch() throws Exception { StreamChunkId streamChunkId = new StreamChunkId(1, 0); TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel()); ChunkReceivedCallback callback = mock(ChunkReceivedCallback.class); handler.addFetchRequest(streamChunkId, callback); assertEquals(1, handler.numOutstandingRequests()); handler.handle(new ChunkFetchFailure(streamChunkId, "some error msg")); verify(callback, times(1)).onFailure(eq(0), any()); assertEquals(0, handler.numOutstandingRequests()); }
@Test public void handleFailedFetch() throws Exception { StreamChunkId streamChunkId = new StreamChunkId(1, 0); TransportResponseHandler handler = new TransportResponseHandler(new LocalChannel()); ChunkReceivedCallback callback = mock(ChunkReceivedCallback.class); handler.addFetchRequest(streamChunkId, callback); assertEquals(1, handler.numOutstandingRequests()); handler.handle(new ChunkFetchFailure(streamChunkId, "some error msg")); verify(callback, times(1)).onFailure(eq(0), any()); assertEquals(0, handler.numOutstandingRequests()); }