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);
}
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;
}
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");
}
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);
}
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);
}
Aggregations