/** * {@inheritDoc} */ @Override public void beforeBody(long methodId, long sensorTypeId, Object object, Object[] parameters, RegisteredSensorConfig rsc) { Object httpContext = REFLECTION_CACHE.getField(object.getClass(), "localContext", object, null); if (httpContext != null) { SpanStoreAdapter spanStoreAdapter = new ApacheHttpContextSpanStoreAdapter(httpContext); SpanStore spanStore = spanStoreAdapter.getSpanStore(); if (spanStore != null) { spanStore.startSpan(); } } }
@Test public void successful() throws Exception { Exception exception = new Exception(); when(spanStoreAdapter.getSpanStore()).thenReturn(spanStore); proxy.failed(exception); verify(spanStoreAdapter).getSpanStore(); verify(spanStore).finishSpan((TagsProvidingAdapter) any()); verify(originalCallback).failed(exception); verifyNoMoreInteractions(spanStore, spanStoreAdapter, originalCallback); }
/** * Failed method of FutureCallback. * * @param exception * Exception thrown when the request failed. */ @ProxyMethod(parameterTypes = { "java.lang.Exception" }) public void failed(Object exception) { try { SpanStore spanStore = spanStoreAdapter.getSpanStore(); if (spanStore != null) { spanStore.finishSpan(new ThrowableAwareResponseAdapter(exception.getClass().getSimpleName())); } } finally { if (originalCallback != null) { WFutureCallback.failed.callSafe(originalCallback, exception); } } }
@Test public void successful() { Object response = new Object(); when(spanStoreAdapter.getSpanStore()).thenReturn(spanStore); proxy.completed(response); verify(spanStoreAdapter).getSpanStore(); verify(spanStore).finishSpan((HttpResponseAdapter) any()); verify(originalCallback).completed(response); verifyNoMoreInteractions(spanStore, spanStoreAdapter, originalCallback); }
@Test public void withoutSpanStoreAndCallback() throws Exception { Object response = new Object(); removeOriginalCallback(); proxy.completed(response); verify(spanStoreAdapter).getSpanStore(); verifyNoMoreInteractions(spanStoreAdapter); verifyZeroInteractions(spanStore, originalCallback); } }
@Test public void withoutSpanStore() { Object response = new Object(); proxy.completed(response); verify(spanStoreAdapter).getSpanStore(); verify(originalCallback).completed(response); verifyNoMoreInteractions(spanStoreAdapter, originalCallback); verifyZeroInteractions(spanStore); }
@Test public void withoutSpanStore() throws Exception { Exception exception = new Exception(); proxy.failed(exception); verify(spanStoreAdapter).getSpanStore(); verify(originalCallback).failed(exception); verifyNoMoreInteractions(spanStoreAdapter, originalCallback); verifyZeroInteractions(spanStore); }
@Test public void withoutSpanStore() throws Exception { proxy.cancelled(); verify(spanStoreAdapter).getSpanStore(); verify(originalCallback).cancelled(); verifyNoMoreInteractions(spanStoreAdapter, originalCallback); verifyZeroInteractions(spanStore); }
@Test public void withoutSpanStoreAndCallback() throws Exception { Exception exception = new Exception(); removeOriginalCallback(); proxy.failed(exception); verify(spanStoreAdapter).getSpanStore(); verifyNoMoreInteractions(spanStoreAdapter); verifyZeroInteractions(spanStore, originalCallback); } }
@Test public void withoutSpanStoreAndCallback() throws Exception { removeOriginalCallback(); proxy.cancelled(); verify(spanStoreAdapter).getSpanStore(); verifyNoMoreInteractions(spanStoreAdapter); verifyZeroInteractions(spanStore, originalCallback); } }
@Test public void successful() throws Exception { when(spanStoreAdapter.getSpanStore()).thenReturn(spanStore); proxy.cancelled(); ArgumentCaptor<TagsProvidingAdapter> captor = ArgumentCaptor.forClass(TagsProvidingAdapter.class); verify(spanStoreAdapter).getSpanStore(); verify(spanStore).finishSpan(captor.capture()); verify(originalCallback).cancelled(); verifyNoMoreInteractions(spanStore, spanStoreAdapter, originalCallback); assertThat(captor.getValue().getTags(), hasKey(SpanStoreAdapter.Constants.CANCEL)); }
/** * Cancelled method for FutureCallback. */ @ProxyMethod() public void cancelled() { try { SpanStore spanStore = spanStoreAdapter.getSpanStore(); if (spanStore != null) { spanStore.finishSpan(new TagsProvidingAdapter() { @Override public Map<String, String> getTags() { return ImmutableMap.of(SpanStoreAdapter.Constants.CANCEL, "true"); } }); } } finally { if (originalCallback != null) { WFutureCallback.cancelled.callSafe(originalCallback); } } }
/** * Completed method for FutureCallback. * * @param response * Response of the request. */ @ProxyMethod(parameterTypes = { "java.lang.Object" }) public void completed(Object response) { try { SpanStore spanStore = spanStoreAdapter.getSpanStore(); if (spanStore != null) { spanStore.finishSpan(new HttpResponseAdapter(new ApacheHttpClientV40HttpResponse(response, CACHE))); } } finally { if (originalCallback != null) { WFutureCallback.completed.callSafe(originalCallback, response); } } }