Merge branch '3.1.x'
This commit is contained in:
@@ -18,6 +18,8 @@
|
||||
<configprops.inclusionPattern>spring.cloud.zookeeper.*|
|
||||
</configprops.inclusionPattern>
|
||||
<upload-docs-zip.phase>deploy</upload-docs-zip.phase>
|
||||
<!-- Don't upload docs jar to central / repo.spring.io -->
|
||||
<maven-deploy-plugin-default.phase>none</maven-deploy-plugin-default.phase>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
set -o errexit
|
||||
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/master/runAcceptanceTests.sh"
|
||||
SCRIPT_URL="https://raw.githubusercontent.com/spring-cloud-samples/brewery/2021.0.x/runAcceptanceTests.sh"
|
||||
AT_WHAT_TO_TEST="ZOOKEEPER"
|
||||
|
||||
curl "${SCRIPT_URL}" --output runAcceptanceTests.sh
|
||||
|
||||
@@ -33,7 +33,10 @@ import org.springframework.cloud.zookeeper.ConditionalOnZookeeperEnabled;
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@ConditionalOnZookeeperEnabled
|
||||
@ConditionalOnProperty(value = "spring.cloud.zookeeper.discovery.enabled", matchIfMissing = true)
|
||||
@ConditionalOnProperty(value = ConditionalOnZookeeperDiscoveryEnabled.PROPERTY, matchIfMissing = true)
|
||||
public @interface ConditionalOnZookeeperDiscoveryEnabled {
|
||||
|
||||
/**
|
||||
* Property name.
|
||||
*/
|
||||
String PROPERTY = "spring.cloud.zookeeper.discovery.enabled";
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
|
||||
package org.springframework.cloud.zookeeper.discovery.configclient;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.curator.framework.CuratorFramework;
|
||||
import org.apache.curator.x.discovery.ServiceDiscovery;
|
||||
import org.apache.curator.x.discovery.ServiceDiscoveryBuilder;
|
||||
@@ -32,6 +34,7 @@ import org.springframework.cloud.commons.util.InetUtilsProperties;
|
||||
import org.springframework.cloud.config.client.ConfigClientProperties;
|
||||
import org.springframework.cloud.config.client.ConfigServerInstanceProvider;
|
||||
import org.springframework.cloud.zookeeper.CuratorFactory;
|
||||
import org.springframework.cloud.zookeeper.discovery.ConditionalOnZookeeperDiscoveryEnabled;
|
||||
import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryClient;
|
||||
import org.springframework.cloud.zookeeper.discovery.ZookeeperDiscoveryProperties;
|
||||
import org.springframework.cloud.zookeeper.discovery.ZookeeperInstance;
|
||||
@@ -102,7 +105,7 @@ public class ZookeeperConfigServerBootstrapper implements BootstrapRegistryIniti
|
||||
// create instance provider
|
||||
registry.registerIfAbsent(ConfigServerInstanceProvider.Function.class, context -> {
|
||||
if (!isEnabled(context.get(Binder.class))) {
|
||||
return null;
|
||||
return (id) -> Collections.emptyList();
|
||||
}
|
||||
return context.get(ZookeeperDiscoveryClient.class)::getInstances;
|
||||
});
|
||||
@@ -122,7 +125,9 @@ public class ZookeeperConfigServerBootstrapper implements BootstrapRegistryIniti
|
||||
}
|
||||
|
||||
private boolean isEnabled(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(ConditionalOnZookeeperDiscoveryEnabled.PROPERTY, Boolean.class).orElse(true) &&
|
||||
binder.bind("spring.cloud.discovery.enabled", Boolean.class).orElse(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.apache.curator.x.discovery.details.JsonInstanceSerializer;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.cloud.client.serviceregistry.ServiceRegistryAutoConfiguration;
|
||||
@@ -52,6 +53,7 @@ public class ZookeeperServiceRegistryAutoConfiguration
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(ServiceDiscovery.class)
|
||||
@SuppressWarnings("unchecked")
|
||||
public ZookeeperServiceRegistry zookeeperServiceRegistry() {
|
||||
return new ZookeeperServiceRegistry(this.context.getBean(ServiceDiscovery.class));
|
||||
|
||||
@@ -52,15 +52,15 @@ public class ZookeeperConfigServerBootstrapperTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void notEnabledDoesNotAddInstanceProviderFn() {
|
||||
public void notEnabledReturnsEmptyList() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfig.class)
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.properties("--server.port=0", "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("ConfigServerInstanceProvider.Function should return empty list")
|
||||
.isEmpty();
|
||||
})).run();
|
||||
CuratorFramework curatorFramework = context.getBean("curatorFramework", CuratorFramework.class);
|
||||
assertThat(curatorFramework).isNotNull();
|
||||
@@ -69,6 +69,48 @@ public class ZookeeperConfigServerBootstrapperTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void zookeeperDiscoveryClientDisabledReturnsEmptyList() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfig.class)
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.properties("--server.port=0", "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.cloud.zookeeper.discovery.enabled=false",
|
||||
"spring.cloud.zookeeper.discovery.metadata[mymetadataprop]=mymetadataval",
|
||||
"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("ConfigServerInstanceProvider.Function should return empty list")
|
||||
.isEmpty();
|
||||
})).run();
|
||||
CuratorFramework curatorFramework = context.getBean("curatorFramework", CuratorFramework.class);
|
||||
assertThat(curatorFramework).isNotNull();
|
||||
assertThatThrownBy(() ->
|
||||
context.getBean("configDataCuratorFramework", CuratorFramework.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void discoveryClientDisabledReturnsEmptyList() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfig.class)
|
||||
.listeners(new ZookeeperTestingServer())
|
||||
.properties("--server.port=0", "spring.cloud.config.discovery.enabled=true",
|
||||
"spring.cloud.discovery.enabled=false",
|
||||
"spring.cloud.zookeeper.discovery.metadata[mymetadataprop]=mymetadataval",
|
||||
"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("ConfigServerInstanceProvider.Function should return empty list")
|
||||
.isEmpty();
|
||||
})).run();
|
||||
CuratorFramework curatorFramework = context.getBean("curatorFramework", CuratorFramework.class);
|
||||
assertThat(curatorFramework).isNotNull();
|
||||
assertThatThrownBy(() ->
|
||||
context.getBean("configDataCuratorFramework", CuratorFramework.class)).isInstanceOf(NoSuchBeanDefinitionException.class);
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void enabledAddsInstanceProviderFn() {
|
||||
AtomicReference<ZookeeperDiscoveryClient> bootstrapDiscoveryClient = new AtomicReference<>();
|
||||
@@ -82,7 +124,7 @@ public class ZookeeperConfigServerBootstrapperTests {
|
||||
.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.")
|
||||
assertThat(providerFn.apply("id")).as("Should return empty list.")
|
||||
.isNotNull();
|
||||
bootstrapDiscoveryClient.set(event.getBootstrapContext().get(ZookeeperDiscoveryClient.class));
|
||||
})).run();
|
||||
|
||||
@@ -52,11 +52,6 @@
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-openfeign</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-test-support</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user