@Test public void shouldSubmitEndpointWithGivenPaths() throws Exception { when(endPointSubmitter.endPointSubmitted()).thenReturn(false); when(servletRequest.getContextPath()).thenReturn(CONTEXT_PATH); when(servletRequest.getLocalAddr()).thenReturn(LOCAL_ADDR); when(servletRequest.getLocalPort()).thenReturn(LOCAL_PORT); filter.doFilter(servletRequest, servletResponse, filterChain); verify(endPointSubmitter).submit(LOCAL_ADDR, LOCAL_PORT, CONTEXT_PATH); }
@Test public void shouldNotSubmitSpanWhenSampleIsFalse() throws Exception { when(endPointSubmitter.endPointSubmitted()).thenReturn(true); when(servletRequest.getHeader(BraveHttpHeaders.Sampled.getName())) .thenReturn(String.valueOf(SAMPLED_FALSE)); filter.doFilter(servletRequest, servletResponse, filterChain); final InOrder inOrder = inOrder(endPointSubmitter, serverTracer); inOrder.verify(serverTracer).clearCurrentSpan(); inOrder.verify(endPointSubmitter).endPointSubmitted(); inOrder .verify(serverTracer, never()) .setStateCurrentTrace(anyLong(), anyLong(), anyLong(), anyString()); inOrder.verify(serverTracer).setStateNoTracing(); }
@Test public void shouldGetTraceDataFromHeaders() throws Exception { when(endPointSubmitter.endPointSubmitted()).thenReturn(true); when(servletRequest.getHeader(BraveHttpHeaders.TraceId.getName())) .thenReturn(String.valueOf(TRACE_ID)); when(servletRequest.getHeader(BraveHttpHeaders.SpanId.getName())) .thenReturn(String.valueOf(SPAN_ID)); when(servletRequest.getHeader(BraveHttpHeaders.ParentSpanId.getName())) .thenReturn(String.valueOf(PARENT_SPAN_ID)); when(servletRequest.getHeader(BraveHttpHeaders.Sampled.getName())) .thenReturn(String.valueOf(SAMPLED_TRUE)); when(servletRequest.getHeader(BraveHttpHeaders.SpanName.getName())).thenReturn(SPAN_NAME); filter.doFilter(servletRequest, servletResponse, filterChain); verify(serverTracer).setStateCurrentTrace(TRACE_ID, SPAN_ID, PARENT_SPAN_ID, SPAN_NAME); verify(servletRequest).getHeader(BraveHttpHeaders.TraceId.getName()); verify(servletRequest).getHeader(BraveHttpHeaders.SpanId.getName()); verify(servletRequest).getHeader(BraveHttpHeaders.ParentSpanId.getName()); verify(servletRequest).getHeader(BraveHttpHeaders.Sampled.getName()); verify(servletRequest).getHeader(BraveHttpHeaders.SpanName.getName()); }