/** * {@inheritDoc} */ @Override public Object beforeBody(long methodId, Object object, Object[] parameters, SpecialSensorConfig ssc) { if ((null != parameters) && (parameters.length == 4)) { // the HTTP context Object httpContext = parameters[2]; // the original callback given by the user Object originalCallback = parameters[3]; SpanStoreAdapter spanStoreAdapter = new ApacheHttpContextSpanStoreAdapter(httpContext); FutureCallbackProxy proxy = new FutureCallbackProxy(originalCallback, spanStoreAdapter); Object newProxy = runtimeLinker.createProxy(FutureCallbackProxy.class, proxy, object.getClass().getClassLoader()); parameters[3] = newProxy; } return null; }
@Test public void returnsAnEmptyCollection() { Object[] args = proxy.getProxyConstructorArguments(); assertThat("Number of args returned by the constructor must be zero.", args, is(new Object[] {})); } }
@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 { Object response = new Object(); removeOriginalCallback(); proxy.completed(response); 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 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() { Object response = new Object(); proxy.completed(response); verify(spanStoreAdapter).getSpanStore(); verify(originalCallback).completed(response); verifyNoMoreInteractions(spanStoreAdapter, originalCallback); verifyZeroInteractions(spanStore); }
@BeforeMethod public void init() throws Exception { proxy = new FutureCallbackProxy(originalCallback, spanStoreAdapter); WFutureCallback.completed = new CachedMethod<Void>(FutureCallback.class.getName(), "completed", Object.class); WFutureCallback.failed = new CachedMethod<Void>(FutureCallback.class.getName(), "failed", Exception.class); WFutureCallback.cancelled = new CachedMethod<Void>(FutureCallback.class.getName(), "cancelled"); }
@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)); }
@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); }
@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); }