@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(); consumerMock = mock(Consumer.class); inObj = mock(ChannelFuture.class); throwExceptionDuringCall = false; currentSpanStackWhenChannelFutureWasCalled = new ArrayList<>(); currentMdcInfoWhenChannelFutureWasCalled = new ArrayList<>(); doAnswer(invocation -> { currentSpanStackWhenChannelFutureWasCalled.add(Tracer.getInstance().getCurrentSpanStackCopy()); currentMdcInfoWhenChannelFutureWasCalled.add(MDC.getCopyOfContextMap()); if (throwExceptionDuringCall) throw new RuntimeException("kaboom"); return null; }).when(consumerMock).accept(inObj); resetTracingAndMdc(); }
consumerMock, spanStack, mdcInfo ); resetTracingAndMdc(); assertThat(Tracer.getInstance().getCurrentSpanStackCopy()).isNull(); assertThat(MDC.getCopyOfContextMap()).isEmpty();