Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix url generated from ConfigCenterConfig missed 'config.' prefix #4411

Merged
merged 8 commits into from
Jul 5, 2019
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()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,6 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;

import static org.apache.dubbo.common.constants.CommonConstants.DEFAULT_TIMEOUT;
import static org.apache.dubbo.common.constants.CommonConstants.TIMEOUT_KEY;

/**
* This class will work as a wrapper wrapping outside of each protocol invoker.
*
Expand Down