@DataProvider(value = { "true", "false" }) @Test public void onFailure_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(); FailureCallbackWithTracing instance = new FailureCallbackWithTracing( failureCallbackMock, spanStack, mdcInfo ); resetTracing(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); Throwable ex = catchThrowable(() -> instance.onFailure(inObj)); verify(failureCallbackMock).onFailure(inObj); if (throwException) { assertThat(ex).isNotNull(); } else { assertThat(ex).isNull(); } assertThat(currentSpanStackWhenFailureCallbackWasCalled.get(0)).isEqualTo(spanStack); assertThat(currentMdcInfoWhenFailureCallbackWasCalled.get(0)).isEqualTo(mdcInfo); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isNullOrEmpty(); }
@Override @SuppressWarnings("deprecation") public void onFailure(Throwable ex) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origFailureCallback.onFailure(ex); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } }
FailureCallbackWithTracing implements FailureCallback { @Override @SuppressWarnings("deprecation") public void onFailure(Throwable ex) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origFailureCallback.onFailure(ex); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } }
FailureCallbackWithTracing implements FailureCallback { @Override @SuppressWarnings("deprecation") public void onFailure(Throwable ex) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origFailureCallback.onFailure(ex); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } FailureCallbackWithTracing(FailureCallback origFailureCallback);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Deque<Span> spanStackForExecution,
                                      Map<String, String> mdcContextMapForExecution); }
FailureCallbackWithTracing implements FailureCallback { @Override @SuppressWarnings("deprecation") public void onFailure(Throwable ex) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origFailureCallback.onFailure(ex); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } FailureCallbackWithTracing(FailureCallback origFailureCallback);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Deque<Span> spanStackForExecution,
                                      Map<String, String> mdcContextMapForExecution); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback,
                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback,
                                                         Deque<Span> spanStackForExecution,
                                                         Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void onFailure(Throwable ex); }
FailureCallbackWithTracing implements FailureCallback { @Override @SuppressWarnings("deprecation") public void onFailure(Throwable ex) { TracingState originalThreadInfo = null; try { originalThreadInfo = linkTracingToCurrentThread(spanStackForExecution, mdcContextMapForExecution); origFailureCallback.onFailure(ex); } finally { unlinkTracingFromCurrentThread(originalThreadInfo); } } FailureCallbackWithTracing(FailureCallback origFailureCallback);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Pair<Deque<Span>, Map<String, String>> originalThreadInfo);  FailureCallbackWithTracing(FailureCallback origFailureCallback,
                                      Deque<Span> spanStackForExecution,
                                      Map<String, String> mdcContextMapForExecution); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback,
                                                         Pair<Deque<Span>, Map<String, String>> originalThreadInfo); static FailureCallbackWithTracing withTracing(FailureCallback origFailureCallback,
                                                         Deque<Span> spanStackForExecution,
                                                         Map<String, String> mdcContextMapForExecution); @Override @SuppressWarnings("deprecation") void onFailure(Throwable ex);  }