Browse Source

Merge branch 'main' of github.com:spring-cloud/spring-cloud-commons

pull/1255/head
Ryan Baxter 2 years ago
parent
commit
8fbf183015
  1. 2
      docs/pom.xml
  2. 4
      docs/src/main/asciidoc/spring-cloud-commons.adoc
  3. 4
      pom.xml
  4. 4
      spring-cloud-commons-dependencies/pom.xml
  5. 2
      spring-cloud-commons/pom.xml
  6. 12
      spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClient.java
  7. 101
      spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientUnitTests.java
  8. 2
      spring-cloud-context-integration-tests/pom.xml
  9. 2
      spring-cloud-context-webflux-integration-tests/pom.xml
  10. 2
      spring-cloud-context/pom.xml
  11. 2
      spring-cloud-loadbalancer/pom.xml
  12. 13
      spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/DelegatingServiceInstanceListSupplier.java
  13. 4
      spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/SameInstancePreferenceServiceInstanceListSupplier.java
  14. 16
      spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/RetryAwareServiceInstanceListSupplierTests.java
  15. 17
      spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancerTests.java
  16. 16
      spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/SameInstancePreferenceServiceInstanceListSupplierTests.java
  17. 28
      spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/TestSelectedServiceInstanceSupplier.java
  18. 11
      spring-cloud-loadbalancer/src/test/resources/logback-test.xml
  19. 2
      spring-cloud-starter-bootstrap/pom.xml
  20. 2
      spring-cloud-starter-loadbalancer/pom.xml
  21. 2
      spring-cloud-starter/pom.xml
  22. 2
      spring-cloud-test-support/pom.xml

2
docs/pom.xml

@ -8,7 +8,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
</parent> </parent>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>Spring Cloud Commons Docs</name> <name>Spring Cloud Commons Docs</name>

4
docs/src/main/asciidoc/spring-cloud-commons.adoc

@ -248,6 +248,10 @@ For a Spring Boot Actuator application, some additional management endpoints are
* `/actuator/restart` to close the `ApplicationContext` and restart it (disabled by default). * `/actuator/restart` to close the `ApplicationContext` and restart it (disabled by default).
* `/actuator/pause` and `/actuator/resume` for calling the `Lifecycle` methods (`stop()` and `start()` on the `ApplicationContext`). * `/actuator/pause` and `/actuator/resume` for calling the `Lifecycle` methods (`stop()` and `start()` on the `ApplicationContext`).
NOTE: While enabling the `POST` method for `/actuator/env` endpoint can provide flexibility and convenience in managing your application environment variables,
it's critical to ensure that the endpoint is secured and monitored to prevent potential security risks.
Add a `spring-boot-starter-security` dependency to configure access control for the actuator’s endpoint.
NOTE: If you disable the `/actuator/restart` endpoint then the `/actuator/pause` and `/actuator/resume` endpoints NOTE: If you disable the `/actuator/restart` endpoint then the `/actuator/pause` and `/actuator/resume` endpoints
will also be disabled since they are just a special case of `/actuator/restart`. will also be disabled since they are just a special case of `/actuator/restart`.

4
pom.xml

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>Spring Cloud Commons Parent</name> <name>Spring Cloud Commons Parent</name>
<description>Spring Cloud Commons Parent</description> <description>Spring Cloud Commons Parent</description>
@ -13,7 +13,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-build</artifactId> <artifactId>spring-cloud-build</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath/> <!-- lookup parent from repository --> <relativePath/> <!-- lookup parent from repository -->
</parent> </parent>
<scm> <scm>

4
spring-cloud-commons-dependencies/pom.xml

@ -6,11 +6,11 @@
<parent> <parent>
<artifactId>spring-cloud-dependencies-parent</artifactId> <artifactId>spring-cloud-dependencies-parent</artifactId>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath/> <relativePath/>
</parent> </parent>
<artifactId>spring-cloud-commons-dependencies</artifactId> <artifactId>spring-cloud-commons-dependencies</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<name>spring-cloud-commons-dependencies</name> <name>spring-cloud-commons-dependencies</name>
<description>Spring Cloud Commons Dependencies</description> <description>Spring Cloud Commons Dependencies</description>

2
spring-cloud-commons/pom.xml

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-commons</artifactId> <artifactId>spring-cloud-commons</artifactId>

