HttpClientHandler extends HttpHandler { @Deprecated public void handleReceive(@Nullable Resp response, @Nullable Throwable error, Span span) { if (span == null) throw new NullPointerException("span == null"); if (response == null && error == null) { throw new IllegalArgumentException( "Either the response or error parameters may be null, but not both"); } if (response == null) { span.error(error).finish(); return; } HttpClientResponse clientResponse; if (response instanceof HttpClientResponse) { clientResponse = (HttpClientResponse) response; if (clientResponse.error() == null && error != null) { span.error(error); } } else { clientResponse = new FromResponseAdapter<>(adapter, response, error); } handleFinish(clientResponse, span); } HttpClientHandler(HttpTracing httpTracing, @Deprecated HttpClientAdapter<Req, Resp> adapter); static HttpClientHandler<HttpClientRequest, HttpClientResponse> create(
    HttpTracing httpTracing); @Deprecated static HttpClientHandler<Req, Resp> create(HttpTracing httpTracing,
    HttpClientAdapter<Req, Resp> adapter); Span handleSend(HttpClientRequest request); Span handleSendWithParent(HttpClientRequest request, @Nullable TraceContext parent); Span handleSend(HttpClientRequest request, Span span); @Deprecated Span handleSend(Injector<Req> injector, Req request); @Deprecated Span handleSend(Injector<C> injector, C carrier, Req request); @Deprecated Span handleSend(Injector<Req> injector, Req request, Span span); @Deprecated Span handleSend(Injector<C> injector, C carrier, Req request, Span span); @Deprecated Span nextSpan(Req request); @Deprecated void handleReceive(@Nullable Resp response, @Nullable Throwable error, Span span); void handleReceive(HttpClientResponse 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(HttpClientResponse.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"); }
@Test public void deprecatedHandleReceive_finishesSpanEvenIfUnwrappedNull() { brave.Span span = mock(brave.Span.class); when(span.context()).thenReturn(context); when(span.customizer()).thenReturn(span); handler.handleReceive(mock(HttpClientResponse.class), null, span); verify(span).isNoop(); verify(span).context(); verify(span).customizer(); verify(span).finish(); verifyNoMoreInteractions(span); }
@Test public void deprecatedHandleReceive_finishesSpanEvenIfUnwrappedNull_withError() { brave.Span span = mock(brave.Span.class); when(span.context()).thenReturn(context); when(span.customizer()).thenReturn(span); Exception error = new RuntimeException("peanuts"); handler.handleReceive(mock(HttpClientResponse.class), error, span); verify(span).isNoop(); verify(span).context(); verify(span).customizer(); verify(span).error(error); verify(span).finish(); verifyNoMoreInteractions(span); }
@Test public void handleReceive_responseParserDoesntSeeNullWhenUnwrappedNull() { AtomicBoolean reachedAssertion = new AtomicBoolean(); init(httpTracingBuilder(tracingBuilder()) .clientParser(new HttpClientParser() { @Override public <Resp> void response(HttpAdapter<?, Resp> adapter, Resp resp, Throwable error, SpanCustomizer span) { assertThat(resp).isSameAs(NULL_SENTINEL); reachedAssertion.set(true); } })); brave.Span span = mock(brave.Span.class); when(span.isNoop()).thenReturn(false); handler.handleReceive(response, null, span); assertThat(reachedAssertion).isTrue(); }