@DataProvider(value = { "true", "false" }) @Test public void onSuccess_handles_tracing_and_mdc_info_as_expected(boolean throwException) { throwExceptionDuringCall = throwException; Tracer.getInstance().startRequestWithRootSpan("foo"); Deque<Span> spanStack = Tracer.getInstance().getCurrentSpanStackCopy(); Map<String, String> mdcInfo = MDC.getCopyOfContextMap(); ListenableFutureCallbackWithTracing instance = new ListenableFutureCallbackWithTracing( listenableFutureCallbackMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = catchThrowable(() -> instance.onSuccess(successInObj)); verify(listenableFutureCallbackMock).onSuccess(successInObj); if (throwException) { assertThat(ex).isNotNull(); } else { assertThat(ex).isNull(); } assertThat(currentSpanStackWhenListenableFutureCallbackWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenListenableFutureCallbackWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }
@Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origListenableFutureCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }
ListenableFutureCallbackWithTracing implements ListenableFutureCallback<T> { @Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origListenableFutureCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } }
ListenableFutureCallbackWithTracing implements ListenableFutureCallback<T> { @Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origListenableFutureCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Deque<Span> spanStackForExecution,
                                               Map<String, String> mdcContextMapForExecution); }
ListenableFutureCallbackWithTracing implements ListenableFutureCallback<T> { @Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origListenableFutureCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Deque<Span> spanStackForExecution,
                                               Map<String, String> mdcContextMapForExecution); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                                                         Deque<Span> spanStackForExecution,
                                                                         Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void onSuccess(T result); @Override @SuppressWarnings("deprecation") void onFailure(Throwable ex); }
ListenableFutureCallbackWithTracing implements ListenableFutureCallback<T> { @Override @SuppressWarnings("deprecation") public void onSuccess(T result) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origListenableFutureCallback.onSuccess(result); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  ListenableFutureCallbackWithTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                               Deque<Span> spanStackForExecution,
                                               Map<String, String> mdcContextMapForExecution); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static ListenableFutureCallbackWithTracing<T> withTracing(ListenableFutureCallback<T> origListenableFutureCallback,
                                                                         Deque<Span> spanStackForExecution,
                                                                         Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void onSuccess(T result); @Override @SuppressWarnings("deprecation") void onFailure(Throwable ex);  }