Search in sources :

Example 31 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class ChannelPipelineFinalizerHandlerTest method setupTracingForChannelInactive.

private Span setupTracingForChannelInactive(boolean traceCompletedOrScheduled) {
    state.setTraceCompletedOrScheduled(traceCompletedOrScheduled);
    Span span = Span.newBuilder("fooSpan", Span.SpanPurpose.SERVER).build();
    Assertions.assertThat(span.isCompleted()).isFalse();
    Deque<Span> spanStack = new LinkedList<>();
    spanStack.add(span);
    state.setDistributedTraceStack(spanStack);
    return span;
}
Also used : Span(com.nike.wingtips.Span) LinkedList(java.util.LinkedList)

Example 32 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class DTraceEndHandlerTest method endDtrace_completes_the_trace_immediately_if_state_is_not_null_but_isResponseSendingLastChunkSent_returns_false.

@Test
public void endDtrace_completes_the_trace_immediately_if_state_is_not_null_but_isResponseSendingLastChunkSent_returns_false() {
    // given
    assertThat(state.isTraceCompletedOrScheduled(), is(false));
    state.setResponseWriterFinalChunkChannelFuture(null);
    assertThat(state.isResponseSendingLastChunkSent(), is(false));
    assertThat(state.getDistributedTraceStack(), nullValue());
    Pair<Deque<Span>, Map<String, String>> expectedDtraceInfo = setupStateWithNewSpan("blahTrace");
    assertThat(state.getDistributedTraceStack(), notNullValue());
    assertThat(state.getDistributedTraceStack(), is(expectedDtraceInfo.getLeft()));
    assertThat(state.getDistributedTraceStack().size(), is(1));
    Span expectedSpan = expectedDtraceInfo.getLeft().peek();
    // when
    handlerSpy.endDtrace(ctxMock);
    // then
    verify(handlerSpy).completeCurrentSpan();
    assertThat(currentSpanWhenCompleteCurrentSpanWasCalled, is(expectedSpan));
    assertThat(currentSpanAfterCompleteCurrentSpanWasCalled, nullValue());
    assertThat(state.isTraceCompletedOrScheduled(), is(true));
}
Also used : Deque(java.util.Deque) Map(java.util.Map) Span(com.nike.wingtips.Span) Test(org.junit.Test)

Example 33 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class DTraceStartHandlerTest method startTrace_creates_trace_from_parent_if_available.

@Test
public void startTrace_creates_trace_from_parent_if_available() {
    // given
    String parentTraceId = UUID.randomUUID().toString();
    String parentParentSpanId = UUID.randomUUID().toString();
    String parentSpanId = UUID.randomUUID().toString();
    String parentSpanName = UUID.randomUUID().toString();
    String parentTraceEnabled = "true";
    String parentUserId = UUID.randomUUID().toString();
    httpRequest.headers().set(TraceHeaders.TRACE_ID, parentTraceId);
    httpRequest.headers().set(TraceHeaders.PARENT_SPAN_ID, parentParentSpanId);
    httpRequest.headers().set(TraceHeaders.SPAN_ID, parentSpanId);
    httpRequest.headers().set(TraceHeaders.SPAN_NAME, parentSpanName);
    httpRequest.headers().set(TraceHeaders.TRACE_SAMPLED, parentTraceEnabled);
    httpRequest.headers().set(USER_ID_HEADER_KEY, parentUserId);
    String expectedSpanName = handler.getSpanName(httpRequest);
    assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
    // when
    handler.startTrace(httpRequest);
    // then
    Span span = Tracer.getInstance().getCurrentSpan();
    assertThat(span.getTraceId(), is(parentTraceId));
    assertThat(span.getParentSpanId(), is(parentSpanId));
    assertThat(span.getSpanId(), notNullValue());
    assertThat(span.getSpanId(), not(parentSpanId));
    assertThat(span.getSpanName(), is(expectedSpanName));
    assertThat(span.getUserId(), is(parentUserId));
    assertThat(span.isSampleable(), is(Boolean.valueOf(parentTraceEnabled)));
}
Also used : Span(com.nike.wingtips.Span) Test(org.junit.Test)

