use of com.netflix.loadbalancer.ServerListUpdater 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.loadbalancer.ServerListUpdater in project ribbon by Netflix.
the class EurekaNotificationServerListUpdaterTest method testTaskAlreadyQueued.
@Test
public void testTaskAlreadyQueued() throws Exception {
EurekaNotificationServerListUpdater serverListUpdater = new EurekaNotificationServerListUpdater(new Provider<EurekaClient>() {
@Override
public EurekaClient get() {
return eurekaClientMock;
}
}, testExecutor);
try {
Capture<EurekaEventListener> eventListenerCapture = new Capture<EurekaEventListener>();
eurekaClientMock.registerEventListener(EasyMock.capture(eventListenerCapture));
EasyMock.replay(eurekaClientMock);
final CountDownLatch countDownLatch = new CountDownLatch(1);
serverListUpdater.start(new ServerListUpdater.UpdateAction() {
@Override
public void doUpdate() {
if (countDownLatch.getCount() == 0) {
Assert.fail("should only countdown once");
}
countDownLatch.countDown();
}
});
eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
eventListenerCapture.getValue().onEvent(new CacheRefreshedEvent());
Assert.assertTrue(countDownLatch.await(2, TimeUnit.SECONDS));
// sleep a bit more
Thread.sleep(100);
Assert.assertFalse(serverListUpdater.updateQueued.get());
} finally {
serverListUpdater.stop();
EasyMock.verify(eurekaClientMock);
}
}
Aggregations