From f456745423138c0a6db89a4f4c1b1e4ba26bc51d Mon Sep 17 00:00:00 2001 From: "ken.lj" Date: Fri, 5 Jul 2019 09:27:20 +0800 Subject: [PATCH] Fix url generated from ConfigCenterConfig missed 'config.' prefix (#4411) * fix url generated from ConfigCenterConfig missed 'config.' prefix * remove useKeyAsParameter=false * fix ut * remove unused imports --- .../dubbo/config/ConfigCenterConfig.java | 26 ++++++++++--------- .../dubbo/config/ConfigCenterConfigTest.java | 14 ++++++++++ 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java index 7caae5634ec..28d3c5a561f 100644 --- a/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java +++ b/dubbo-config/dubbo-config-api/src/main/java/org/apache/dubbo/config/ConfigCenterConfig.java @@ -23,20 +23,21 @@ import org.apache.dubbo.common.utils.UrlUtils; import org.apache.dubbo.config.support.Parameter; +import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import static org.apache.dubbo.common.constants.CommonConstants.ANYHOST_VALUE; import static org.apache.dubbo.common.constants.CommonConstants.PATH_KEY; import static org.apache.dubbo.common.constants.CommonConstants.PROTOCOL_KEY; +import static org.apache.dubbo.config.Constants.CONFIG_CONFIGFILE_KEY; +import static org.apache.dubbo.config.Constants.CONFIG_ENABLE_KEY; +import static org.apache.dubbo.config.Constants.CONFIG_TIMEOUT_KEY; +import static org.apache.dubbo.config.Constants.ZOOKEEPER_PROTOCOL; import static org.apache.dubbo.configcenter.Constants.CONFIG_CHECK_KEY; import static org.apache.dubbo.configcenter.Constants.CONFIG_CLUSTER_KEY; import static org.apache.dubbo.configcenter.Constants.CONFIG_GROUP_KEY; import static org.apache.dubbo.configcenter.Constants.CONFIG_NAMESPACE_KEY; -import static org.apache.dubbo.config.Constants.ZOOKEEPER_PROTOCOL; -import static org.apache.dubbo.config.Constants.CONFIG_CONFIGFILE_KEY; -import static org.apache.dubbo.config.Constants.CONFIG_ENABLE_KEY; -import static org.apache.dubbo.config.Constants.CONFIG_TIMEOUT_KEY; /** * ConfigCenterConfig @@ -90,7 +91,8 @@ public ConfigCenterConfig() { } public URL toUrl() { - Map map = this.getMetaData(); + Map map = new HashMap<>(); + appendParameters(map, this); if (StringUtils.isEmpty(address)) { address = ANYHOST_VALUE; } @@ -131,7 +133,7 @@ public void setAddress(String address) { this.address = address; } - @Parameter(key = CONFIG_CLUSTER_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_CLUSTER_KEY) public String getCluster() { return cluster; } @@ -140,7 +142,7 @@ public void setCluster(String cluster) { this.cluster = cluster; } - @Parameter(key = CONFIG_NAMESPACE_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_NAMESPACE_KEY) public String getNamespace() { return namespace; } @@ -149,7 +151,7 @@ public void setNamespace(String namespace) { this.namespace = namespace; } - @Parameter(key = CONFIG_GROUP_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_GROUP_KEY) public String getGroup() { return group; } @@ -158,7 +160,7 @@ public void setGroup(String group) { this.group = group; } - @Parameter(key = CONFIG_CHECK_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_CHECK_KEY) public Boolean isCheck() { return check; } @@ -167,7 +169,7 @@ public void setCheck(Boolean check) { this.check = check; } - @Parameter(key = CONFIG_ENABLE_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_ENABLE_KEY) public Boolean isHighestPriority() { return highestPriority; } @@ -192,7 +194,7 @@ public void setPassword(String password) { this.password = password; } - @Parameter(key = CONFIG_TIMEOUT_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_TIMEOUT_KEY) public Long getTimeout() { return timeout; } @@ -201,7 +203,7 @@ public void setTimeout(Long timeout) { this.timeout = timeout; } - @Parameter(key = CONFIG_CONFIGFILE_KEY, useKeyAsProperty = false) + @Parameter(key = CONFIG_CONFIGFILE_KEY) public String getConfigFile() { return configFile; } diff --git a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java index 96e55825d74..cf10ed50b85 100644 --- a/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java +++ b/dubbo-config/dubbo-config-api/src/test/java/org/apache/dubbo/config/ConfigCenterConfigTest.java @@ -29,4 +29,18 @@ public void testPrefix() { ConfigCenterConfig config = new ConfigCenterConfig(); Assertions.assertEquals("dubbo.config-center", config.getPrefix()); } + + @Test + public void testToUrl() { + ConfigCenterConfig config = new ConfigCenterConfig(); + config.setNamespace("namespace"); + config.setGroup("group"); + config.setAddress("zookeeper://127.0.0.1:2181"); + + Assertions.assertEquals("zookeeper://127.0.0.1:2181/ConfigCenterConfig?config.check=true&" + + "config.config-file=dubbo.properties&config.group=group&config.highest-priority=true&" + + "config.namespace=namespace&config.timeout=3000", + config.toUrl().toFullString() + ); + } }