RpcClientHandler extends RpcHandler<RpcClientRequest, RpcClientResponse> { public void handleReceive(RpcClientResponse response, Span span) { handleFinish(response, span); } RpcClientHandler(RpcTracing rpcTracing); static RpcClientHandler create(RpcTracing rpcTracing); Span handleSend(RpcClientRequest request); Span handleSendWithParent(RpcClientRequest request, @Nullable TraceContext parent); Span handleSend(RpcClientRequest request, Span span); void handleReceive(RpcClientResponse response, Span span);  }
@Test public void handleReceive_finishesSpanEvenIfUnwrappedNull() { brave.Span span = mock(brave.Span.class); when(span.context()).thenReturn(context); when(span.customizer()).thenReturn(span); handler.handleReceive(mock(RpcClientResponse.class), span); verify(span).isNoop(); verify(span).context(); verify(span).customizer(); verify(span).finish(); verifyNoMoreInteractions(span); }
@Test public void handleReceive_finishesSpanEvenIfUnwrappedNull_withError() { brave.Span span = mock(brave.Span.class); when(span.context()).thenReturn(context); when(span.customizer()).thenReturn(span); Exception error = new RuntimeException("peanuts"); when(response.error()).thenReturn(error); handler.handleReceive(response, span); verify(span).isNoop(); verify(span).context(); verify(span).customizer(); verify(span).error(error); verify(span).finish(); verifyNoMoreInteractions(span); }
@Test public void handleReceive_responseRequired() { brave.Span span = mock(brave.Span.class); assertThatThrownBy(() -> handler.handleReceive(null, span)) .isInstanceOf(NullPointerException.class) .hasMessage("response == null"); }