diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 8546d0b2..c2bc6b95 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -10,6 +10,11 @@ updates: target-branch: "4.0.x" # oldest OSS supported branch schedule: interval: "weekly" + - package-ecosystem: "github-actions" + directory: "/" + target-branch: "4.1.x" + schedule: + interval: "weekly" - package-ecosystem: "github-actions" directory: "/" target-branch: "main" @@ -37,6 +42,17 @@ updates: update-types: - version-update:semver-major - version-update:semver-minor + - package-ecosystem: maven + directory: / + schedule: + interval: daily + target-branch: 4.1.x + ignore: + # only upgrade patch versions for maintenance branch + - dependency-name: "*" + update-types: + - version-update:semver-major + - version-update:semver-minor - package-ecosystem: maven directory: / schedule: diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 96e8b1d4..7979a5c5 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -5,9 +5,9 @@ name: Build on: push: - branches: [ main, 4.1.x, 4.0.x, 3.1.x ] + branches: [ main, 4.1.x ] pull_request: - branches: [ main, 4.1.x, 4.0.x, 3.1.x ] + branches: [ main, 4.1.x ] jobs: build: diff --git a/spring-cloud-commons/pom.xml b/spring-cloud-commons/pom.xml index 70f12033..b4a439fa 100644 --- a/spring-cloud-commons/pom.xml +++ b/spring-cloud-commons/pom.xml @@ -225,5 +225,11 @@ micrometer-observation-test test + + org.apache.commons + commons-lang3 + 3.16.0 + test + diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RandomLoadBalancer.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RandomLoadBalancer.java index ed97037c..67222ffa 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RandomLoadBalancer.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RandomLoadBalancer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2024 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,11 +29,13 @@ import org.springframework.cloud.client.loadbalancer.DefaultResponse; import org.springframework.cloud.client.loadbalancer.EmptyResponse; import org.springframework.cloud.client.loadbalancer.Request; import org.springframework.cloud.client.loadbalancer.Response; +import org.springframework.util.function.SingletonSupplier; /** * A random-based implementation of {@link ReactorServiceInstanceLoadBalancer}. * * @author Olga Maciaszek-Sharma + * @author Nan Chiu * @since 2.2.7 */ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer { @@ -42,7 +44,7 @@ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer { private final String serviceId; - private ObjectProvider serviceInstanceListSupplierProvider; + private final SingletonSupplier serviceInstanceListSingletonSupplier; /** * @param serviceInstanceListSupplierProvider a provider of @@ -52,14 +54,14 @@ public class RandomLoadBalancer implements ReactorServiceInstanceLoadBalancer { public RandomLoadBalancer(ObjectProvider serviceInstanceListSupplierProvider, String serviceId) { this.serviceId = serviceId; - this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider; + this.serviceInstanceListSingletonSupplier = SingletonSupplier + .of(() -> serviceInstanceListSupplierProvider.getIfAvailable(NoopServiceInstanceListSupplier::new)); } @SuppressWarnings("rawtypes") @Override public Mono> choose(Request request) { - ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider - .getIfAvailable(NoopServiceInstanceListSupplier::new); + ServiceInstanceListSupplier supplier = serviceInstanceListSingletonSupplier.obtain(); return supplier.get(request) .next() .map(serviceInstances -> processInstanceResponse(supplier, serviceInstances)); diff --git a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancer.java b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancer.java index 7bed7fe5..64805204 100644 --- a/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancer.java +++ b/spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancer.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2024 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. @@ -30,6 +30,7 @@ import org.springframework.cloud.client.loadbalancer.DefaultResponse; import org.springframework.cloud.client.loadbalancer.EmptyResponse; import org.springframework.cloud.client.loadbalancer.Request; import org.springframework.cloud.client.loadbalancer.Response; +import org.springframework.util.function.SingletonSupplier; /** * A Round-Robin-based implementation of {@link ReactorServiceInstanceLoadBalancer}. @@ -37,6 +38,7 @@ import org.springframework.cloud.client.loadbalancer.Response; * @author Spencer Gibb * @author Olga Maciaszek-Sharma * @author Zhuozhi JI + * @author Nan Chiu */ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalancer { @@ -46,7 +48,7 @@ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalance final String serviceId; - ObjectProvider serviceInstanceListSupplierProvider; + private final SingletonSupplier serviceInstanceListSingletonSupplier; /** * @param serviceInstanceListSupplierProvider a provider of @@ -67,7 +69,8 @@ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalance public RoundRobinLoadBalancer(ObjectProvider serviceInstanceListSupplierProvider, String serviceId, int seedPosition) { this.serviceId = serviceId; - this.serviceInstanceListSupplierProvider = serviceInstanceListSupplierProvider; + this.serviceInstanceListSingletonSupplier = SingletonSupplier + .of(() -> serviceInstanceListSupplierProvider.getIfAvailable(NoopServiceInstanceListSupplier::new)); this.position = new AtomicInteger(seedPosition); } @@ -77,8 +80,7 @@ public class RoundRobinLoadBalancer implements ReactorServiceInstanceLoadBalance // https://github.com/Netflix/ocelli/blob/master/ocelli-core/ // src/main/java/netflix/ocelli/loadbalancer/RoundRobinLoadBalancer.java public Mono> choose(Request request) { - ServiceInstanceListSupplier supplier = serviceInstanceListSupplierProvider - .getIfAvailable(NoopServiceInstanceListSupplier::new); + ServiceInstanceListSupplier supplier = serviceInstanceListSingletonSupplier.obtain(); return supplier.get(request) .next() .map(serviceInstances -> processInstanceResponse(supplier, serviceInstances)); diff --git a/spring-cloud-test-support/pom.xml b/spring-cloud-test-support/pom.xml index 39dbd6c4..c4a6f3b2 100644 --- a/spring-cloud-test-support/pom.xml +++ b/spring-cloud-test-support/pom.xml @@ -15,8 +15,8 @@ spring-cloud-test-support Spring Cloud Test Support - 3.9.5 - 1.9.16 + 3.9.9 + 1.9.22