|
|
|
|
@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
|
|
|
|
|
/* |
|
|
|
|
* Copyright 2002-2024 the original author or authors. |
|
|
|
|
* Copyright 2002-2025 the original author or authors. |
|
|
|
|
* |
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
|
@ -91,38 +91,39 @@ class RestClientAdapterTests {
@@ -91,38 +91,39 @@ class RestClientAdapterTests {
|
|
|
|
|
|
|
|
|
|
public static Stream<Object[]> arguments() { |
|
|
|
|
return Stream.of( |
|
|
|
|
args((url, observationRegistry) -> { |
|
|
|
|
RestClient restClient = RestClient.builder().baseUrl(url).observationRegistry(observationRegistry).build(); |
|
|
|
|
createArgsForAdapter((url, or) -> { |
|
|
|
|
RestClient restClient = RestClient.builder().baseUrl(url).observationRegistry(or).build(); |
|
|
|
|
return RestClientAdapter.create(restClient); |
|
|
|
|
}), |
|
|
|
|
args((url, observationRegistry) -> { |
|
|
|
|
createArgsForAdapter((url, or) -> { |
|
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
|
restTemplate.setObservationRegistry(observationRegistry); |
|
|
|
|
restTemplate.setObservationRegistry(or); |
|
|
|
|
restTemplate.setUriTemplateHandler(new DefaultUriBuilderFactory(url)); |
|
|
|
|
return RestTemplateAdapter.create(restTemplate); |
|
|
|
|
})); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@SuppressWarnings("resource") |
|
|
|
|
private static Object[] args(BiFunction<String, TestObservationRegistry, HttpExchangeAdapter> adapterFactory) { |
|
|
|
|
private static Object[] createArgsForAdapter( |
|
|
|
|
BiFunction<String, TestObservationRegistry, HttpExchangeAdapter> adapterFactory) { |
|
|
|
|
|
|
|
|
|
MockWebServer server = new MockWebServer(); |
|
|
|
|
|
|
|
|
|
MockResponse response = new MockResponse(); |
|
|
|
|
response.setHeader("Content-Type", "text/plain").setBody("Hello Spring!"); |
|
|
|
|
server.enqueue(response); |
|
|
|
|
|
|
|
|
|
TestObservationRegistry observationRegistry = TestObservationRegistry.create(); |
|
|
|
|
TestObservationRegistry registry = TestObservationRegistry.create(); |
|
|
|
|
|
|
|
|
|
HttpExchangeAdapter adapter = adapterFactory.apply(server.url("/").toString(), observationRegistry); |
|
|
|
|
HttpExchangeAdapter adapter = adapterFactory.apply(server.url("/").toString(), registry); |
|
|
|
|
Service service = HttpServiceProxyFactory.builderFor(adapter).build().createClient(Service.class); |
|
|
|
|
|
|
|
|
|
return new Object[] { server, service, observationRegistry }; |
|
|
|
|
return new Object[] { server, service, registry }; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ParameterizedAdapterTest |
|
|
|
|
void greeting( |
|
|
|
|
MockWebServer server, Service service, TestObservationRegistry observationRegistry) throws Exception { |
|
|
|
|
void greeting(MockWebServer server, Service service, TestObservationRegistry registry) throws Exception { |
|
|
|
|
|
|
|
|
|
String response = service.getGreeting(); |
|
|
|
|
|
|
|
|
|
@ -130,13 +131,12 @@ class RestClientAdapterTests {
@@ -130,13 +131,12 @@ class RestClientAdapterTests {
|
|
|
|
|
assertThat(response).isEqualTo("Hello Spring!"); |
|
|
|
|
assertThat(request.getMethod()).isEqualTo("GET"); |
|
|
|
|
assertThat(request.getPath()).isEqualTo("/greeting"); |
|
|
|
|
assertThat(observationRegistry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
assertThat(registry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
.hasLowCardinalityKeyValue("uri", "/greeting"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ParameterizedAdapterTest |
|
|
|
|
void greetingById( |
|
|
|
|
MockWebServer server, Service service, TestObservationRegistry observationRegistry) throws Exception { |
|
|
|
|
void greetingById(MockWebServer server, Service service, TestObservationRegistry registry) throws Exception { |
|
|
|
|
|
|
|
|
|
ResponseEntity<String> response = service.getGreetingById("456"); |
|
|
|
|
|
|
|
|
|
@ -145,13 +145,12 @@ class RestClientAdapterTests {
@@ -145,13 +145,12 @@ class RestClientAdapterTests {
|
|
|
|
|
assertThat(response.getBody()).isEqualTo("Hello Spring!"); |
|
|
|
|
assertThat(request.getMethod()).isEqualTo("GET"); |
|
|
|
|
assertThat(request.getPath()).isEqualTo("/greeting/456"); |
|
|
|
|
assertThat(observationRegistry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
assertThat(registry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
.hasLowCardinalityKeyValue("uri", "/greeting/{id}"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ParameterizedAdapterTest |
|
|
|
|
void greetingWithDynamicUri( |
|
|
|
|
MockWebServer server, Service service, TestObservationRegistry observationRegistry) throws Exception { |
|
|
|
|
void greetingWithDynamicUri(MockWebServer server, Service service, TestObservationRegistry registry) throws Exception { |
|
|
|
|
|
|
|
|
|
URI dynamicUri = server.url("/greeting/123").uri(); |
|
|
|
|
Optional<String> response = service.getGreetingWithDynamicUri(dynamicUri, "456"); |
|
|
|
|
@ -160,7 +159,7 @@ class RestClientAdapterTests {
@@ -160,7 +159,7 @@ class RestClientAdapterTests {
|
|
|
|
|
assertThat(response.orElse("empty")).isEqualTo("Hello Spring!"); |
|
|
|
|
assertThat(request.getMethod()).isEqualTo("GET"); |
|
|
|
|
assertThat(request.getRequestUrl().uri()).isEqualTo(dynamicUri); |
|
|
|
|
assertThat(observationRegistry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
assertThat(registry).hasObservationWithNameEqualTo("http.client.requests").that() |
|
|
|
|
.hasLowCardinalityKeyValue("uri", "none"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
@ -308,8 +307,8 @@ class RestClientAdapterTests {
@@ -308,8 +307,8 @@ class RestClientAdapterTests {
|
|
|
|
|
ResponseEntity<String> getWithUriBuilderFactory(UriBuilderFactory uriBuilderFactory); |
|
|
|
|
|
|
|
|
|
@GetExchange("/greeting/{id}") |
|
|
|
|
ResponseEntity<String> getWithUriBuilderFactory(UriBuilderFactory uriBuilderFactory, |
|
|
|
|
@PathVariable String id, @RequestParam String param); |
|
|
|
|
ResponseEntity<String> getWithUriBuilderFactory( |
|
|
|
|
UriBuilderFactory uriBuilderFactory, @PathVariable String id, @RequestParam String param); |
|
|
|
|
|
|
|
|
|
@GetExchange("/greeting") |
|
|
|
|
ResponseEntity<String> getWithIgnoredUriBuilderFactory(URI uri, UriBuilderFactory uriBuilderFactory); |
|
|
|
|
|