提交 bf65e373 编写于 作者: E elandau

Fix client name being null

上级 e1111b49
......@@ -27,6 +27,7 @@ import com.netflix.config.DynamicStringProperty;
import com.netflix.config.PropertyWrapper;
import org.apache.commons.configuration.AbstractConfiguration;
import org.apache.commons.configuration.Configuration;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -163,7 +164,7 @@ public class DefaultClientConfigImpl implements IClientConfig {
private static final Logger LOG = LoggerFactory.getLogger(DefaultClientConfigImpl.class);
private String clientName = null;
private String clientName = "";
private VipAddressResolver resolver = null;
......@@ -452,7 +453,7 @@ public class DefaultClientConfigImpl implements IClientConfig {
}
private String getConfigKey(String propName) {
return (clientName == null) ? getDefaultPropName(propName) : getInstancePropName(clientName, propName);
return (StringUtils.isEmpty(clientName)) ? getDefaultPropName(propName) : getInstancePropName(clientName, propName);
}
protected void setPropertyInternal(final String propName, Object value) {
......@@ -909,6 +910,8 @@ public class DefaultClientConfigImpl implements IClientConfig {
@Override
public <T> Property<T> getGlobalProperty(IClientConfigKey<T> key) {
LOG.debug("Get global property {}", key.key());
final PropertyWrapper<T> propertyWrapper = getPropertyWrapper(
key.key(),
key.type(),
......@@ -994,6 +997,8 @@ public class DefaultClientConfigImpl implements IClientConfig {
@Override
public <T> Property<T> getDynamicProperty(IClientConfigKey<T> key) {
LOG.debug("Get dynamic property {}", key.key());
final PropertyWrapper<T> propertyWrapper = getPropertyWrapper(
getInstancePropName(getClientName(), key.key()),
key.type(),
......
......@@ -80,7 +80,6 @@ public class LBBuilderTest {
}
@Test
@Ignore
public void testBuildWithDiscoveryEnabledNIWSServerList() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
......@@ -100,7 +99,6 @@ public class LBBuilderTest {
}
@Test
@Ignore
public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
......
......@@ -235,9 +235,9 @@ public class BaseLoadBalancer extends AbstractLoadBalancer implements
try {
return (LoadBalancerStats) factory.create(loadBalancerStatsClassName, clientConfig);
} catch (Exception e) {
logger.warn("Error initializing configured LoadBalancerStats class - " + String.valueOf(loadBalancerStatsClassName)
+ ". Falling-back to a new LoadBalancerStats instance instead.", e);
return new LoadBalancerStats(clientConfig.getClientName());
throw new RuntimeException(
"Error initializing configured LoadBalancerStats class - " + loadBalancerStatsClassName,
e);
}
}
......
......@@ -28,6 +28,7 @@ import com.netflix.client.config.IClientConfig;
import com.netflix.servo.monitor.Monitors;
import com.netflix.servo.monitor.Timer;
import com.netflix.util.Pair;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -87,7 +88,7 @@ public class LoadBalancerContext implements IClientConfigAware {
return;
}
clientName = clientConfig.getClientName();
if (clientName == null) {
if (StringUtils.isEmpty(clientName)) {
clientName = "default";
}
vipAddresses = clientConfig.resolveDeploymentContextbasedVipAddresses();
......
......@@ -70,11 +70,11 @@ public class ZoneAwareLoadBalancerTest {
@Test
@Ignore
public void testChooseZone() throws Exception {
ConfigurationManager.getConfigInstance().setProperty("niws.loadbalancer.serverStats.activeRequestsCount.effectiveWindowSeconds", 10);
DefaultClientConfigImpl config = new DefaultClientConfigImpl();
config.setClientName("testChooseZone");
ZoneAwareLoadBalancer<Server> balancer = new ZoneAwareLoadBalancer<Server>();
balancer.init();
IRule globalRule = new RoundRobinRule();
......
......@@ -25,11 +25,13 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import com.netflix.ribbon.testutils.MockedDiscoveryServerListTest;
import io.netty.buffer.ByteBuf;
import org.junit.Test;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import java.util.List;
import static org.junit.Assert.assertEquals;
@PowerMockIgnore("com.google.*")
public class DiscoveryLoadBalancerTest extends MockedDiscoveryServerListTest {
@Override
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册