@After public void afterMethod() { resetTracingAndMdc(); }
@Before public void beforeMethod() { channelMock = mock(Channel.class); ctxMock = mock(ChannelHandlerContext.class); stateAttributeMock = mock(Attribute.class); state = new HttpProcessingState(); doReturn(channelMock).when(ctxMock).channel(); doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY); doReturn(state).when(stateAttributeMock).get(); biFunctionMock = mock(BiFunction.class); inObj1 = new Object(); inObj2 = new Object(); outObj = new Object(); throwExceptionDuringCall = false; currentSpanStackWhenFunctionWasCalled = new ArrayList<>(); currentMdcInfoWhenFunctionWasCalled = new ArrayList<>(); doAnswer(invocation -> { currentSpanStackWhenFunctionWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy()); currentMdcInfoWhenFunctionWasCalled.add(MDC.getCopyOfContextMap()); if (throwExceptionDuringCall) throw new RuntimeException("kaboom"); return outObj; }).when(biFunctionMock).apply(inObj1, inObj2); resetTracingAndMdc(); }
biFunctionMock, spanStack, mdcInfo ); resetTracingAndMdc(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isEmpty();