Search in sources :

Example 1 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter 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);
}
Also used : Server(com.netflix.loadbalancer.Server) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) IRule(com.netflix.loadbalancer.IRule) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter 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 3 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter in project ribbon by Netflix.

the class DefaultNIWSServerListFilterTest method testZoneExclusivity.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZoneExclusivity() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.EnableZoneExclusivity", "true");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest2.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest2");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);
    for (int i = 1; i <= 4; i++) {
        loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(expected, filtered);
}
Also used : DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 4 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter in project ribbon by Netflix.

the class DefaultNIWSServerListFilterTest method testZoneAffinityEnabled.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZoneAffinityEnabled() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest1.ribbon.EnableZoneAffinity", "true");
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest1");
    assertTrue(lb.getRule() instanceof AvailabilityFilteringRule);
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    servers.add(createServer(3, "c"));
    servers.add(createServer(4, "c"));
    servers.add(createServer(5, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    expected.add(createServer(4, "c"));
    expected.add(createServer(5, "c"));
    assertEquals(expected, filtered);
    lb.setServersList(filtered);
    for (int i = 1; i <= 4; i++) {
        loadBalancerStats.incrementActiveRequestsCount(createServer(i, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);
}
Also used : DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) ArrayList(java.util.ArrayList) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) Test(org.junit.Test)

Example 5 with ZoneAffinityServerListFilter

use of com.netflix.loadbalancer.ZoneAffinityServerListFilter in project ribbon by Netflix.

the class DefaultNIWSServerListFilterTest method testZoneAffinityOverride.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testZoneAffinityOverride() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.DeploymentContextBasedVipAddresses", "l10nservicegeneral.cloud.netflix.net:7001");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NFLoadBalancerClassName", DynamicServerListLoadBalancer.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.EnableZoneAffinity", "true");
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.NIWSServerListClassName", DiscoveryEnabledNIWSServerList.class.getName());
    ConfigurationManager.getConfigInstance().setProperty("DefaultNIWSServerListFilterTest3.ribbon.zoneAffinity.minAvailableServers", "3");
    DynamicServerListLoadBalancer lb = (DynamicServerListLoadBalancer) ClientFactory.getNamedLoadBalancer("DefaultNIWSServerListFilterTest3");
    ZoneAffinityServerListFilter filter = (ZoneAffinityServerListFilter) lb.getFilter();
    LoadBalancerStats loadBalancerStats = lb.getLoadBalancerStats();
    List<DiscoveryEnabledServer> servers = new ArrayList<DiscoveryEnabledServer>();
    servers.add(createServer(1, "a"));
    servers.add(createServer(2, "a"));
    servers.add(createServer(3, "a"));
    servers.add(createServer(4, "a"));
    servers.add(createServer(1, "b"));
    servers.add(createServer(2, "b"));
    servers.add(createServer(3, "b"));
    servers.add(createServer(1, "c"));
    servers.add(createServer(2, "c"));
    List<DiscoveryEnabledServer> filtered = filter.getFilteredListOfServers(servers);
    List<DiscoveryEnabledServer> expected = new ArrayList<DiscoveryEnabledServer>();
    /*
        expected.add(createServer(1, "c"));
        expected.add(createServer(2, "c"));
        expected.add(createServer(3, "c"));
        expected.add(createServer(4, "c"));
        expected.add(createServer(5, "c")); */
    // less than 3 servers in zone c, will not honor zone affinity
    assertEquals(servers, filtered);
    lb.setServersList(filtered);
    servers.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(1, "c"));
    expected.add(createServer(2, "c"));
    expected.add(createServer(3, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    // now we have enough servers in C
    assertEquals(expected, filtered);
    // make one server black out
    for (int i = 1; i <= 3; i++) {
        loadBalancerStats.incrementSuccessiveConnectionFailureCount(createServer(1, "c"));
    }
    filtered = filter.getFilteredListOfServers(servers);
    assertEquals(servers, filtered);
    // new server added in zone c, zone c should now have enough servers
    servers.add(createServer(4, "c"));
    filtered = filter.getFilteredListOfServers(servers);
    expected.add(createServer(4, "c"));
    assertEquals(expected, filtered);
}
Also used : DynamicServerListLoadBalancer(com.netflix.loadbalancer.DynamicServerListLoadBalancer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)6 Test (org.junit.Test)5 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)4 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)3 LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)3 ArrayList (java.util.ArrayList)3 IRule (com.netflix.loadbalancer.IRule)2 Server (com.netflix.loadbalancer.Server)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 DefaultClientConfigImpl (com.netflix.client.config.DefaultClientConfigImpl)1 IClientConfig (com.netflix.client.config.IClientConfig)1 EurekaClient (com.netflix.discovery.EurekaClient)1 DummyPing (com.netflix.loadbalancer.DummyPing)1 ILoadBalancer (com.netflix.loadbalancer.ILoadBalancer)1 RandomRule (com.netflix.loadbalancer.RandomRule)1 RoundRobinRule (com.netflix.loadbalancer.RoundRobinRule)1 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)1 DiscoveryEnabledNIWSServerList (com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList)1 DiscoveryEnabledServer (com.netflix.niws.loadbalancer.DiscoveryEnabledServer)1 EurekaNotificationServerListUpdater (com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater)1