use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project spring-cloud-netflix by spring-cloud.
the class EurekaRibbonClientConfiguration method ribbonServerList.
@Bean
@ConditionalOnMissingBean
public ServerList<?> ribbonServerList(IClientConfig config, Provider<EurekaClient> eurekaClientProvider) {
if (this.propertiesFactory.isSet(ServerList.class, serviceId)) {
return this.propertiesFactory.get(ServerList.class, config, serviceId);
}
DiscoveryEnabledNIWSServerList discoveryServerList = new DiscoveryEnabledNIWSServerList(config, eurekaClientProvider);
DomainExtractingServerList serverList = new DomainExtractingServerList(discoveryServerList, config, this.approximateZoneFromHostname);
return serverList;
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project ribbon by Netflix.
the class EurekaDynamicServerListLoadBalancerTest method testShutdownMultiple.
@Test
public void testShutdownMultiple() {
try {
eurekaClientMock.registerEventListener(EasyMock.anyObject(EurekaEventListener.class));
EasyMock.expectLastCall().anyTimes();
PowerMock.replay(DiscoveryClient.class);
PowerMock.replay(eurekaClientMock);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb1 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb2 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb3 = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
lb3.shutdown();
lb1.shutdown();
lb2.shutdown();
} finally {
PowerMock.verify(eurekaClientMock);
PowerMock.verify(DiscoveryClient.class);
}
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project nutzboot by nutzam.
the class FeignStarter method getLoadBalancer.
public Object getLoadBalancer(String name, FeignInject fc) {
EurekaClient eurekaClient = ioc.get(EurekaClient.class, "eurekaClient");
DefaultClientConfigImpl clientConfig = DefaultClientConfigImpl.getClientConfigWithDefaultValues(name);
ServerList<DiscoveryEnabledServer> list = new DiscoveryEnabledNIWSServerList(name, () -> eurekaClient);
ServerListFilter<DiscoveryEnabledServer> filter = new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(clientConfig);
ServerListUpdater updater = new EurekaNotificationServerListUpdater(() -> eurekaClient);
IRule rule = null;
switch(getLbRuleString(fc.lbRule())) {
case "random":
rule = new RandomRule();
break;
case "availability":
default:
AvailabilityFilteringRule _rule = new AvailabilityFilteringRule();
_rule.initWithNiwsConfig(clientConfig);
rule = _rule;
break;
}
ZoneAwareLoadBalancer<DiscoveryEnabledServer> lb = LoadBalancerBuilder.<DiscoveryEnabledServer>newBuilder().withDynamicServerList(list).withRule(rule).withServerListFilter(filter).withServerListUpdater(updater).withClientConfig(clientConfig).buildDynamicServerListLoadBalancerWithUpdater();
return LBClient.create(lb, clientConfig);
}
use of com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList in project ribbon by Netflix.
the class EurekaDynamicServerListLoadBalancerTest method testLoadBalancerHappyCase.
@Test
public void testLoadBalancerHappyCase() throws Exception {
Assert.assertNotEquals("the two test server list counts should be different", secondServerListSize, initialServerListSize);
DynamicServerListLoadBalancer<DiscoveryEnabledServer> lb = null;
try {
Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
PowerMock.replay(DiscoveryClient.class);
PowerMock.replay(eurekaClientMock);
// actual testing
// initial creation and loading of the first serverlist
lb = new DynamicServerListLoadBalancer<DiscoveryEnabledServer>(config, new AvailabilityFilteringRule(), new DummyPing(), new DiscoveryEnabledNIWSServerList(vipAddress, eurekaClientProvider), new ZoneAffinityServerListFilter<DiscoveryEnabledServer>(), new EurekaNotificationServerListUpdater(eurekaClientProvider));
Assert.assertEquals(initialServerListSize, lb.getServerCount(false));
// trigger an eureka CacheRefreshEvent
eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
Assert.assertTrue(verifyFinalServerListCount(secondServerListSize, lb));
} finally {
if (lb != null) {
lb.shutdown();
PowerMock.verify(eurekaClientMock);
PowerMock.verify(DiscoveryClient.class);
}
}
}
Aggregations