Adjust to changes in FW.

Signed-off-by: Olga Maciaszek-Sharma <olga.maciaszek-sharma@broadcom.com>
This commit is contained in:
Olga Maciaszek-Sharma
2025-04-24 19:43:01 +02:00
parent 9fa1b6cfc8
commit 37fa7a7ae8
13 changed files with 68 additions and 57 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -29,6 +29,7 @@ import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ClientRequest;
@@ -80,7 +81,7 @@ public class RequestData {
}
private static MultiValueMap<String, String> buildCookies(MultiValueMap<String, HttpCookie> cookies) {
HttpHeaders newCookies = new HttpHeaders();
MultiValueMap<String, String> newCookies = new LinkedMultiValueMap<>();
if (cookies != null) {
cookies.forEach((key, value) -> value
.forEach(cookie -> newCookies.put(cookie.getName(), Collections.singletonList(cookie.getValue()))));
@@ -89,7 +90,7 @@ public class RequestData {
}
private static MultiValueMap<String, String> buildCookiesFromHeaders(HttpHeaders headers) {
HttpHeaders newCookies = new HttpHeaders();
MultiValueMap<String, String> newCookies = new LinkedMultiValueMap<>();
if (headers == null) {
return newCookies;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -22,6 +22,7 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
*/
@ConfigurationProperties("spring.cloud.compatibility-verifier")
public class CompatibilityVerifierProperties {
@@ -36,7 +37,7 @@ public class CompatibilityVerifierProperties {
* the patch version if you don't want to specify a concrete value. Example:
* {@code 3.5.x}
*/
private List<String> compatibleBootVersions = List.of("3.5.x");
private List<String> compatibleBootVersions = List.of("4.0.x");
public boolean isEnabled() {
return this.enabled;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -27,7 +27,7 @@ import org.springframework.boot.SpringBootVersion;
import org.springframework.util.StringUtils;
/**
* Verifies if Spring Boot has proper version.
* Verifies if Spring Boot has the proper version.
*/
class SpringBootVersionVerifier implements CompatibilityVerifier {
@@ -35,7 +35,7 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
final Map<String, CompatibilityPredicate> ACCEPTED_VERSIONS = new HashMap<>() {
{
this.put("3.5", is3_5());
this.put("4.0", is4_0());
}
};
@@ -70,12 +70,12 @@ class SpringBootVersionVerifier implements CompatibilityVerifier {
return SpringBootVersion.getVersion();
}
CompatibilityPredicate is3_5() {
CompatibilityPredicate is4_0() {
return new CompatibilityPredicate() {
@Override
public String toString() {
return "Predicate for Boot 3.5";
return "Predicate for Boot 4.0";
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -31,6 +31,7 @@ import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFunction;
@@ -75,7 +76,7 @@ class RetryableLoadBalancerExchangeFilterFunctionTests {
when(factory.getInstance("test")).thenReturn(new TestReactiveLoadBalancer());
when(factory.getProperties(any())).thenReturn(properties);
when(clientRequest.headers()).thenReturn(new HttpHeaders());
when(clientRequest.cookies()).thenReturn(new HttpHeaders());
when(clientRequest.cookies()).thenReturn(new LinkedMultiValueMap<>());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-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.
@@ -27,6 +27,7 @@ import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Marcin Grzejszczak
* @author Olga Maciaszek-Sharma
*/
public class SpringBootDependencyTests {
@@ -176,8 +177,8 @@ public class SpringBootDependencyTests {
@Test
public void should_match_against_current_manifest() {
try {
verifyCurrentVersionFromManifest("3.5");
verifyCurrentVersionFromManifest("3.5.x");
verifyCurrentVersionFromManifest("4.0");
verifyCurrentVersionFromManifest("4.0.x");
}
catch (AssertionError e) {
// if (e.getMessage() != null && e.getMessage().contains("3.3.")) {
@@ -204,7 +205,7 @@ public class SpringBootDependencyTests {
@Test
public void should_match_against_current_predicate() {
List<String> acceptedVersions = Collections.singletonList("3.0");
List<String> acceptedVersions = Collections.singletonList("4.0");
SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) {
@Override
String getVersionFromManifest() {
@@ -212,7 +213,7 @@ public class SpringBootDependencyTests {
}
};
versionVerifier.ACCEPTED_VERSIONS.clear();
versionVerifier.ACCEPTED_VERSIONS.put("3.0", versionVerifier.is3_5());
versionVerifier.ACCEPTED_VERSIONS.put("4.0", versionVerifier.is4_0());
VerificationResult verificationResult = versionVerifier.verify();
@@ -222,7 +223,7 @@ public class SpringBootDependencyTests {
@Test
public void should_match_against_current_predicate_with_version_ending_with_x() {
List<String> acceptedVersions = Collections.singletonList("3.0.x");
List<String> acceptedVersions = Collections.singletonList("4.0.x");
SpringBootVersionVerifier versionVerifier = new SpringBootVersionVerifier(acceptedVersions) {
@Override
String getVersionFromManifest() {
@@ -230,7 +231,7 @@ public class SpringBootDependencyTests {
}
};
versionVerifier.ACCEPTED_VERSIONS.clear();
versionVerifier.ACCEPTED_VERSIONS.put("3.0", versionVerifier.is3_5());
versionVerifier.ACCEPTED_VERSIONS.put("4.0", versionVerifier.is4_0());
VerificationResult verificationResult = versionVerifier.verify();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-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.
@@ -380,9 +380,10 @@ public final class ServiceInstanceListSupplierBuilder {
return new HealthCheckServiceInstanceListSupplier(delegate, loadBalancerClientFactory,
(serviceInstance, healthCheckPath) -> webClient.get()
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build().toUri())
.exchange()
.flatMap(clientResponse -> clientResponse.releaseBody()
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode()))));
.retrieve()
.toBodilessEntity()
.map(response -> HttpStatus.OK.equals(response.getStatusCode()))
.onErrorReturn(false));
}
private ServiceInstanceListSupplier blockingHealthCheckServiceInstanceListSupplier(RestTemplate restTemplate,

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -65,9 +65,9 @@ class XForwardedHeadersTransformerTests {
HttpRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.getHeaders()).containsKey("X-Forwarded-Host");
assertThat(newRequest.getHeaders().containsHeader("X-Forwarded-Host")).isTrue();
assertThat(newRequest.getHeaders().getFirst("X-Forwarded-Host")).isEqualTo("google.com");
assertThat(newRequest.getHeaders()).containsKey("X-Forwarded-Proto");
assertThat(newRequest.getHeaders().containsHeader("X-Forwarded-Proto")).isTrue();
assertThat(newRequest.getHeaders().getFirst("X-Forwarded-Proto")).isEqualTo("https");
}
@@ -78,8 +78,8 @@ class XForwardedHeadersTransformerTests {
XForwardedHeadersTransformer transformer = new XForwardedHeadersTransformer(loadBalancerClientFactory);
HttpRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.getHeaders()).doesNotContainKey("X-Forwarded-Host");
assertThat(newRequest.getHeaders()).doesNotContainKey("X-Forwarded-Proto");
assertThat(newRequest.getHeaders().containsHeader("X-Forwarded-Host")).isFalse();
assertThat(newRequest.getHeaders().containsHeader("X-Forwarded-Proto")).isFalse();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2023 the original author or authors.
* Copyright 2012-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.
@@ -703,7 +703,7 @@ class HealthCheckServiceInstanceListSupplierTests {
}
@Test
void shouldCheckUseProvidedPortForHealthCheckRequest() {
void shouldCheckUserProvidedPortForHealthCheckRequest() {
Throwable exception = catchThrowable(() -> {
String serviceId = "ignored-service";
properties.getHealthCheck().setPort(8888);
@@ -718,7 +718,7 @@ class HealthCheckServiceInstanceListSupplierTests {
listSupplier.isAlive(serviceInstance).block();
});
assertThat(exception).hasMessageContaining("Connection refused: /127.0.0.1:888");
assertThat(exception).hasMessageContaining("Connection refused: /127.0.0.1:8888");
}
private static Stream<Arguments> healthCheckFunctions() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -74,7 +74,7 @@ class LoadBalancerServiceInstanceCookieTransformerTests {
void shouldReturnPassedRequestWhenNoServiceInstance() {
HttpRequest newRequest = transformer.transformRequest(request, null);
assertThat(newRequest.getHeaders()).doesNotContainKey(HttpHeaders.COOKIE);
assertThat(newRequest.getHeaders().containsHeader(HttpHeaders.COOKIE)).isFalse();
}
@Test
@@ -82,7 +82,7 @@ class LoadBalancerServiceInstanceCookieTransformerTests {
properties.getStickySession().setInstanceIdCookieName(null);
HttpRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.getHeaders()).doesNotContainKey(HttpHeaders.COOKIE);
assertThat(newRequest.getHeaders().containsHeader(HttpHeaders.COOKIE)).isFalse();
}
@Test
@@ -90,7 +90,7 @@ class LoadBalancerServiceInstanceCookieTransformerTests {
properties.getStickySession().setInstanceIdCookieName("");
HttpRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.getHeaders()).doesNotContainKey(HttpHeaders.COOKIE);
assertThat(newRequest.getHeaders().containsHeader(HttpHeaders.COOKIE)).isFalse();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -17,6 +17,7 @@
package org.springframework.cloud.loadbalancer.core;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
@@ -31,7 +32,8 @@ import org.springframework.cloud.client.loadbalancer.LoadBalancerProperties;
import org.springframework.cloud.client.loadbalancer.Request;
import org.springframework.cloud.client.loadbalancer.RequestData;
import org.springframework.cloud.client.loadbalancer.RequestDataContext;
import org.springframework.http.HttpHeaders;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.reactive.function.client.ClientRequest;
import static org.assertj.core.api.Assertions.assertThat;
@@ -72,8 +74,8 @@ class RequestBasedStickySessionServiceInstanceListSupplierTests {
@Test
void shouldReturnInstanceBasedOnCookieFromClientRequest() {
HttpHeaders headers = new HttpHeaders();
headers.add(properties.getStickySession().getInstanceIdCookieName(), "test-1");
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.put(properties.getStickySession().getInstanceIdCookieName(), Collections.singletonList("test-1"));
when(clientRequest.cookies()).thenReturn(headers);
Request<RequestDataContext> request = new DefaultRequest<>(
new RequestDataContext(new RequestData(clientRequest)));
@@ -86,8 +88,8 @@ class RequestBasedStickySessionServiceInstanceListSupplierTests {
@Test
void shouldReturnAllDelegateInstancesIfInstanceBasedOnCookieFromClientRequestNotFound() {
HttpHeaders headers = new HttpHeaders();
headers.add(properties.getStickySession().getInstanceIdCookieName(), "test-4");
MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
headers.put(properties.getStickySession().getInstanceIdCookieName(), Collections.singletonList("test-4"));
when(clientRequest.cookies()).thenReturn(headers);
Request<RequestDataContext> request = new DefaultRequest<>(
new RequestDataContext(new RequestData(clientRequest)));
@@ -99,7 +101,7 @@ class RequestBasedStickySessionServiceInstanceListSupplierTests {
@Test
void shouldReturnAllInstancesFromDelegateIfClientRequestHasNoCookie() {
when(clientRequest.cookies()).thenReturn(new HttpHeaders());
when(clientRequest.cookies()).thenReturn(new LinkedMultiValueMap<>());
Request<RequestDataContext> request = new DefaultRequest<>(
new RequestDataContext(new RequestData(clientRequest)));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2023 the original author or authors.
* Copyright 2013-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.
@@ -26,6 +26,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.client.RestClient;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.util.UriComponentsBuilder;
import static org.springframework.cloud.loadbalancer.core.ServiceInstanceListSupplierBuilder.getUri;
@@ -46,9 +47,10 @@ final class ServiceInstanceListSuppliersTestUtils {
static BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunction(WebClient webClient) {
return (serviceInstance, healthCheckPath) -> webClient.get()
.uri(UriComponentsBuilder.fromUriString(getUri(serviceInstance, healthCheckPath)).build().toUri())
.exchange()
.flatMap(clientResponse -> clientResponse.releaseBody()
.thenReturn(HttpStatus.OK.equals(clientResponse.statusCode())));
.retrieve()
.toBodilessEntity()
.map(response -> HttpStatus.OK.equals(response.getStatusCode()))
.onErrorReturn(throwable -> !(throwable instanceof WebClientRequestException), false);
}
static BiFunction<ServiceInstance, String, Mono<Boolean>> healthCheckFunction(RestTemplate restTemplate) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-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.
@@ -66,9 +66,9 @@ class XForwardedHeadersTransformerTests {
ClientRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.headers()).containsKey("X-Forwarded-Host");
assertThat(newRequest.headers().containsHeader("X-Forwarded-Host")).isTrue();
assertThat(newRequest.headers().getFirst("X-Forwarded-Host")).isEqualTo("spring.io");
assertThat(newRequest.headers()).containsKey("X-Forwarded-Proto");
assertThat(newRequest.headers().containsHeader("X-Forwarded-Host")).isTrue();
assertThat(newRequest.headers().getFirst("X-Forwarded-Proto")).isEqualTo("https");
}
@@ -79,8 +79,8 @@ class XForwardedHeadersTransformerTests {
ClientRequest newRequest = transformer.transformRequest(request, serviceInstance);
assertThat(newRequest.headers()).doesNotContainKey("X-Forwarded-Host");
assertThat(newRequest.headers()).doesNotContainKey("X-Forwarded-Proto");
assertThat(newRequest.headers().containsHeader("X-Forwarded-Host")).isFalse();
assertThat(newRequest.headers().containsHeader("X-Forwarded-Proto")).isFalse();
}
}

View File

@@ -44,6 +44,7 @@ import org.springframework.cloud.client.loadbalancer.reactive.ReactiveLoadBalanc
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMapAdapter;
import static org.assertj.core.api.Assertions.assertThat;
@@ -71,7 +72,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
@Test
void shouldRecordSuccessfulTimedRequest() {
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test"), new HttpHeaders(),
new HttpHeaders(), new HashMap<>());
new LinkedMultiValueMap<>(), new HashMap<>());
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
@@ -93,6 +94,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
Tag.of("serviceInstance.port", "8080"), Tag.of("status", "200"), Tag.of("uri", "/test"));
}
@SuppressWarnings("unchecked")
@Test
void shouldNotAddPathValueWhenDisabled() {
ReactiveLoadBalancer.Factory<ServiceInstance> factory = mock(ReactiveLoadBalancer.Factory.class);
@@ -102,7 +104,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
MicrometerStatsLoadBalancerLifecycle statsLifecycle = new MicrometerStatsLoadBalancerLifecycle(meterRegistry,
factory);
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test"), new HttpHeaders(),
new HttpHeaders(), new HashMap<>());
new LinkedMultiValueMap<>(), new HashMap<>());
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
@@ -126,7 +128,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
String uriTemplate = "/test/{pathParam}/test";
attributes.put(attributeName, uriTemplate);
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test/123/test"),
new HttpHeaders(), new HttpHeaders(), attributes);
new HttpHeaders(), new LinkedMultiValueMap<>(), attributes);
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
@@ -152,7 +154,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
@Test
void shouldRecordFailedTimedRequest() {
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test"), new HttpHeaders(),
new HttpHeaders(), new HashMap<>());
new LinkedMultiValueMap<>(), new HashMap<>());
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new DefaultResponse(
new DefaultServiceInstance("test-1", "test", "test.org", 8080, false, new HashMap<>()));
@@ -175,7 +177,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
@Test
void shouldNotRecordDiscardedRequest() {
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test"), new HttpHeaders(),
new HttpHeaders(), new HashMap<>());
new LinkedMultiValueMap<>(), new HashMap<>());
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
Response<ServiceInstance> lbResponse = new EmptyResponse();
statsLifecycle.onStartRequest(lbRequest, lbResponse);
@@ -247,7 +249,7 @@ class MicrometerStatsLoadBalancerLifecycleTests {
@Test
void shouldHandleNullLoadBalancerResponse() {
RequestData requestData = new RequestData(HttpMethod.GET, URI.create("http://test.org/test"), new HttpHeaders(),
new HttpHeaders(), new HashMap<>());
new LinkedMultiValueMap<>(), new HashMap<>());
Request<Object> lbRequest = new DefaultRequest<>(new RequestDataContext(requestData));
assertThatCode(() -> {
statsLifecycle.onStartRequest(lbRequest, null);