use of com.netflix.loadbalancer.AvailabilityFilteringRule 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<>();
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);
}
use of com.netflix.loadbalancer.AvailabilityFilteringRule in project ribbon by Netflix.
the class LBBuilderTest method testBuildStaticServerListLoadBalancer.
@Test
public void testBuildStaticServerListLoadBalancer() {
List<Server> list = Lists.newArrayList(expected, expected);
IRule rule = new AvailabilityFilteringRule();
IClientConfig clientConfig = IClientConfig.Builder.newBuilder().withDefaultValues().withMaxAutoRetriesNextServer(3).build();
assertEquals(3, clientConfig.get(Keys.MaxAutoRetriesNextServer).intValue());
BaseLoadBalancer lb = LoadBalancerBuilder.newBuilder().withRule(rule).buildFixedServerListLoadBalancer(list);
assertEquals(list, lb.getAllServers());
assertSame(rule, lb.getRule());
}
use of com.netflix.loadbalancer.AvailabilityFilteringRule in project ribbon by Netflix.
the class LBBuilderTest method testBuildWithDiscoveryEnabledNIWSServerListAndUpdater.
@Test
public void testBuildWithDiscoveryEnabledNIWSServerListAndUpdater() {
IRule rule = new AvailabilityFilteringRule();
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList("dummy:7001");
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<>();
ServerListUpdater updater = new PollingServerListUpdater();
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).buildDynamicServerListLoadBalancerWithUpdater();
assertNotNull(lb);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
assertSame(filter, lb.getFilter());
assertSame(list, lb.getServerListImpl());
assertSame(updater, lb.getServerListUpdater());
Server server = lb.chooseServer();
// make sure load balancer does not recreate the server instance
assertTrue(server instanceof DiscoveryEnabledServer);
}
use of com.netflix.loadbalancer.AvailabilityFilteringRule in project ribbon by Netflix.
the class RetryTest method beforeTest.
@Before
public void beforeTest() {
ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.NFLoadBalancerClassName", BaseLoadBalancer.class.getName());
ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.client.NFLoadBalancerPingClassName", DummyPing.class.getName());
ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon.ReadTimeout", "1000");
ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon." + CommonClientConfigKey.ConnectTimeout, "500");
ConfigurationManager.getConfigInstance().setProperty("RetryTest.ribbon." + CommonClientConfigKey.OkToRetryOnAllOperations, "true");
client = (RestClient) ClientFactory.getNamedClient("RetryTest");
lb = (BaseLoadBalancer) client.getLoadBalancer();
lb.setServersList(Lists.newArrayList(localServer));
httpClient = NFHttpClientFactory.getNamedNFHttpClient("RetryTest");
connectionPoolManager = (MonitoredConnectionManager) httpClient.getConnectionManager();
client.setMaxAutoRetries(0);
client.setMaxAutoRetriesNextServer(0);
client.setOkToRetryOnAllOperations(false);
lb.setServersList(Lists.newArrayList(localServer));
// reset the server index
lb.setRule(new AvailabilityFilteringRule());
lb.getLoadBalancerStats().getSingleServerStat(localServer).clearSuccessiveConnectionFailureCount();
}
use of com.netflix.loadbalancer.AvailabilityFilteringRule in project ribbon by Netflix.
the class NettyClientTest method testObservableWithRetrySameServer.
@Test
public void testObservableWithRetrySameServer() throws Exception {
IClientConfig config = DefaultClientConfigImpl.getClientConfigWithDefaultValues().withProperty(CommonClientConfigKey.ConnectTimeout, "1000");
HttpClientRequest<ByteBuf> request = HttpClientRequest.createGet("/testAsync/person");
Server badServer = new Server("localhost:12345");
Server goodServer = new Server("localhost:" + port);
List<Server> servers = Lists.newArrayList(badServer, badServer, goodServer);
BaseLoadBalancer lb = LoadBalancerBuilder.<Server>newBuilder().withRule(new AvailabilityFilteringRule()).withPing(new DummyPing()).buildFixedServerListLoadBalancer(servers);
LoadBalancingHttpClient<ByteBuf, ByteBuf> lbObservables = RibbonTransport.newHttpClient(lb, config, new NettyHttpLoadBalancerErrorHandler(1, 0, true));
Observable<Person> observableWithRetries = getPersonObservable(lbObservables.submit(request));
ObserverWithLatch<Person> observer = new ObserverWithLatch<Person>();
observableWithRetries.subscribe(observer);
observer.await();
assertNull(observer.obj);
assertTrue(observer.error instanceof ClientException);
ServerStats stats = lbObservables.getServerStats(badServer);
// two requests to bad server because retry same server is set to 1
assertEquals(2, stats.getTotalRequestsCount());
assertEquals(0, stats.getActiveRequestsCount());
stats = lbObservables.getServerStats(goodServer);
assertEquals(0, stats.getTotalRequestsCount());
}
Aggregations