AsyncWingtipsHelperJava7 { @Deprecated public static TracingState linkTracingToCurrentThread( Pair<Deque<Span>, Map<String, String>> threadInfoToLink ) { Deque<Span> spanStack = (threadInfoToLink == null) ? null : threadInfoToLink.getLeft(); Map<String, String> mdcContextMap = (threadInfoToLink == null) ? null : threadInfoToLink.getRight(); return linkTracingToCurrentThread(spanStack, mdcContextMap); } protected  AsyncWingtipsHelperJava7(); @Deprecated static Runnable runnableWithTracing(Runnable runnable); @Deprecated static Runnable runnableWithTracing(Runnable runnable,
                                               Pair<Deque<Span>, Map<String, String>> threadInfoToLink); @Deprecated static Runnable runnableWithTracing(Runnable runnable,
                                               Deque<Span> spanStackToLink,
                                               Map<String, String> mdcContextMapToLink); @Deprecated static Callable<U> callableWithTracing(Callable<U> callable); @Deprecated static Callable<U> callableWithTracing(Callable<U> callable,
                                                      Pair<Deque<Span>, Map<String, String>> threadInfoToLink); @Deprecated static Callable<U> callableWithTracing(Callable<U> callable,
                                                      Deque<Span> spanStackToLink,
                                                      Map<String, String> mdcContextMapToLink); @Deprecated static ExecutorServiceWithTracing executorServiceWithTracing(ExecutorService delegate); @Deprecated static ScheduledExecutorServiceWithTracing scheduledExecutorServiceWithTracing(
        ScheduledExecutorService delegate
    ); @Deprecated static TracingState linkTracingToCurrentThread(
        Pair<Deque<Span>, Map<String, String>> threadInfoToLink
    ); @Deprecated static TracingState linkTracingToCurrentThread(
        Deque<Span> spanStackToLink,
        Map<String, String> mdcContextMapToLink
    ); @Deprecated static void unlinkTracingFromCurrentThread(
        Pair<Deque<Span>, Map<String, String>> threadInfoToResetFor
    ); @Deprecated static void unlinkTracingFromCurrentThread(Deque<Span> spanStackToResetFor,
                                                      Map<String, String> mdcContextMapToResetFor);  }
@DataProvider(value = { "true", "false" }, splitBy = "\\|") @Test public void linkTracingToCurrentThread_pair_works_as_expected(boolean useNullPair) { Pair<Deque<Span>, Map<String, String>> infoForLinking = (useNullPair) ? null : generateTracingInfo(); resetTracing(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); Pair<Deque<Span>, Map<String, String>> preCallInfo = linkTracingToCurrentThread(infoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); assertThat(preCallInfo).isEqualTo(expectedPreCallInfo); if (useNullPair) { assertThat(postCallInfo.getLeft()).isNull(); assertThat(postCallInfo.getRight()).isNullOrEmpty(); } else assertThat(postCallInfo).isEqualTo(infoForLinking); }
@Test public void linkTracingToCurrentThread_pair_works_as_expected_with_non_null_pair_and_null_innards() { Pair<Deque<Span>, Map<String, String>> infoForLinking = Pair.of(null, null); resetTracing(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); Pair<Deque<Span>, Map<String, String>> preCallInfo = linkTracingToCurrentThread(infoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); assertThat(preCallInfo).isEqualTo(expectedPreCallInfo); assertThat(postCallInfo.getLeft()).isNull(); assertThat(postCallInfo.getRight()).isNullOrEmpty(); }
@DataProvider(value = { "true | true", "false | true", "true | false", "false | false" }, splitBy = "\\|") @Test public void linkTracingToCurrentThread_separate_args_works_as_expected(boolean useNullSpanStack, boolean useNullMdcInfo) { Pair<Deque<Span>, Map<String, String>> info = generateTracingInfo(); info.getRight().put("fooMdcKey", UUID.randomUUID().toString()); Deque<Span> spanStackForLinking = (useNullSpanStack) ? null : info.getLeft(); Map<String, String> mdcInfoForLinking = (useNullMdcInfo) ? null : info.getRight(); resetTracing(); Tracer.getInstance().startRequestWithRootSpan("foo-" + UUID.randomUUID().toString()); Pair<Deque<Span>, Map<String, String>> expectedPreCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); Map<String, String> expectedMdcInfo; if (useNullMdcInfo) { if (useNullSpanStack) expectedMdcInfo = Collections.emptyMap(); else { expectedMdcInfo = new HashMap<>(); Span expectedSpan = spanStackForLinking.peek(); expectedMdcInfo.put(SpanFieldForLoggerMdc.TRACE_ID.mdcKey, expectedSpan.getTraceId()); } } else { expectedMdcInfo = new HashMap<>(mdcInfoForLinking); if (useNullSpanStack) { expectedMdcInfo.remove(SpanFieldForLoggerMdc.TRACE_ID.mdcKey); } } Pair<Deque<Span>, Map<String, String>> preCallInfo = linkTracingToCurrentThread(spanStackForLinking, mdcInfoForLinking); Pair<Deque<Span>, Map<String, String>> postCallInfo = Pair.of( Tracer.getInstance().getCurrentSpanStackCopy(), MDC.getCopyOfContextMap() ); assertThat(preCallInfo).isEqualTo(expectedPreCallInfo); assertThat(postCallInfo.getLeft()).isEqualTo(spanStackForLinking); if (expectedMdcInfo.isEmpty()) { assertThat(postCallInfo.getRight()).isNullOrEmpty(); } else { assertThat(postCallInfo.getRight()).isEqualTo(expectedMdcInfo); } }