diff --git a/docs/pom.xml b/docs/pom.xml index b87d03337..f6bd27df5 100644 --- a/docs/pom.xml +++ b/docs/pom.xml @@ -18,6 +18,8 @@ .*.eureka.* deploy + + none diff --git a/scripts/runAcceptanceTests.sh b/scripts/runAcceptanceTests.sh index cbaea6bce..60186d417 100755 --- a/scripts/runAcceptanceTests.sh +++ b/scripts/runAcceptanceTests.sh @@ -4,7 +4,7 @@ set -o errexit mkdir -p target -SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/main/runAcceptanceTests.sh" +SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/3.1.x/runAcceptanceTests.sh" AT_WHAT_TO_TEST="EUREKA" cd target diff --git a/spring-cloud-netflix-dependencies/pom.xml b/spring-cloud-netflix-dependencies/pom.xml index b636556c3..c180de3f9 100644 --- a/spring-cloud-netflix-dependencies/pom.xml +++ b/spring-cloud-netflix-dependencies/pom.xml @@ -5,7 +5,7 @@ spring-cloud-dependencies-parent org.springframework.cloud - 3.1.0 + 4.0.0-SNAPSHOT spring-cloud-netflix-dependencies diff --git a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java index cee3b550d..9f94cf20e 100644 --- a/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java +++ b/spring-cloud-netflix-eureka-client/src/main/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapper.java @@ -16,6 +16,8 @@ package org.springframework.cloud.netflix.eureka.config; +import java.util.Collections; + import com.netflix.discovery.shared.transport.EurekaHttpClient; import org.springframework.boot.BootstrapRegistry; @@ -50,7 +52,7 @@ public class EurekaConfigServerBootstrapper implements BootstrapRegistryInitiali registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, context -> { Binder binder = context.get(Binder.class); if (!getDiscoveryEnabled(binder)) { - return null; + return (id) -> Collections.emptyList(); } EurekaClientConfigBean config = context.get(EurekaClientConfigBean.class); EurekaHttpClient httpClient = new RestTemplateTransportClientFactory( @@ -63,7 +65,9 @@ public class EurekaConfigServerBootstrapper implements BootstrapRegistryInitiali } private Boolean getDiscoveryEnabled(Binder binder) { - return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false); + return binder.bind(ConfigClientProperties.CONFIG_DISCOVERY_ENABLED, Boolean.class).orElse(false) + && binder.bind("eureka.client.enabled", Boolean.class).orElse(true) + && binder.bind("spring.cloud.discovery.enabled", Boolean.class).orElse(true); } } diff --git a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperTests.java b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperTests.java index bd8cebb5a..3d3cac079 100644 --- a/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperTests.java +++ b/spring-cloud-netflix-eureka-client/src/test/java/org/springframework/cloud/netflix/eureka/config/EurekaConfigServerBootstrapperTests.java @@ -22,20 +22,45 @@ import org.springframework.boot.SpringBootConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.cloud.config.client.ConfigServerInstanceProvider; +import org.springframework.web.client.ResourceAccessException; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; class EurekaConfigServerBootstrapperTests { @Test - void notEnabledDoesNotAddInstanceProviderFn() { + void notEnabledReturnsEmptyList() { new SpringApplicationBuilder(TestConfig.class) .properties("spring.cloud.service-registry.auto-registration.enabled=false") .addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> { ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext() .get(ConfigServerInstanceProvider.Function.class); - assertThat(providerFn).as("ConfigServerInstanceProvider.Function was created when it shouldn't") - .isNull(); + assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty(); + })).run().close(); + } + + @Test + public void discoveryClientNotEnabledProvidesEmptyList() { + new SpringApplicationBuilder(TestConfig.class) + .properties("spring.cloud.config.discovery.enabled=true", "spring.cloud.discovery.enabled=false", + "spring.cloud.service-registry.auto-registration.enabled=false") + .addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> { + ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext() + .get(ConfigServerInstanceProvider.Function.class); + assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty(); + })).run().close(); + } + + @Test + public void eurekaClientNotEnabledProvidesEmptyList() { + new SpringApplicationBuilder(TestConfig.class) + .properties("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false", + "spring.cloud.service-registry.auto-registration.enabled=false") + .addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> { + ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext() + .get(ConfigServerInstanceProvider.Function.class); + assertThat(providerFn.apply("id")).as("Should return empty list").isEmpty(); })).run().close(); } @@ -47,8 +72,9 @@ class EurekaConfigServerBootstrapperTests { .addBootstrapRegistryInitializer(registry -> registry.addCloseListener(event -> { ConfigServerInstanceProvider.Function providerFn = event.getBootstrapContext() .get(ConfigServerInstanceProvider.Function.class); - assertThat(providerFn).as("ConfigServerInstanceProvider.Function was not created when it should.") - .isNotNull(); + assertThatThrownBy(() -> providerFn.apply("id")).isInstanceOf(ResourceAccessException.class) + .hasMessageContaining("I/O error on GET request for \"http://localhost:8761/eureka/apps/\"") + .as("Should have tried to connect to Eureka to fetch instances."); })).run().close(); }