@GetMapping(path = NESTED_ASYNC_CALL_PATH) @SuppressWarnings("unused") public DeferredResult<EndpointSpanInfoDto> getNestedAsyncCall() { DeferredResult<EndpointSpanInfoDto> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { try { logger.info("Nested async call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar" ); logger.info("...Calling: " + nestedCallUri.toString()); ListenableFuture<ResponseEntity<EndpointSpanInfoDto>> asyncRestTemplateResultFuture = wingtipsEnabledAsyncRestTemplate.exchange( nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class ); asyncRestTemplateResultFuture.addCallback( successCallbackWithTracing(result -> { logger.info("AsyncRestTemplate call complete"); asyncResponse.setResult(result.getBody()); }), failureCallbackWithTracing(asyncResponse::setErrorResult) ); } catch(Throwable t) { asyncResponse.setErrorResult(t); } })); return asyncResponse; }
@GetMapping(path = NESTED_ASYNC_CALL_PATH) @SuppressWarnings("unused") public DeferredResult<EndpointSpanInfoDto> getNestedAsyncCall() { DeferredResult<EndpointSpanInfoDto> asyncResponse = new DeferredResult<>(); executor.execute(runnableWithTracing(() -> { try { logger.info("Nested async call endpoint hit. Sleeping..."); sleepThread(SLEEP_TIME_MILLIS); URI nestedCallUri = URI.create( "http://localhost:" + serverPort + SPAN_INFO_CALL_PATH + "?someQuery=foobar" ); logger.info("...Calling: " + nestedCallUri.toString()); ListenableFuture<ResponseEntity<EndpointSpanInfoDto>> asyncRestTemplateResultFuture = wingtipsEnabledAsyncRestTemplate.exchange( nestedCallUri, HttpMethod.GET, getHttpEntityWithUserIdHeader(), EndpointSpanInfoDto.class ); asyncRestTemplateResultFuture.addCallback( successCallbackWithTracing(result -> { logger.info("AsyncRestTemplate call complete"); asyncResponse.setResult(result.getBody()); }), failureCallbackWithTracing(asyncResponse::setErrorResult) ); } catch(Throwable t) { asyncResponse.setErrorResult(t); } })); return asyncResponse; }
@Test public void successCallbackWithTracing_using_current_thread_info_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = setupCurrentThreadWithTracingInfo(); // when SuccessCallback result = successCallbackWithTracing(successCallbackMock); // then verifySuccessCallbackWithTracing(result, successCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }
@Test public void successCallbackWithTracing_pair_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingInfo(); // when SuccessCallback result = successCallbackWithTracing(successCallbackMock, setupInfo); // then verifySuccessCallbackWithTracing(result, successCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }
@Test public void successCallbackWithTracing_separate_args_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingInfo(); // when SuccessCallback result = successCallbackWithTracing( successCallbackMock, setupInfo.getLeft(), setupInfo.getRight() ); // then verifySuccessCallbackWithTracing(result, successCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }