use of com.netflix.loadbalancer.PollingServerListUpdater in project camel by apache.
the class RibbonLoadBalancer method createLoadBalancer.
// ************************
// Helpers
// ************************
private ZoneAwareLoadBalancer<RibbonServiceDefinition> createLoadBalancer(String serviceName, ServiceDiscovery serviceDiscovery) {
// setup client config
IClientConfig config = configuration.getClientName() != null ? IClientConfig.Builder.newBuilder(configuration.getClientName()).build() : IClientConfig.Builder.newBuilder().build();
if (configuration.getClientConfig() != null) {
for (Map.Entry<String, String> entry : configuration.getClientConfig().entrySet()) {
IClientConfigKey key = IClientConfigKey.Keys.valueOf(entry.getKey());
String value = entry.getValue();
LOGGER.debug("RibbonClientConfig: {}={}", key.key(), value);
config.set(key, value);
}
}
return new ZoneAwareLoadBalancer<>(config, configuration.getRuleOrDefault(RoundRobinRule::new), configuration.getPingOrDefault(DummyPing::new), new RibbonServerList(serviceName, serviceDiscovery, serviceFilter), null, new PollingServerListUpdater(config));
}
use of com.netflix.loadbalancer.PollingServerListUpdater in project spring-cloud-netflix by spring-cloud.
the class RibbonClientConfigurationIntegrationTests method testLoadBalancerConstruction.
@Test
public void testLoadBalancerConstruction() {
ILoadBalancer loadBalancer = clientFactory.getInstance("test", ILoadBalancer.class);
assertThat(loadBalancer, is(instanceOf(ZoneAwareLoadBalancer.class)));
ZoneAwareLoadBalancer lb = (ZoneAwareLoadBalancer) loadBalancer;
ServerListUpdater serverListUpdater = (PollingServerListUpdater) ReflectionTestUtils.getField(loadBalancer, "serverListUpdater");
Long refreshIntervalMs = (Long) ReflectionTestUtils.getField(serverListUpdater, "refreshIntervalMs");
// assertThat(refreshIntervalMs, equalTo(999L));
ServerListUpdater updater = clientFactory.getInstance("test", ServerListUpdater.class);
assertThat(updater, is(sameInstance(serverListUpdater)));
}
use of com.netflix.loadbalancer.PollingServerListUpdater 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());
config.setProperty("client1.niws.client." + Keys.ServerListUpdaterClassName, PollingServerListUpdater.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.getServerListUpdater() instanceof PollingServerListUpdater);
assertTrue(dynamicLB.getFilter() instanceof ZoneAffinityServerListFilter);
assertTrue(dynamicLB.getRule() instanceof RoundRobinRule);
assertTrue(dynamicLB.getPing() instanceof DummyPing);
assertEquals(Lists.newArrayList(expected), lb.getAllServers());
}
use of com.netflix.loadbalancer.PollingServerListUpdater 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);
}
Aggregations