ServletRuntime { abstract void setupTracingCompletionWhenAsyncRequestCompletes( HttpServletRequest asyncRequest, HttpServletResponse asyncResponse, TracingState originalRequestTracingState, HttpTagAndSpanNamingStrategy<HttpServletRequest,HttpServletResponse> tagAndNamingStrategy, HttpTagAndSpanNamingAdapter<HttpServletRequest,HttpServletResponse> tagAndNamingAdapter );    }
@Test public void servlet2_setupTracingCompletionWhenAsyncRequestCompletes_should_throw_IllegalStateException( ) { Throwable ex = catchThrowable( () -> servlet2Runtime.setupTracingCompletionWhenAsyncRequestCompletes( requestMock, responseMock, mock(TracingState.class), mock(HttpTagAndSpanNamingStrategy.class), mock(HttpTagAndSpanNamingAdapter.class) ) ); assertThat(ex) .isInstanceOf(IllegalStateException.class) .hasMessage("This method should never be called in a pre-Servlet-3.0 environment."); }
@Test public void setupTracingCompletionWhenAsyncRequestCompletes_should_add_WingtipsRequestSpanCompletionAsyncListener( ) { AsyncContext asyncContextMock = mock(AsyncContext.class); doReturn(asyncContextMock).when(requestMock).getAsyncContext(); TracingState tracingStateMock = mock(TracingState.class); HttpTagAndSpanNamingStrategy<HttpServletRequest, HttpServletResponse> tagStrategyMock = mock(HttpTagAndSpanNamingStrategy.class); HttpTagAndSpanNamingAdapter<HttpServletRequest,HttpServletResponse> tagAdapterMock = mock(HttpTagAndSpanNamingAdapter.class); ArgumentCaptor<AsyncListener> listenerCaptor = ArgumentCaptor.forClass(AsyncListener.class); servlet3Runtime.setupTracingCompletionWhenAsyncRequestCompletes( requestMock, responseMock, tracingStateMock, tagStrategyMock, tagAdapterMock ); verify(asyncContextMock).addListener(listenerCaptor.capture(), eq(requestMock), eq(responseMock)); List<AsyncListener> addedListeners = listenerCaptor.getAllValues(); assertThat(addedListeners).hasSize(1); assertThat(addedListeners.get(0)).isInstanceOf(WingtipsRequestSpanCompletionAsyncListener.class); WingtipsRequestSpanCompletionAsyncListener listener = (WingtipsRequestSpanCompletionAsyncListener)addedListeners.get(0); assertThat(listener.originalRequestTracingState).isSameAs(tracingStateMock); assertThat(listener.tagAndNamingStrategy).isSameAs(tagStrategyMock); assertThat(listener.tagAndNamingAdapter).isSameAs(tagAdapterMock); }