Merge branch '3.0.x'

This commit is contained in:
spencergibb
2021-07-28 21:18:48 -04:00
4 changed files with 114 additions and 19 deletions

View File

@@ -51,7 +51,7 @@ import org.springframework.web.reactive.function.client.WebClient;
* @author Dave Syer
*/
@ConditionalOnClass(ConfigServicePropertySourceLocator.class)
@ConditionalOnProperty("spring.cloud.config.discovery.enabled")
@ConditionalOnProperty({ "spring.cloud.config.discovery.enabled", "eureka.client.enabled" })
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
public class EurekaConfigServerBootstrapConfiguration {

View File

@@ -33,6 +33,7 @@ import org.springframework.boot.SpringBootConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.context.assertj.AssertableApplicationContext;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.test.system.OutputCaptureRule;
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
@@ -53,38 +54,119 @@ import static org.mockito.Mockito.when;
*/
@RunWith(ModifiedClassPathRunner.class)
@ClassPathExclusions("spring-webflux-*")
class EurekaConfigServerBootstrapConfigurationTests {
public class EurekaConfigServerBootstrapConfigurationTests {
@Rule
public OutputCaptureRule output = new OutputCaptureRule();
@Test
void offByDefault() {
public void offByDefault() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.run(context -> {
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
assertEurekaBeansNotPresent(context);
});
}
@Test
void properBeansCreatedWhenEnabled() {
public void properBeansCreatedWhenDiscoveryEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
assertEurekaBeansNotPresent(context);
});
}
@Test
void eurekaDnsConfigurationWorks() {
public void beansNotCreatedWhenDiscoveryNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
.withPropertyValues("spring.cloud.config.discovery.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=true").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.enabled=false").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenEurekaClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("eureka.client.disabled").run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void properBeansCreatedWhenDiscoveryEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=true")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void beansNotCreatedWhenDiscoveryNotEnabled_EurekaNotEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=false", "eureka.client.enabled=false")
.run(context -> {
assertEurekaBeansNotPresent(context);
});
}
@Test
public void eurekaDnsConfigurationWorks() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"eureka.instance.hostname=eurekaclient1",
"eureka.client.use-dns-for-fetching-service-urls=true",
"eureka.client.eureka-server-d-n-s-name=myeurekahost",
@@ -95,11 +177,12 @@ class EurekaConfigServerBootstrapConfigurationTests {
}
@Test
void eurekaConfigServerInstanceProviderCalled() {
public void eurekaConfigServerInstanceProviderCalled() {
// FIXME: why do I need to do this? (fails in maven build without it.
TomcatURLStreamHandlerFactory.disable();
new SpringApplicationBuilder(TestConfigDiscoveryConfiguration.class)
.properties("spring.config.use-legacy-processing=true", "spring.cloud.config.discovery.enabled=true",
"eureka.client.enabled=true",
"spring.main.sources=" + TestConfigDiscoveryBootstrapConfiguration.class.getName(),
"logging.level.org.springframework.cloud.netflix.eureka.config=DEBUG")
.run();
@@ -107,6 +190,18 @@ class EurekaConfigServerBootstrapConfigurationTests {
.contains("eurekaConfigServerInstanceProvider found 1 instance(s) for configserver");
}
private void assertEurekaBeansPresent(AssertableApplicationContext context) {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);
assertThat(context).hasSingleBean(ConfigServerInstanceProvider.Function.class);
}
private void assertEurekaBeansNotPresent(AssertableApplicationContext context) {
assertThat(context).doesNotHaveBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(EurekaHttpClient.class);
assertThat(context).doesNotHaveBean(ConfigServerInstanceProvider.Function.class);
}
@SpringBootConfiguration
@EnableAutoConfiguration
protected static class TestConfigDiscoveryConfiguration {

View File

@@ -38,10 +38,9 @@ import static org.springframework.boot.test.context.SpringBootTest.WebEnvironmen
/**
* @author Spencer Gibb
*/
@SpringBootTest(
properties = { "spring.cloud.config.discovery.enabled=true", "spring.config.use-legacy-processing=true",
"eureka.client.webclient.enabled=true", "spring.codec.max-in-memory-size=310000" },
webEnvironment = RANDOM_PORT)
@SpringBootTest(properties = { "spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"spring.config.use-legacy-processing=true", "eureka.client.webclient.enabled=true",
"spring.codec.max-in-memory-size=310000" }, webEnvironment = RANDOM_PORT)
class EurekaConfigServerBootstrapConfigurationWebClientIntegrationTests {
@LocalServerPort

View File

@@ -36,7 +36,7 @@ class EurekaConfigServerBootstrapConfigurationWebClientTests {
void properBeansCreatedWhenEnabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true",
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true",
"eureka.client.webclient.enabled=true")
.run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
@@ -49,7 +49,8 @@ class EurekaConfigServerBootstrapConfigurationWebClientTests {
void properBeansCreatedWhenEnabledWebClientDisabled() {
new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(EurekaConfigServerBootstrapConfiguration.class))
.withPropertyValues("spring.cloud.config.discovery.enabled=true").run(context -> {
.withPropertyValues("spring.cloud.config.discovery.enabled=true", "eureka.client.enabled=true")
.run(context -> {
assertThat(context).hasSingleBean(EurekaClientConfigBean.class);
assertThat(context).doesNotHaveBean(WebClientEurekaHttpClient.class);
assertThat(context).hasSingleBean(RestTemplateEurekaHttpClient.class);