Search in sources :

Example 1 with RoundRobinRule

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());
}
Also used : Configuration(org.apache.commons.configuration.Configuration) Server(com.netflix.loadbalancer.Server) DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) ILoadBalancer(com.netflix.loadbalancer.ILoadBalancer) DummyPing(com.netflix.loadbalancer.DummyPing) IClientConfig(com.netflix.client.config.IClientConfig) RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with RoundRobinRule

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());
}
Also used : Server(com.netflix.loadbalancer.Server) RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) Test(org.junit.Test)

Example 3 with RoundRobinRule

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;
}
Also used : RoundRobinRule(com.netflix.loadbalancer.RoundRobinRule) IRule(com.netflix.loadbalancer.IRule)

Aggregations

RoundRobinRule (com.netflix.loadbalancer.RoundRobinRule)3 Server (com.netflix.loadbalancer.Server)2 Test (org.junit.Test)2 IClientConfig (com.netflix.client.config.IClientConfig)1 DummyPing (com.netflix.loadbalancer.DummyPing)1 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 IRule (com.netflix.loadbalancer.IRule)1 ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)1 Configuration (org.apache.commons.configuration.Configuration)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1