Skip to content

Commit

Permalink
Fix client name being null
Browse files Browse the repository at this point in the history
  • Loading branch information
elandau committed Apr 25, 2019
1 parent e1111b4 commit bf65e37
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -452,7 +453,7 @@ protected void setPropertyInternal(IClientConfigKey propName, Object value) {
}

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) {
Expand Down Expand Up @@ -909,6 +910,8 @@ public <T> T get(IClientConfigKey<T> key) {

@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(),
Expand Down Expand Up @@ -994,6 +997,8 @@ private <T> PropertyWrapper<T> getPropertyWrapper(String propName, Class<T> type

@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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ public void setupMock(){
}

@Test
@Ignore
public void testBuildWithDiscoveryEnabledNIWSServerList() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
Expand All @@ -100,7 +99,6 @@ public void testBuildWithDiscoveryEnabledNIWSServerList() {
}

@Test
@Ignore
public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,9 @@ private LoadBalancerStats createLoadBalancerStatsFromConfig(IClientConfig client
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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
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;

Expand Down Expand Up @@ -87,7 +88,7 @@ public void initWithNiwsConfig(IClientConfig clientConfig) {
return;
}
clientName = clientConfig.getClientName();
if (clientName == null) {
if (StringUtils.isEmpty(clientName)) {
clientName = "default";
}
vipAddresses = clientConfig.resolveDeploymentContextbasedVipAddresses();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ private void testChooseServer(ZoneAwareLoadBalancer<Server> balancer, String...


@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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@
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
Expand Down

0 comments on commit bf65e37

Please sign in to comment.