use of com.netflix.discovery.EurekaClient 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);
}
}
use of com.netflix.discovery.EurekaClient 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.discovery.EurekaClient in project hazelcast-eureka by hazelcast.
the class EurekaOnePropertyBasedClientConfigTest method checkPropertyBasedConfigurationWorking.
@Test
public void checkPropertyBasedConfigurationWorking() {
EurekaClient client = strategy.getEurekaClient();
assertThat(client, notNullValue());
assertThat(client.getEurekaClientConfig(), notNullValue());
assertThat(client.getEurekaClientConfig(), instanceOf(PropertyBasedEurekaClientConfig.class));
assertThat(client.getEurekaClientConfig().getEurekaServerServiceUrls("default").get(0), is(properties.get("serviceUrl.default")));
}
use of com.netflix.discovery.EurekaClient in project spring-cloud-netflix by spring-cloud.
the class DiscoveryClientConfigServiceAutoConfigurationTests method onWhenRequested.
@Test
public void onWhenRequested() throws Exception {
setup("spring.cloud.config.discovery.enabled=true", "eureka.instance.metadataMap.foo:bar", "eureka.instance.nonSecurePort:7001", "eureka.instance.hostname:foo");
assertEquals(1, this.context.getBeanNamesForType(EurekaDiscoveryClientConfigServiceAutoConfiguration.class).length);
EurekaClient eurekaClient = this.context.getParent().getBean(EurekaClient.class);
Mockito.verify(eurekaClient, times(2)).getInstancesByVipAddress(DEFAULT_CONFIG_SERVER, false);
Mockito.verify(eurekaClient, times(1)).shutdown();
ConfigClientProperties locator = this.context.getBean(ConfigClientProperties.class);
assertEquals("http://foo:7001/", locator.getRawUri());
ApplicationInfoManager infoManager = this.context.getBean(ApplicationInfoManager.class);
assertEquals("bar", infoManager.getInfo().getMetadata().get("foo"));
}
use of com.netflix.discovery.EurekaClient in project eureka by Netflix.
the class ExampleEurekaClient method main.
public static void main(String[] args) {
ExampleEurekaClient sampleClient = new ExampleEurekaClient();
// create the client
ApplicationInfoManager applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
EurekaClient client = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
// use the client
sampleClient.sendRequestToServiceUsingEureka(client);
// shutdown the client
eurekaClient.shutdown();
}
Aggregations