@BeforeMethod public void setup() { when(requestAdapter.getFormat()).thenReturn(Format.Builtin.TEXT_MAP); when(requestAdapter.getCarrier()).thenReturn(carrier); when(requestAdapter.getSpanStoreAdapter()).thenReturn(spanStoreAdapter); when(tracer.buildSpan(anyString(), anyString(), anyBoolean())).thenReturn(spanBuilder); when(spanBuilder.build()).thenReturn(span); when(span.context()).thenReturn(context); }
@Test public void spanStoreListenerNull() { Proxy proxyListener = new Proxy(); when(httpExchange.getEventListener()).thenReturn(null); when(runtimeLinker.createProxy(eq(JettyEventListenerProxy.class), Mockito.<JettyEventListenerProxy> any(), Mockito.<ClassLoader> any())).thenReturn(proxyListener); AsyncClientRequestAdapter<TextMap> adapter = sensor.getAsyncClientRequestAdapter(object, new Object[] { httpExchange }, rsc); adapter.getSpanStoreAdapter().setSpanStore(spanStore); verify(httpExchange).setEventListener(proxyListener); ArgumentCaptor<JettyEventListenerProxy> proxyCaptor = ArgumentCaptor.forClass(JettyEventListenerProxy.class); verify(runtimeLinker).createProxy(eq(JettyEventListenerProxy.class), proxyCaptor.capture(), eq(httpExchange.getClass().getClassLoader())); assertThat(proxyCaptor.getValue().getOriginalListener(), is(nullValue())); assertThat(proxyCaptor.getValue().getSpanStore(), is(spanStore)); verifyNoMoreInteractions(runtimeLinker); verifyZeroInteractions(object, rsc); }
@Test public void spanStore() { Object listener = new Object(); Proxy proxyListener = new Proxy(); when(httpExchange.getEventListener()).thenReturn(listener); when(runtimeLinker.createProxy(eq(JettyEventListenerProxy.class), Mockito.<JettyEventListenerProxy> any(), Mockito.<ClassLoader> any())).thenReturn(proxyListener); AsyncClientRequestAdapter<TextMap> adapter = sensor.getAsyncClientRequestAdapter(object, new Object[] { httpExchange }, rsc); adapter.getSpanStoreAdapter().setSpanStore(spanStore); verify(httpExchange).setEventListener(proxyListener); ArgumentCaptor<JettyEventListenerProxy> proxyCaptor = ArgumentCaptor.forClass(JettyEventListenerProxy.class); verify(runtimeLinker).createProxy(eq(JettyEventListenerProxy.class), proxyCaptor.capture(), eq(httpExchange.getClass().getClassLoader())); assertThat(proxyCaptor.getValue().getOriginalListener(), is(listener)); assertThat(proxyCaptor.getValue().getSpanStore(), is(spanStore)); verifyNoMoreInteractions(runtimeLinker); verifyZeroInteractions(object, rsc); }
/** * Handles the {@link ClientRequestAdapter}. This method should be called when new client * request is created. * * @param <C> * type of carrier adapter is providing * @param requestAdapter * {@link ClientRequestAdapter} providing necessary information. * @return Created span */ public <C> SpanImpl handleAsyncRequest(AsyncClientRequestAdapter<C> requestAdapter) { SpanBuilderImpl builder = handleRequestInternal(requestAdapter); // nothing to do if builder was not created if (null == builder) { return null; } // just build the span and store it for later start SpanImpl span = builder.build(); SpanStore spanStore = new SpanStore(); spanStore.storeSpan(span); requestAdapter.getSpanStoreAdapter().setSpanStore(spanStore); // inject here as the context is created when span is started tracer.inject(span.context(), requestAdapter.getFormat(), requestAdapter.getCarrier()); return span; }