use of com.netflix.loadbalancer.RoundRobinRule in project ribbon by Netflix.
the class LBBuilderTest method testBuildWithArchaiusProperties.
@Test
public void testBuildWithArchaiusProperties() {
Configuration config = ConfigurationManager.getConfigInstance();
config.setProperty("client1.niws.client." + Keys.DeploymentContextBasedVipAddresses, "dummy:7001");
config.setProperty("client1.niws.client." + Keys.InitializeNFLoadBalancer, "true");
config.setProperty("client1.niws.client." + Keys.NFLoadBalancerClassName, DynamicServerListLoadBalancer.class.getName());
config.setProperty("client1.niws.client." + Keys.NFLoadBalancerRuleClassName, RoundRobinRule.class.getName());
config.setProperty("client1.niws.client." + Keys.NIWSServerListClassName, DiscoveryEnabledNIWSServerList.class.getName());
config.setProperty("client1.niws.client." + Keys.NIWSServerListFilterClassName, ZoneAffinityServerListFilter.class.getName());
IClientConfig clientConfig = IClientConfig.Builder.newBuilder(NiwsClientConfig.class, "client1").build();
ILoadBalancer lb = LoadBalancerBuilder.newBuilder().withClientConfig(clientConfig).buildLoadBalancerFromConfigWithReflection();
assertNotNull(lb);
assertEquals(DynamicServerListLoadBalancer.class.getName(), lb.getClass().getName());
DynamicServerListLoadBalancer<Server> dynamicLB = (DynamicServerListLoadBalancer<Server>) lb;
assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
assertTrue(dynamicLB.getPing() instanceof DummyPing);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
use of com.netflix.loadbalancer.RoundRobinRule in project camel by apache.
the class RibbonServerListTest method testFixedServerList.
@Test
public void testFixedServerList() throws Exception {
ZoneAwareLoadBalancer<RibbonServiceDefinition> lb = LoadBalancerBuilder.<RibbonServiceDefinition>newBuilder().withDynamicServerList(new RibbonLoadBalancer.RibbonServerList("unknown", StaticServiceDiscovery.forServices(new RibbonServiceDefinition("unknown", "localhost", 9090), new RibbonServiceDefinition("unknown", "localhost", 9091)), PassThroughServiceFilter.INSTANCE)).withRule(new RoundRobinRule()).buildDynamicServerListLoadBalancer();
Server server = lb.chooseServer();
assertEquals("localhost", server.getHost());
assertEquals(9091, server.getPort());
server = lb.chooseServer();
assertEquals("localhost", server.getHost());
assertEquals(9090, server.getPort());
}
use of com.netflix.loadbalancer.RoundRobinRule 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