Search in sources :

Example 1 with LoadBalancerStats

use of com.netflix.loadbalancer.LoadBalancerStats 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 2 with LoadBalancerStats

use of com.netflix.loadbalancer.LoadBalancerStats in project java-chassis by ServiceComb.

the class SessionStickinessRule method isErrorThresholdMet.

private boolean isErrorThresholdMet() {
    AbstractLoadBalancer lb = (AbstractLoadBalancer) getLoadBalancer();
    LoadBalancerStats stats = lb.getLoadBalancerStats();
    if (stats != null && stats.getServerStats() != null && stats.getServerStats().size() > 0) {
        ServerStats serverStats = stats.getSingleServerStat(lastServer);
        int successiveFaildCount = serverStats.getSuccessiveConnectionFailureCount();
        if (Configuration.INSTANCE.getSuccessiveFailedTimes() > 0 && successiveFaildCount >= Configuration.INSTANCE.getSuccessiveFailedTimes()) {
            serverStats.clearSuccessiveConnectionFailureCount();
            return true;
        }
    }
    return false;
}
Also used : ServerStats(com.netflix.loadbalancer.ServerStats) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) AbstractLoadBalancer(com.netflix.loadbalancer.AbstractLoadBalancer)

Example 3 with LoadBalancerStats

use of com.netflix.loadbalancer.LoadBalancerStats in project java-chassis by ServiceComb.

the class TestIsolationServerListFilter method setUp.

@Before
public void setUp() throws Exception {
    IsolationServerListFilter = new IsolationServerListFilter();
    loadBalancerStats = new LoadBalancerStats("loadBalancer");
}
Also used : LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) Before(org.junit.Before)

Example 4 with LoadBalancerStats

use of com.netflix.loadbalancer.LoadBalancerStats in project java-chassis by ServiceComb.

the class TestSessionSticknessRule method testRuleFullOperation.

@Test
public void testRuleFullOperation() {
    SessionStickinessRule rule = new SessionStickinessRule();
    LoadBalancer mockedLb = mock(LoadBalancer.class);
    Transport transport = mock(Transport.class);
    CseServer mockedServer = new CseServer(transport, new CacheEndpoint("rest:127.0.0.1:8888", null));
    Object key = Mockito.mock(Object.class);
    LoadBalancerStats stats = mock(LoadBalancerStats.class);
    Mockito.when(mockedLb.getLoadBalancerStats()).thenReturn(stats);
    Deencapsulation.invoke(rule, "chooseServerWhenTimeout", key);
    mockedServer.setAlive(true);
    mockedServer.setReadyToServe(true);
    List<Server> allServers = Arrays.asList(mockedServer);
    when(mockedLb.getReachableServers()).thenReturn(allServers);
    when(mockedLb.getAllServers()).thenReturn(allServers);
    rule.setLoadBalancer(mockedLb);
    Assert.assertEquals(rule.getLoadBalancer(), mockedLb);
    Server s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
    s = rule.choose("default");
    Assert.assertEquals(s, mockedServer);
}
Also used : Server(com.netflix.loadbalancer.Server) CacheEndpoint(io.servicecomb.serviceregistry.cache.CacheEndpoint) LoadBalancerStats(com.netflix.loadbalancer.LoadBalancerStats) Transport(io.servicecomb.core.Transport) Test(org.junit.Test)

Example 5 with LoadBalancerStats

use of com.netflix.loadbalancer.LoadBalancerStats 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)

Aggregations

LoadBalancerStats (com.netflix.loadbalancer.LoadBalancerStats)7 Test (org.junit.Test)4 DynamicServerListLoadBalancer (com.netflix.loadbalancer.DynamicServerListLoadBalancer)3 ZoneAffinityServerListFilter (com.netflix.loadbalancer.ZoneAffinityServerListFilter)3 ArrayList (java.util.ArrayList)3 AbstractLoadBalancer (com.netflix.loadbalancer.AbstractLoadBalancer)1 AvailabilityFilteringRule (com.netflix.loadbalancer.AvailabilityFilteringRule)1 Server (com.netflix.loadbalancer.Server)1 ServerStats (com.netflix.loadbalancer.ServerStats)1 ZoneSnapshot (com.netflix.loadbalancer.ZoneSnapshot)1 Transport (io.servicecomb.core.Transport)1 CacheEndpoint (io.servicecomb.serviceregistry.cache.CacheEndpoint)1 Before (org.junit.Before)1