12
spring-cloud-commons/src/main/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClient.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -31,6 +31,7 @@ import org.springframework.core.annotation.AnnotationAwareOrderComparator;
* *
* @author Biju Kunjummen * @author Biju Kunjummen
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author Sean Ruffatti
*/ */
public class CompositeDiscoveryClient implements DiscoveryClient { public class CompositeDiscoveryClient implements DiscoveryClient {
@ -73,6 +74,15 @@ public class CompositeDiscoveryClient implements DiscoveryClient {
return new ArrayList<>(services); return new ArrayList<>(services);
} }
@Override
public void probe() {
if (this.discoveryClients != null) {
for (DiscoveryClient discoveryClient : this.discoveryClients) {
discoveryClient.probe();
}
}
}
public List<DiscoveryClient> getDiscoveryClients() { public List<DiscoveryClient> getDiscoveryClients() {
return this.discoveryClients; return this.discoveryClients;
} }

101
spring-cloud-commons/src/test/java/org/springframework/cloud/client/discovery/composite/CompositeDiscoveryClientUnitTests.java

@ -0,0 +1,101 @@
/*
* Copyright 2012-2023 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.client.discovery.composite;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import static org.assertj.core.api.BDDAssertions.then;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Mockito tests for Composite Discovery Client
*
* @author Sean Ruffatti
*/
@ExtendWith(MockitoExtension.class)
public class CompositeDiscoveryClientUnitTests {
private CompositeDiscoveryClient underTest;
@Mock
private DiscoveryClient client1;
@Mock
private DiscoveryClient client2;
@BeforeEach
void setUp() {
underTest = new CompositeDiscoveryClient(Arrays.asList(client1, client2));
}
@Test
void shouldRetrieveInstancesByServiceId() {
ServiceInstance serviceInstance1 = new DefaultServiceInstance("instance1", "serviceId", "https://s1", 8443,
true);
when(client1.getInstances("serviceId")).thenReturn(Collections.singletonList(serviceInstance1));
List<ServiceInstance> serviceInstances = underTest.getInstances("serviceId");
then(serviceInstances.get(0).getInstanceId()).isEqualTo("instance1");
then(serviceInstances.get(0).getServiceId()).isEqualTo("serviceId");
then(serviceInstances.get(0).getHost()).isEqualTo("https://s1");
then(serviceInstances.get(0).getPort()).isEqualTo(8443);
}
@Test
void shouldReturnServiceIds() {
when(client1.getServices()).thenReturn(Collections.singletonList("serviceId1"));
when(client2.getServices()).thenReturn(Collections.singletonList("serviceId2"));
List<String> services = underTest.getServices();
then(services.size()).isEqualTo(2);
then(services).containsOnlyOnce("serviceId1", "serviceId2");
}
@Test
void shouldReturnAllDiscoveryClients() {
then(underTest.getDiscoveryClients()).containsOnlyOnce(client1, client2);
}
@Test
void shouldCallProbeOnAllDiscoveryClients() {
underTest.probe();
// Every DiscoveryClient bean should invoke DiscoveryClient.probe() when
// CompositeDiscoveryClient.probe() is invoked.
verify(client1, times(1)).probe();
verify(client1, times(0)).getServices();
verify(client2, times(1)).probe();
verify(client2, times(0)).getServices();
}
}

2
spring-cloud-context-integration-tests/pom.xml

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-context-integration-tests</artifactId> <artifactId>spring-cloud-context-integration-tests</artifactId>

2
spring-cloud-context-webflux-integration-tests/pom.xml

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-context-webflux-integration-tests</artifactId> <artifactId>spring-cloud-context-webflux-integration-tests</artifactId>

2
spring-cloud-context/pom.xml

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-context</artifactId> <artifactId>spring-cloud-context</artifactId>

2
spring-cloud-loadbalancer/pom.xml

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-loadbalancer</artifactId> <artifactId>spring-cloud-loadbalancer</artifactId>

13
spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/DelegatingServiceInstanceListSupplier.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2019 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -18,6 +18,7 @@ package org.springframework.cloud.loadbalancer.core;
import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.util.Assert; import org.springframework.util.Assert;
/** /**
@ -26,9 +27,10 @@ import org.springframework.util.Assert;
* *
* @author Spencer Gibb * @author Spencer Gibb
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author Jürgen Kreitler
*/ */
public abstract class DelegatingServiceInstanceListSupplier public abstract class DelegatingServiceInstanceListSupplier
implements ServiceInstanceListSupplier, InitializingBean, DisposableBean { implements ServiceInstanceListSupplier, SelectedInstanceCallback, InitializingBean, DisposableBean {
protected final ServiceInstanceListSupplier delegate; protected final ServiceInstanceListSupplier delegate;
@ -46,6 +48,13 @@ public abstract class DelegatingServiceInstanceListSupplier
return this.delegate.getServiceId(); return this.delegate.getServiceId();
} }
@Override
public void selectedServiceInstance(ServiceInstance serviceInstance) {
if (delegate instanceof SelectedInstanceCallback selectedInstanceCallbackDelegate) {
selectedInstanceCallbackDelegate.selectedServiceInstance(serviceInstance);
}
}
@Override @Override
public void afterPropertiesSet() throws Exception { public void afterPropertiesSet() throws Exception {
if (delegate instanceof InitializingBean) { if (delegate instanceof InitializingBean) {

4
spring-cloud-loadbalancer/src/main/java/org/springframework/cloud/loadbalancer/core/SameInstancePreferenceServiceInstanceListSupplier.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,6 +30,7 @@ import org.springframework.cloud.client.ServiceInstance;
* chosen instance if it's available. * chosen instance if it's available.
* *
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author Jürgen Kreitler
* @since 2.2.7 * @since 2.2.7
*/ */
public class SameInstancePreferenceServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier public class SameInstancePreferenceServiceInstanceListSupplier extends DelegatingServiceInstanceListSupplier
@ -72,6 +73,7 @@ public class SameInstancePreferenceServiceInstanceListSupplier extends Delegatin
@Override @Override
public void selectedServiceInstance(ServiceInstance serviceInstance) { public void selectedServiceInstance(ServiceInstance serviceInstance) {
super.selectedServiceInstance(serviceInstance);
if (previouslyReturnedInstance == null || !previouslyReturnedInstance.equals(serviceInstance)) { if (previouslyReturnedInstance == null || !previouslyReturnedInstance.equals(serviceInstance)) {
previouslyReturnedInstance = serviceInstance; previouslyReturnedInstance = serviceInstance;
} }

16
spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/RetryAwareServiceInstanceListSupplierTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -27,11 +27,16 @@ import org.springframework.cloud.client.loadbalancer.RetryableRequestContext;
import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers; import org.springframework.cloud.loadbalancer.support.ServiceInstanceListSuppliers;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/** /**
* Tests for {@link RetryAwareServiceInstanceListSupplier}. * Tests for {@link RetryAwareServiceInstanceListSupplier}.
* *
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author Jürgen Kreitler
*/ */
class RetryAwareServiceInstanceListSupplierTests { class RetryAwareServiceInstanceListSupplierTests {
@ -78,4 +83,13 @@ class RetryAwareServiceInstanceListSupplierTests {
assertThat(returnedInstances).containsExactly(firstInstance); assertThat(returnedInstances).containsExactly(firstInstance);
} }
@Test
void shouldCallSelectedServiceInstanceOnItsDelegate() {
ServiceInstance firstInstance = instance(serviceId, "1host", false);
TestSelectedServiceInstanceSupplier delegate = mock(TestSelectedServiceInstanceSupplier.class);
DelegatingServiceInstanceListSupplier supplier = new RetryAwareServiceInstanceListSupplier(delegate);
supplier.selectedServiceInstance(firstInstance);
verify(delegate, times(1)).selectedServiceInstance(any(ServiceInstance.class));
}
} }

17
spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/RoundRobinLoadBalancerTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2022 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -32,10 +32,13 @@ import static java.lang.Integer.MIN_VALUE;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* @author Zhuozhi JI * @author Zhuozhi JI
* @author Jürgen Kreitler
*/ */
class RoundRobinLoadBalancerTests { class RoundRobinLoadBalancerTests {
@ -68,6 +71,18 @@ class RoundRobinLoadBalancerTests {
assertThat(loadBalancer.position).hasValue(0); assertThat(loadBalancer.position).hasValue(0);
} }
@Test
void shouldCallSelectedServiceInstanceIfSupplierOrItsDelegateIsInstanceOf() {
TestSelectedServiceInstanceSupplier delegate = mock(TestSelectedServiceInstanceSupplier.class);
DelegatingServiceInstanceListSupplier supplier = new RetryAwareServiceInstanceListSupplier(delegate);
when(delegate.get(any())).thenReturn(Flux.just(Collections.singletonList(new DefaultServiceInstance())));
RoundRobinLoadBalancer loadBalancer = new RoundRobinLoadBalancer(new SimpleObjectProvider<>(supplier),
"shouldNotMovePositionIfOnlyOneInstance", 0);
loadBalancer.choose().block();
verify(delegate, times(1)).selectedServiceInstance(any(ServiceInstance.class));
}
@SuppressWarnings("all") @SuppressWarnings("all")
void assertOrderEnforced(int seed) { void assertOrderEnforced(int seed) {
List<ServiceInstance> instances = new ArrayList<>(); List<ServiceInstance> instances = new ArrayList<>();

16
spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/SameInstancePreferenceServiceInstanceListSupplierTests.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2012-2020 the original author or authors. * Copyright 2012-2023 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -26,13 +26,17 @@ import org.springframework.cloud.client.DefaultServiceInstance;
import org.springframework.cloud.client.ServiceInstance; import org.springframework.cloud.client.ServiceInstance;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
/** /**
* Tests for {@link SameInstancePreferenceServiceInstanceListSupplier}. * Tests for {@link SameInstancePreferenceServiceInstanceListSupplier}.
* *
* @author Olga Maciaszek-Sharma * @author Olga Maciaszek-Sharma
* @author Jürgen Kreitler
*/ */
class SameInstancePreferenceServiceInstanceListSupplierTests { class SameInstancePreferenceServiceInstanceListSupplierTests {
@ -78,6 +82,16 @@ class SameInstancePreferenceServiceInstanceListSupplierTests {
assertThat(instances).hasSize(2); assertThat(instances).hasSize(2);
} }
@Test
void shouldCallSelectedServiceInstanceOnItsDelegate() {
ServiceInstance firstInstance = serviceInstance("test-4");
TestSelectedServiceInstanceSupplier delegate = mock(TestSelectedServiceInstanceSupplier.class);
DelegatingServiceInstanceListSupplier supplier = new SameInstancePreferenceServiceInstanceListSupplier(
delegate);
supplier.selectedServiceInstance(firstInstance);
verify(delegate, times(1)).selectedServiceInstance(any(ServiceInstance.class));
}
private DefaultServiceInstance serviceInstance(String instanceId) { private DefaultServiceInstance serviceInstance(String instanceId) {
return new DefaultServiceInstance(instanceId, "test", "http://test.test", 9080, false); return new DefaultServiceInstance(instanceId, "test", "http://test.test", 9080, false);
} }

28
spring-cloud-loadbalancer/src/test/java/org/springframework/cloud/loadbalancer/core/TestSelectedServiceInstanceSupplier.java

@ -0,0 +1,28 @@
/*
* Copyright 2012-2023 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.loadbalancer.core;
/**
* Test supplier interface extending {@link ServiceInstanceListSupplier} and
* {@link SelectedInstanceCallback}. Useful if you need to verify certain behavior
* happened on a mock for example.
*
* @author Jürgen Kreitler
*/
public interface TestSelectedServiceInstanceSupplier extends ServiceInstanceListSupplier, SelectedInstanceCallback {
}

11
spring-cloud-loadbalancer/src/test/resources/logback-test.xml

@ -0,0 +1,11 @@
<configuration>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>

2
spring-cloud-starter-bootstrap/pom.xml

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<packaging>jar</packaging> <packaging>jar</packaging>

2
spring-cloud-starter-loadbalancer/pom.xml

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

2
spring-cloud-starter/pom.xml

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
</parent> </parent>
<artifactId>spring-cloud-starter</artifactId> <artifactId>spring-cloud-starter</artifactId>
<name>spring-cloud-starter</name> <name>spring-cloud-starter</name>

2
spring-cloud-test-support/pom.xml

@ -7,7 +7,7 @@
<parent> <parent>
<groupId>org.springframework.cloud</groupId> <groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-commons-parent</artifactId> <artifactId>spring-cloud-commons-parent</artifactId>
<version>4.0.3-SNAPSHOT</version> <version>4.0.4-SNAPSHOT</version>
<relativePath>..</relativePath> <relativePath>..</relativePath>
</parent> </parent>
<artifactId>spring-cloud-test-support</artifactId> <artifactId>spring-cloud-test-support</artifactId>

Loading…
Cancel
Save