/** * Request committed event. This is earliest place we can start a span. * * @throws IOException * IOException */ @ProxyMethod() public void onRequestCommitted() throws IOException { spanStore.startSpan(); if (null != originalListener) { WHttpEventListenerWrapper.ON_REQUEST_COMMITED.call(originalListener); } }
/** * {@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 happyPath() throws IOException { proxy.onRequestCommitted(); verify(spanStore).startSpan(); } }
@Test public void spanIsNull() { spanStore.storeSpan(null); boolean result = spanStore.startSpan(); assertThat(result, is(false)); verifyZeroInteractions(span); } }
@Test public void alreadyStarted() { when(span.isStarted()).thenReturn(true); boolean result = spanStore.startSpan(); assertThat(result, is(false)); verify(span).isStarted(); verifyNoMoreInteractions(span); }
@Test public void successful() { SpanStore spanStore = mock(SpanStore.class); HttpContext context = mock(HttpContext.class); when(context.getAttribute(SpanStoreAdapter.Constants.ID)).thenReturn(spanStore); handler.localContext = context; hook.beforeBody(5L, 10L, handler, null, rsc); verify(context).getAttribute(SpanStoreAdapter.Constants.ID); verify(spanStore).startSpan(); verifyNoMoreInteractions(spanStore, context); verifyZeroInteractions(rsc); }
@Test public void successful() { when(span.isStarted()).thenReturn(false); boolean result = spanStore.startSpan(); assertThat(result, is(true)); verify(span).start(); verify(span).isStarted(); verifyNoMoreInteractions(span); }