Example 34 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class DTraceStartHandlerTest method startTrace_creates_new_trace_if_no_parent_available.

@Test
public void startTrace_creates_new_trace_if_no_parent_available() {
    // given
    String expectedSpanName = handler.getSpanName(httpRequest);
    assertThat(Tracer.getInstance().getCurrentSpan(), nullValue());
    // when
    handler.startTrace(httpRequest);
    // then
    Span span = Tracer.getInstance().getCurrentSpan();
    assertThat(span.getTraceId(), notNullValue());
    assertThat(span.getParentSpanId(), nullValue());
    assertThat(span.getSpanId(), notNullValue());
    assertThat(span.getSpanName(), is(expectedSpanName));
    assertThat(span.getUserId(), nullValue());
}
Also used : Span(com.nike.wingtips.Span) Test(org.junit.Test)

Example 35 with Span

use of com.nike.wingtips.Span in project riposte by Nike-Inc.

the class AsyncCompletionHandlerWithTracingAndMdcSupportTest method constructor_sets_values_exactly_as_given_when_subtracing_is_off.

@Test
public void constructor_sets_values_exactly_as_given_when_subtracing_is_off() {
    // given
    CompletableFuture cfResponse = mock(CompletableFuture.class);
    AsyncResponseHandler responseHandlerFunc = mock(AsyncResponseHandler.class);
    String method = "notused-method";
    String url = "notused-url";
    Optional<CircuitBreaker<Response>> circuitBreaker = Optional.of(mock(CircuitBreaker.class));
    Deque<Span> spanStack = mock(Deque.class);
    Map<String, String> mdcInfo = mock(Map.class);
    Deque<Span> spanStackBeforeCall = Tracer.getInstance().getCurrentSpanStackCopy();
    Map<String, String> mdcInfoBeforeCall = MDC.getCopyOfContextMap();
    // when
    AsyncCompletionHandlerWithTracingAndMdcSupport instance = new AsyncCompletionHandlerWithTracingAndMdcSupport(cfResponse, responseHandlerFunc, false, method, url, circuitBreaker, spanStack, mdcInfo);
    // then
    assertThat(instance.completableFutureResponse).isSameAs(cfResponse);
    assertThat(instance.responseHandlerFunction).isSameAs(responseHandlerFunc);
    assertThat(instance.performSubSpanAroundDownstreamCalls).isEqualTo(false);
    assertThat(instance.circuitBreakerManualTask).isSameAs(circuitBreaker);
    assertThat(instance.distributedTraceStackToUse).isSameAs(spanStack);
    assertThat(instance.mdcContextToUse).isSameAs(mdcInfo);
    assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isEqualTo(spanStackBeforeCall);
    assertThat(MDC.getCopyOfContextMap()).isEqualTo(mdcInfoBeforeCall);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) CircuitBreaker(com.nike.fastbreak.CircuitBreaker) Span(com.nike.wingtips.Span) Test(org.junit.Test)

Aggregations

Span (com.nike.wingtips.Span)46 Test (org.junit.Test)38 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)21 Map (java.util.Map)14 Deque (java.util.Deque)13 Assertions.catchThrowable (org.assertj.core.api.Assertions.catchThrowable)9 CompletableFuture (java.util.concurrent.CompletableFuture)7 HashMap (java.util.HashMap)6 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)5 Tracer (com.nike.wingtips.Tracer)4 ChannelFuture (io.netty.channel.ChannelFuture)4 LinkedList (java.util.LinkedList)4 CircuitBreaker (com.nike.fastbreak.CircuitBreaker)3 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)3 RequestInfo (com.nike.riposte.server.http.RequestInfo)3 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)3 Matchers.anyString (org.mockito.Matchers.anyString)3 WrapperException (com.nike.backstopper.exception.WrapperException)2 Pair (com.nike.internal.util.Pair)2 DownstreamIdleChannelTimeoutHandler (com.nike.riposte.client.asynchttp.netty.downstreampipeline.DownstreamIdleChannelTimeoutHandler)2