use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class DefaultAsyncHttpClientHelperSpanNamingAndTaggingStrategyTest method beforeMethod.
@Before
public void beforeMethod() {
initialSpanNameFromStrategy = new AtomicReference<>("span-name-from-strategy-" + UUID.randomUUID().toString());
strategyInitialSpanNameMethodCalled = new AtomicBoolean(false);
strategyRequestTaggingMethodCalled = new AtomicBoolean(false);
strategyResponseTaggingAndFinalSpanNameMethodCalled = new AtomicBoolean(false);
strategyInitialSpanNameArgs = new AtomicReference<>(null);
strategyRequestTaggingArgs = new AtomicReference<>(null);
strategyResponseTaggingArgs = new AtomicReference<>(null);
wingtipsStrategy = new ArgCapturingHttpTagAndSpanNamingStrategy<>(initialSpanNameFromStrategy, strategyInitialSpanNameMethodCalled, strategyRequestTaggingMethodCalled, strategyResponseTaggingAndFinalSpanNameMethodCalled, strategyInitialSpanNameArgs, strategyRequestTaggingArgs, strategyResponseTaggingArgs);
wingtipsAdapterMock = mock(HttpTagAndSpanNamingAdapter.class);
impl = new DefaultAsyncHttpClientHelperSpanNamingAndTaggingStrategy(wingtipsStrategy, wingtipsAdapterMock);
requestMock = mock(RequestBuilderWrapper.class);
responseMock = mock(Response.class);
errorMock = mock(Throwable.class);
spanMock = mock(Span.class);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class AsyncCompletionHandlerWithTracingAndMdcSupportTest method onCompleted_deals_with_trace_info_as_expected.
@DataProvider(value = { "null", "false", "true" })
@Test
public void onCompleted_deals_with_trace_info_as_expected(Boolean setupForSubspan) throws Throwable {
// given
Pair<Deque<Span>, Map<String, String>> traceInfo = generateTraceInfo(setupForSubspan);
Whitebox.setInternalState(handlerSpy, "distributedTraceStackToUse", traceInfo.getLeft());
Whitebox.setInternalState(handlerSpy, "mdcContextToUse", traceInfo.getRight());
Whitebox.setInternalState(handlerSpy, "performSubSpanAroundDownstreamCalls", TRUE.equals(setupForSubspan));
Span expectedSpanBeforeCompletion = (traceInfo.getLeft() == null) ? null : traceInfo.getLeft().peek();
Span expectedSpanAfterCompletion = (setupForSubspan == null) ? null : // one there).
traceInfo.getLeft().peekLast();
Pair<ObjectHolder<Span>, ObjectHolder<Span>> actualBeforeAndAfterSpanHolders = setupBeforeAndAfterSpanCaptureForOnCompleted();
// when
handlerSpy.onCompleted(responseMock);
// then
verify(circuitBreakerManualTaskMock).handleEvent(responseMock);
verify(responseHandlerFunctionMock).handleResponse(responseMock);
assertThat(actualBeforeAndAfterSpanHolders.getLeft().objSet).isTrue();
assertThat(actualBeforeAndAfterSpanHolders.getRight().objSet).isTrue();
assertThat(actualBeforeAndAfterSpanHolders.getLeft().obj).isEqualTo(expectedSpanBeforeCompletion);
assertThat(actualBeforeAndAfterSpanHolders.getRight().obj).isEqualTo(expectedSpanAfterCompletion);
if (TRUE.equals(setupForSubspan)) {
assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isTrue();
strategyResponseTaggingArgs.get().verifyArgs(expectedSpanBeforeCompletion, handlerSpy.rbwCopyWithHttpMethodAndUrlOnly, responseMock, null, wingtipsTagAndNamingAdapterMock);
} else {
assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isFalse();
}
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class AsyncCompletionHandlerWithTracingAndMdcSupportTest method getTraceForCall_works_as_expected.
@DataProvider(value = { "NULL", "EMPTY", "HAS_EXISTING_SPAN" }, splitBy = "\\|")
@Test
public void getTraceForCall_works_as_expected(ExistingSpanStackState existingSpanStackState) {
// given
Deque<Span> spanStack;
Span expectedResult;
switch(existingSpanStackState) {
case NULL:
spanStack = null;
expectedResult = null;
break;
case EMPTY:
spanStack = new LinkedList<>();
expectedResult = null;
break;
case HAS_EXISTING_SPAN:
spanStack = handlerSpy.distributedTraceStackToUse;
assertThat(spanStack).isNotEmpty();
expectedResult = spanStack.peek();
break;
default:
throw new IllegalArgumentException("Unhandled state: " + existingSpanStackState.name());
}
Whitebox.setInternalState(handlerSpy, "distributedTraceStackToUse", spanStack);
// when
Span spanForCall = handlerSpy.getSpanForCall();
// then
assertThat(spanForCall).isEqualTo(expectedResult);
}
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);
RequestBuilderWrapper rbwMock = mock(RequestBuilderWrapper.class);
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, rbwMock, circuitBreaker, spanStack, mdcInfo, tagAndNamingStrategy);
// 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);
}
use of com.nike.wingtips.Span in project riposte by Nike-Inc.
the class AsyncCompletionHandlerWithTracingAndMdcSupportTest method onThrowable_deals_with_trace_info_as_expected.
@DataProvider(value = { "null", "false", "true" })
@Test
public void onThrowable_deals_with_trace_info_as_expected(Boolean setupForSubspan) throws Throwable {
// given
Exception ex = new Exception("kaboom");
CompletableFuture<String> cfMock = mock(CompletableFuture.class);
Whitebox.setInternalState(handlerSpy, "completableFutureResponse", cfMock);
doReturn(false).when(cfMock).isDone();
Pair<Deque<Span>, Map<String, String>> traceInfo = generateTraceInfo(setupForSubspan);
Whitebox.setInternalState(handlerSpy, "distributedTraceStackToUse", traceInfo.getLeft());
Whitebox.setInternalState(handlerSpy, "mdcContextToUse", traceInfo.getRight());
Whitebox.setInternalState(handlerSpy, "performSubSpanAroundDownstreamCalls", TRUE.equals(setupForSubspan));
Span expectedSpanBeforeCompletion = (traceInfo.getLeft() == null) ? null : traceInfo.getLeft().peek();
Span expectedSpanAfterCompletion = (setupForSubspan == null) ? null : // one there).
traceInfo.getLeft().peekLast();
Pair<ObjectHolder<Span>, ObjectHolder<Span>> actualBeforeAndAfterSpanHolders = setupBeforeAndAfterSpanCaptureForOnThrowable(cfMock);
// when
handlerSpy.onThrowable(ex);
// then
verify(circuitBreakerManualTaskMock).handleException(ex);
verify(cfMock).completeExceptionally(ex);
assertThat(actualBeforeAndAfterSpanHolders.getLeft().objSet).isTrue();
assertThat(actualBeforeAndAfterSpanHolders.getRight().objSet).isTrue();
assertThat(actualBeforeAndAfterSpanHolders.getLeft().obj).isEqualTo(expectedSpanBeforeCompletion);
assertThat(actualBeforeAndAfterSpanHolders.getRight().obj).isEqualTo(expectedSpanAfterCompletion);
if (TRUE.equals(setupForSubspan)) {
assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isTrue();
strategyResponseTaggingArgs.get().verifyArgs(expectedSpanBeforeCompletion, handlerSpy.rbwCopyWithHttpMethodAndUrlOnly, null, ex, wingtipsTagAndNamingAdapterMock);
} else {
assertThat(strategyResponseTaggingAndFinalSpanNameMethodCalled.get()).isFalse();
}
}
Aggregations