@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 failureCallbackWithTracing_pair_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingInfo(); // when FailureCallback result = failureCallbackWithTracing(failureCallbackMock, setupInfo); // then verifyFailureCallbackWithTracing(result, failureCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }
@Test public void failureCallbackWithTracing_using_current_thread_info_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = setupCurrentThreadWithTracingInfo(); // when FailureCallback result = failureCallbackWithTracing(failureCallbackMock); // then verifyFailureCallbackWithTracing(result, failureCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }
@Test public void failureCallbackWithTracing_separate_args_works_as_expected() { // given Pair<Deque<Span>, Map<String, String>> setupInfo = generateTracingInfo(); // when FailureCallback result = failureCallbackWithTracing( failureCallbackMock, setupInfo.getLeft(), setupInfo.getRight() ); // then verifyFailureCallbackWithTracing(result, failureCallbackMock, setupInfo.getLeft(), setupInfo.getRight()); }