@DataProvider(value = { "spanNameFromStrategy | PATCH | spanNameFromStrategy", "null | PATCH | asyncresttemplate_downstream_call-PATCH", " | PATCH | asyncresttemplate_downstream_call-PATCH", "[whitespace] | PATCH | asyncresttemplate_downstream_call-PATCH", "null | null | asyncresttemplate_downstream_call-UNKNOWN_HTTP_METHOD", }, splitBy = "\\|") @Test public void getSubspanSpanName_works_as_expected( String strategyResult, HttpMethod httpMethod, String expectedResult ) { // given if ("[whitespace]".equals(strategyResult)) { strategyResult = " \n\r\t "; } initialSpanNameFromStrategy.set(strategyResult); doReturn(httpMethod).when(requestMock).getMethod(); WingtipsAsyncClientHttpRequestInterceptor interceptor = new WingtipsAsyncClientHttpRequestInterceptor( true, tagAndNamingStrategy, tagAndNamingAdapterMock ); // when String result = interceptor.getSubspanSpanName(requestMock, tagAndNamingStrategy, tagAndNamingAdapterMock); // then assertThat(result).isEqualTo(expectedResult); }
@Test public void createAsyncSubSpanAndExecute_trigger_null_subspanFinisher_in_catch_block_branch_for_code_coverage() { // given Tracer.getInstance().startRequestWithRootSpan("someRootSpan"); TracingState tracingStateBeforeInterceptorCall = TracingState.getCurrentThreadTracingState(); WingtipsAsyncClientHttpRequestInterceptor interceptorSpy = spy(new WingtipsAsyncClientHttpRequestInterceptor( true, tagAndNamingStrategy, tagAndNamingAdapterMock )); RuntimeException explodingSubspanNameMethodEx = new RuntimeException("Intentional exception thrown by getSubspanSpanName()"); doThrow(explodingSubspanNameMethodEx).when(interceptorSpy).getSubspanSpanName( any(HttpRequest.class), any(HttpTagAndSpanNamingStrategy.class), any(HttpTagAndSpanNamingAdapter.class) ); HttpRequestWrapperWithModifiableHeaders wrapperRequest = new HttpRequestWrapperWithModifiableHeaders(requestMock); byte[] body = new byte[]{42}; // when Throwable ex = catchThrowable( () -> interceptorSpy.createAsyncSubSpanAndExecute(wrapperRequest, body, executionMock) ); // then assertThat(ex).isSameAs(explodingSubspanNameMethodEx); verify(interceptorSpy).getSubspanSpanName(wrapperRequest, tagAndNamingStrategy, tagAndNamingAdapterMock); // TracingState should have been reset even though an exception occurred in some unexpected place. assertThat(normalizeTracingState(TracingState.getCurrentThreadTracingState())) .isEqualTo(normalizeTracingState(tracingStateBeforeInterceptorCall)); }
getSubspanSpanName(wrapperRequest, tagAndNamingStrategy, tagAndNamingAdapter), Span.SpanPurpose.CLIENT );
getSubspanSpanName(wrapperRequest, tagAndNamingStrategy, tagAndNamingAdapter), Span.SpanPurpose.CLIENT );