use of com.netflix.loadbalancer.IRule in project ribbon by Netflix.
the class LBBuilderTest method testBuildWithDiscoveryEnabledNIWSServerList.
@Test
public void testBuildWithDiscoveryEnabledNIWSServerList() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>();
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).buildDynamicServerListLoadBalancer();
assertNotNull(lb);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
assertSame(filter, lb.getFilter());
assertSame(list, lb.getServerListImpl());
Server server = lb.chooseServer();
// make sure load balancer does not recreate the server instance
assertTrue(server instanceof DiscoveryEnabledServer);
}
use of com.netflix.loadbalancer.IRule in project ribbon by Netflix.
the class LBBuilderTest method testBuildStaticServerListLoadBalancer.
@Test
public void testBuildStaticServerListLoadBalancer() {
List<Server> list = Lists.newArrayList(expected, expected);
IRule rule = new AvailabilityFilteringRule();
IClientConfig clientConfig = IClientConfig.Builder.newBuilder().withDefaultValues().withMaxAutoRetriesNextServer(3).build();
assertEquals(3, clientConfig.get(Keys.MaxAutoRetriesNextServer).intValue());
BaseLoadBalancer lb = LoadBalancerBuilder.newBuilder().withRule(rule).buildFixedServerListLoadBalancer(list);
assertEquals(list, lb.getAllServers());
assertSame(rule, lb.getRule());
}
use of com.netflix.loadbalancer.IRule in project java-chassis by ServiceComb.
the class LoadbalanceHandler method createLoadBalancer.
private LoadBalancer createLoadBalancer(String appId, String microserviceName, String microserviceVersionRule, String transportName) {
IRule rule;
try {
rule = (IRule) Class.forName(policy, true, Thread.currentThread().getContextClassLoader()).newInstance();
LOGGER.info("Using loadbalance rule [{}] for service [{},{}].", policy, microserviceName, transportName);
} catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
LOGGER.warn("Loadbalance rule [{}] is incorrect, using default RoundRobinRule.", policy);
rule = new RoundRobinRule();
}
CseServerList serverList = new CseServerList(appId, microserviceName, microserviceVersionRule, transportName);
LoadBalancer lb = new LoadBalancer(serverList, rule);
return lb;
}
Aggregations