Skip to content

Commit

Permalink
Fix url generated from ConfigCenterConfig missed 'config.' prefix (#4411
Browse files Browse the repository at this point in the history
)

* fix url generated from ConfigCenterConfig missed 'config.' prefix

* remove useKeyAsParameter=false

* fix ut

* remove unused imports
  • Loading branch information
chickenlj authored and nzomkxia committed Jul 5, 2019
1 parent 2497dcf commit f456745
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +91,8 @@ public ConfigCenterConfig() {
}

public URL toUrl() {
Map<String, String> map = this.getMetaData();
Map<String, String> map = new HashMap<>();
appendParameters(map, this);
if (StringUtils.isEmpty(address)) {
address = ANYHOST_VALUE;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
}

0 comments on commit f456745

Please sign in to comment.