Commit af0b24d1 by Spencer Gibb

use LoadBalancerBuilder so all parts of the LoadBalancer can be injected via Spring.

This includes support for: ServerList, ServerListFilter, IRule, IPing and IClientConfig. Eliminates custom wrapping of ServerList. fixes gh-185
parent b5bd371d
......@@ -24,10 +24,7 @@ import org.springframework.context.annotation.Configuration;
import com.netflix.client.config.DefaultClientConfigImpl;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ServerListFilter;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.loadbalancer.*;
import com.netflix.niws.client.http.RestClient;
import com.netflix.servo.monitor.Monitors;
......@@ -55,6 +52,29 @@ public class RibbonClientConfiguration {
@Bean
@ConditionalOnMissingBean
public IRule ribbonRule(IClientConfig config) {
ZoneAvoidanceRule rule = new ZoneAvoidanceRule();
rule.initWithNiwsConfig(config);
return rule;
}
@Bean
@ConditionalOnMissingBean
public IPing ribbonPing(IClientConfig config) {
// TODO: use PingUrl
return new NoOpPing();
}
@Bean
@ConditionalOnMissingBean
public ServerList<Server> ribbonServerList(IClientConfig config) {
ConfigurationBasedServerList serverList = new ConfigurationBasedServerList();
serverList.initWithNiwsConfig(config);
return serverList;
}
@Bean
@ConditionalOnMissingBean
public RestClient ribbonRestClient(IClientConfig config, ILoadBalancer loadBalancer) {
RestClient client = new RestClient(config);
client.setLoadBalancer(loadBalancer);
......@@ -65,9 +85,16 @@ public class RibbonClientConfiguration {
@Bean
@ConditionalOnMissingBean
public ILoadBalancer ribbonLoadBalancer(IClientConfig config,
ServerListFilter<Server> filter) {
ZoneAwareLoadBalancer<Server> balancer = new ZoneAwareLoadBalancer<>(config);
balancer.setFilter(filter);
ServerList<Server> serverList,
ServerListFilter<Server> serverListFilter,
IRule rule, IPing ping) {
ZoneAwareLoadBalancer<Server> balancer = LoadBalancerBuilder.newBuilder()
.withClientConfig(config)
.withRule(rule)
.withPing(ping)
.withServerListFilter(serverListFilter)
.withDynamicServerList(serverList)
.buildDynamicServerListLoadBalancer();
return balancer;
}
......
......@@ -34,15 +34,15 @@ import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
/**
* @author Dave Syer
*/
public class DomainExtractingServerList implements ServerList<Server> {
public class DomainExtractingServerList implements ServerList<DiscoveryEnabledServer> {
private ServerList<Server> list;
private ServerList<DiscoveryEnabledServer> list;
private IClientConfig clientConfig;
private boolean approximateZoneFromHostname;
public DomainExtractingServerList(ServerList<Server> list,
public DomainExtractingServerList(ServerList<DiscoveryEnabledServer> list,
IClientConfig clientConfig, boolean approximateZoneFromHostname) {
this.list = list;
this.clientConfig = clientConfig;
......@@ -50,31 +50,26 @@ public class DomainExtractingServerList implements ServerList<Server> {
}
@Override
public List<Server> getInitialListOfServers() {
List<Server> servers = setZones(this.list.getInitialListOfServers());
public List<DiscoveryEnabledServer> getInitialListOfServers() {
List<DiscoveryEnabledServer> servers = setZones(this.list.getInitialListOfServers());
return servers;
}
@Override
public List<Server> getUpdatedListOfServers() {
List<Server> servers = setZones(this.list.getUpdatedListOfServers());
public List<DiscoveryEnabledServer> getUpdatedListOfServers() {
List<DiscoveryEnabledServer> servers = setZones(this.list.getUpdatedListOfServers());
return servers;
}
private List<Server> setZones(List<Server> servers) {
List<Server> result = new ArrayList<>();
private List<DiscoveryEnabledServer> setZones(List<DiscoveryEnabledServer> servers) {
List<DiscoveryEnabledServer> result = new ArrayList<>();
boolean isSecure = this.clientConfig.getPropertyAsBoolean(
CommonClientConfigKey.IsSecure, Boolean.TRUE);
boolean shouldUseIpAddr = this.clientConfig.getPropertyAsBoolean(
CommonClientConfigKey.UseIPAddrForServer, Boolean.FALSE);
for (Server server : servers) {
if (server instanceof DiscoveryEnabledServer) {
result.add(new DomainExtractingServer((DiscoveryEnabledServer) server,
isSecure, shouldUseIpAddr, this.approximateZoneFromHostname));
}
else {
result.add(server);
}
for (DiscoveryEnabledServer server : servers) {
result.add(new DomainExtractingServer(server,
isSecure, shouldUseIpAddr, this.approximateZoneFromHostname));
}
return result;
}
......
......@@ -16,31 +16,27 @@
package org.springframework.cloud.netflix.ribbon.eureka;
import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
import javax.annotation.PostConstruct;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.cloud.netflix.ribbon.ZonePreferenceServerListFilter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.netflix.client.config.IClientConfig;
import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext.ContextKey;
import com.netflix.config.DynamicPropertyFactory;
import com.netflix.config.DynamicStringProperty;
import com.netflix.discovery.EurekaClientConfig;
import com.netflix.loadbalancer.DynamicServerListLoadBalancer;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.ServerList;
import com.netflix.loadbalancer.ZoneAvoidanceRule;
import com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList;
import static com.netflix.client.config.CommonClientConfigKey.DeploymentContextBasedVipAddresses;
import static com.netflix.client.config.CommonClientConfigKey.EnableZoneAffinity;
import static com.netflix.client.config.CommonClientConfigKey.NFLoadBalancerRuleClassName;
import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListClassName;
import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListFilterClassName;
import com.netflix.niws.loadbalancer.NIWSDiscoveryPing;
/**
* Preprocessor that configures defaults for eureka-discovered ribbon clients. Such as:
......@@ -51,7 +47,7 @@ import static com.netflix.client.config.CommonClientConfigKey.NIWSServerListFilt
* @author Dave Syer
*/
@Configuration
public class EurekaRibbonClientConfiguration implements BeanPostProcessor {
public class EurekaRibbonClientConfiguration {
@Value("${ribbon.eureka.approximateZoneFromHostname:false}")
private boolean approximateZoneFromHostname = false;
......@@ -75,6 +71,22 @@ public class EurekaRibbonClientConfiguration implements BeanPostProcessor {
this.serviceId = serviceId;
}
@Bean
@ConditionalOnMissingBean
public IPing ribbonPing(IClientConfig config) {
NIWSDiscoveryPing ping = new NIWSDiscoveryPing();
ping.initWithNiwsConfig(config);
return ping;
}
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config) {
DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(config);
DomainExtractingServerList serverList = new DomainExtractingServerList(discoveryServerList, config, this.approximateZoneFromHostname);
return serverList;
}
@PostConstruct
public void preprocess() {
if (this.clientConfig != null
......@@ -89,47 +101,10 @@ public class EurekaRibbonClientConfiguration implements BeanPostProcessor {
zone);
}
}
// TODO: should this look more like hibernate spring boot props?
setProp(this.serviceId, NIWSServerListClassName.key(),
DiscoveryEnabledNIWSServerList.class.getName());
// FIXME: what should this be?
setProp(this.serviceId, DeploymentContextBasedVipAddresses.key(), this.serviceId);
setProp(this.serviceId, NFLoadBalancerRuleClassName.key(),
ZoneAvoidanceRule.class.getName());
setProp(this.serviceId, NIWSServerListFilterClassName.key(),
ZonePreferenceServerListFilter.class.getName());
setProp(this.serviceId, EnableZoneAffinity.key(), "true");
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName)
throws BeansException {
return bean;
}
@Override
public Object postProcessAfterInitialization(Object bean, String beanName)
throws BeansException {
if (bean instanceof DynamicServerListLoadBalancer) {
wrapServerList((DynamicServerListLoadBalancer<?>) bean);
}
return bean;
}
private void wrapServerList(DynamicServerListLoadBalancer<?> balancer) {
@SuppressWarnings("unchecked")
DynamicServerListLoadBalancer<Server> dynamic = (DynamicServerListLoadBalancer<Server>) balancer;
ServerList<Server> list = dynamic.getServerListImpl();
if (!(list instanceof DomainExtractingServerList)) {
// This is optional: you can use the native Eureka AWS features as long as
// the server zone is populated. TODO: verify that we back off if AWS
// metadata *is* available.
// @see com.netflix.appinfo.AmazonInfo.Builder
dynamic.setServerListImpl(new DomainExtractingServerList(list, dynamic
.getClientConfig(), this.approximateZoneFromHostname));
}
}
protected void setProp(String serviceId, String suffix, String value) {
// how to set the namespace properly?
String key = getKey(serviceId, suffix);
......
......@@ -16,8 +16,6 @@
package org.springframework.cloud.netflix.ribbon;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -25,15 +23,12 @@ import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfigurati
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClientPreprocessorIntegrationTests.PlainConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.netflix.loadbalancer.AvailabilityFilteringRule;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.loadbalancer.*;
/**
* @author Dave Syer
......@@ -47,38 +42,35 @@ public class RibbonClientPreprocessorIntegrationTests {
private SpringClientFactory factory;
@Test
public void ruleDefaultsToAvailability() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
AvailabilityFilteringRule.class.cast(loadBalancer.getRule());
public void ruleDefaultsToZoneAvoidance() throws Exception {
ZoneAvoidanceRule.class.cast(getLoadBalancer().getRule());
}
@Test
public void serverListFilterDefaultsToZonePreference() throws Exception {
ZonePreferenceServerListFilter.class.cast(getLoadBalancer().getFilter());
}
@Test
public void pingDefaultsToNoOp() throws Exception {
NoOpPing.class.cast(getLoadBalancer().getPing());
}
@Test
public void serverListFilterOverride() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
assertEquals("myTestZone",
ZonePreferenceServerListFilter.class.cast(loadBalancer.getFilter())
.getZone());
public void serverListDefaultsToConfigurationBased() throws Exception {
ConfigurationBasedServerList.class.cast(getLoadBalancer().getServerListImpl());
}
@SuppressWarnings("unchecked")
private ZoneAwareLoadBalancer<Server> getLoadBalancer() {
return (ZoneAwareLoadBalancer<Server>) this.factory.getLoadBalancer("foo");
}
@Configuration
@RibbonClient(name = "foo", configuration = FooConfiguration.class)
@RibbonClient(name = "foo")
@Import({ PropertyPlaceholderAutoConfiguration.class,
ArchaiusAutoConfiguration.class, RibbonAutoConfiguration.class })
protected static class PlainConfiguration {
}
@Configuration
protected static class FooConfiguration {
@Bean
public ZonePreferenceServerListFilter serverListFilter() {
ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter();
filter.setZone("myTestZone");
return filter;
}
}
}
/*
* Copyright 2013-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.netflix.ribbon;
import static org.junit.Assert.assertEquals;
import com.netflix.client.config.IClientConfig;
import com.netflix.loadbalancer.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dave Syer
*/
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = RibbonClientPreprocessorOverridesIntegrationTests.TestConfiguration.class)
@DirtiesContext
public class RibbonClientPreprocessorOverridesIntegrationTests {
@Autowired
private SpringClientFactory factory;
@Test
public void ruleOverridesToRandom() throws Exception {
RandomRule.class.cast(getLoadBalancer().getRule());
}
@Test
public void pingOverridesToDummy() throws Exception {
DummyPing.class.cast(getLoadBalancer().getPing());
}
@Test
public void serverListOverridesToMy() throws Exception {
MyServiceList.class.cast(getLoadBalancer().getServerListImpl());
}
@SuppressWarnings("unchecked")
private ZoneAwareLoadBalancer<Server> getLoadBalancer() {
return (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
}
@Test
public void serverListFilterOverride() throws Exception {
ServerListFilter<Server> filter = getLoadBalancer().getFilter();
assertEquals("MyTestZone",
ZonePreferenceServerListFilter.class.cast(filter)
.getZone());
}
@Configuration
@RibbonClient(name = "foo", configuration = FooConfiguration.class)
@Import({ PropertyPlaceholderAutoConfiguration.class,
ArchaiusAutoConfiguration.class, EurekaClientAutoConfiguration.class,
RibbonAutoConfiguration.class})
protected static class TestConfiguration {
}
@Configuration
public static class FooConfiguration {
public FooConfiguration() {
System.out.println("here");
}
@Bean
public IRule ribbonRule() {
return new RandomRule();
}
@Bean
public IPing ribbonPing() {
return new DummyPing();
}
@Bean
public ServerList<Server> ribbonServerList(IClientConfig config) {
return new MyServiceList(config);
}
@Bean
public ZonePreferenceServerListFilter serverListFilter() {
ZonePreferenceServerListFilter filter = new ZonePreferenceServerListFilter();
filter.setZone("MyTestZone");
return filter;
}
}
public static class MyServiceList extends ConfigurationBasedServerList {
public MyServiceList(IClientConfig config) {
super.initWithNiwsConfig(config);
}
}
}
......@@ -24,8 +24,6 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.cloud.netflix.archaius.ArchaiusAutoConfiguration;
import org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration;
import org.springframework.cloud.netflix.ribbon.RibbonClientsPreprocessorIntegrationTests.TestConfiguration;
import org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList;
import org.springframework.cloud.netflix.ribbon.eureka.RibbonEurekaAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
......@@ -50,28 +48,20 @@ public class RibbonClientsPreprocessorIntegrationTests {
private SpringClientFactory factory;
@Test
public void serverListIsWrapped() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
DomainExtractingServerList.class.cast(loadBalancer.getServerListImpl());
public void ruleDefaultsToZoneAvoidance() throws Exception {
ZoneAvoidanceRule.class.cast(getLoadBalancer().getRule());
}
@Test
public void ruleDefaultsToZoneAvoidance() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
@SuppressWarnings("unchecked")
private ZoneAwareLoadBalancer<Server> getLoadBalancer() {
return (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
ZoneAvoidanceRule.class.cast(loadBalancer.getRule());
}
@Test
public void serverListFilterOverride() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
assertEquals("myTestZone",
ZonePreferenceServerListFilter.class.cast(loadBalancer.getFilter())
ZonePreferenceServerListFilter.class.cast(getLoadBalancer().getFilter())
.getZone());
}
......@@ -79,7 +69,7 @@ public class RibbonClientsPreprocessorIntegrationTests {
@RibbonClients(@RibbonClient(name = "foo", configuration = FooConfiguration.class))
@Import({ PropertyPlaceholderAutoConfiguration.class,
ArchaiusAutoConfiguration.class, EurekaClientAutoConfiguration.class,
RibbonAutoConfiguration.class, RibbonEurekaAutoConfiguration.class })
RibbonAutoConfiguration.class})
protected static class TestConfiguration {
}
......
......@@ -54,7 +54,7 @@ public class DomainExtractingServerListTests {
public void testDomainExtractingServer() {
DomainExtractingServerList serverList = getDomainExtractingServerList(
new DefaultClientConfigImpl(), true);
List<Server> servers = serverList.getInitialListOfServers();
List<DiscoveryEnabledServer> servers = serverList.getInitialListOfServers();
assertNotNull("servers was null", servers);
assertEquals("servers was not size 1", 1, servers.size());
DomainExtractingServer des = assertDomainExtractingServer(servers, ZONE);
......@@ -65,14 +65,14 @@ public class DomainExtractingServerListTests {
public void testDomainExtractingServerDontApproximateZone() {
DomainExtractingServerList serverList = getDomainExtractingServerList(
new DefaultClientConfigImpl(), false);
List<Server> servers = serverList.getInitialListOfServers();
List<DiscoveryEnabledServer> servers = serverList.getInitialListOfServers();
assertNotNull("servers was null", servers);
assertEquals("servers was not size 1", 1, servers.size());
DomainExtractingServer des = assertDomainExtractingServer(servers, null);
assertEquals("hostPort was wrong", HOST_NAME + ":" + PORT, des.getHostPort());
}
protected DomainExtractingServer assertDomainExtractingServer(List<Server> servers,
protected DomainExtractingServer assertDomainExtractingServer(List<DiscoveryEnabledServer> servers,
String zone) {
Server actualServer = servers.get(0);
assertTrue("server was not a DomainExtractingServer",
......@@ -89,7 +89,7 @@ public class DomainExtractingServerListTests {
config.setProperty(CommonClientConfigKey.UseIPAddrForServer, true);
DomainExtractingServerList serverList = getDomainExtractingServerList(config,
true);
List<Server> servers = serverList.getInitialListOfServers();
List<DiscoveryEnabledServer> servers = serverList.getInitialListOfServers();
assertNotNull("servers was null", servers);
assertEquals("servers was not size 1", 1, servers.size());
DomainExtractingServer des = assertDomainExtractingServer(servers, ZONE);
......@@ -100,7 +100,7 @@ public class DomainExtractingServerListTests {
DefaultClientConfigImpl config, boolean approximateZoneFromHostname) {
DiscoveryEnabledServer server = mock(DiscoveryEnabledServer.class);
@SuppressWarnings("unchecked")
ServerList<Server> originalServerList = mock(ServerList.class);
ServerList<DiscoveryEnabledServer> originalServerList = mock(ServerList.class);
InstanceInfo instanceInfo = mock(InstanceInfo.class);
given(server.getInstanceInfo()).willReturn(instanceInfo);
given(server.getHost()).willReturn(HOST_NAME);
......@@ -111,7 +111,7 @@ public class DomainExtractingServerListTests {
given(instanceInfo.getIPAddr()).willReturn(IP_ADDR);
given(instanceInfo.getPort()).willReturn(PORT);
given(originalServerList.getInitialListOfServers()).willReturn(
Arrays.<Server> asList(server));
Arrays.asList(server));
return new DomainExtractingServerList(originalServerList, config,
approximateZoneFromHostname);
}
......
......@@ -26,12 +26,10 @@ import com.netflix.config.ConfigurationManager;
import com.netflix.config.DeploymentContext.ContextKey;
import com.netflix.config.DynamicStringProperty;
import com.netflix.loadbalancer.ILoadBalancer;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.niws.loadbalancer.DiscoveryEnabledServer;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import static org.springframework.cloud.netflix.ribbon.eureka.EurekaRibbonClientConfiguration.VALUE_NOT_SET;
/**
......@@ -56,7 +54,7 @@ public class EurekaRibbonClientConfigurationTests {
ILoadBalancer balancer = clientFactory.getLoadBalancer("service");
assertNotNull(balancer);
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> aware = (ZoneAwareLoadBalancer<Server>) balancer;
ZoneAwareLoadBalancer<DiscoveryEnabledServer> aware = (ZoneAwareLoadBalancer<DiscoveryEnabledServer>) balancer;
assertTrue(aware.getServerListImpl() instanceof DomainExtractingServerList);
assertEquals("foo",
ConfigurationManager.getDeploymentContext().getValue(ContextKey.zone));
......
......@@ -35,6 +35,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.netflix.loadbalancer.Server;
import com.netflix.loadbalancer.ZoneAvoidanceRule;
import com.netflix.loadbalancer.ZoneAwareLoadBalancer;
import com.netflix.niws.loadbalancer.NIWSDiscoveryPing;
/**
* @author Dave Syer
......@@ -48,11 +49,24 @@ public class EurekaRibbonClientPreprocessorIntegrationTests {
private SpringClientFactory factory;
@Test
public void serverListDefaultsToDomainExtracting() throws Exception {
DomainExtractingServerList.class.cast(getLoadBalancer().getServerListImpl());
}
@Test
public void ruleDefaultsToZoneAvoidance() throws Exception {
@SuppressWarnings("unchecked")
ZoneAwareLoadBalancer<Server> loadBalancer = (ZoneAwareLoadBalancer<Server>) this.factory
ZoneAvoidanceRule.class.cast(getLoadBalancer().getRule());
}
@Test
public void pingDefaultsToDiscoveryPing() throws Exception {
NIWSDiscoveryPing.class.cast(getLoadBalancer().getPing());
}
@SuppressWarnings("unchecked")
private ZoneAwareLoadBalancer<Server> getLoadBalancer() {
return (ZoneAwareLoadBalancer<Server>) this.factory
.getLoadBalancer("foo");
ZoneAvoidanceRule.class.cast(loadBalancer.getRule());
}
@Configuration
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment