Search in sources :

Example 16 with EurekaClient

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);
    }
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient) EurekaEventListener(com.netflix.discovery.EurekaEventListener) CountDownLatch(java.util.concurrent.CountDownLatch) Capture(org.easymock.Capture) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) CacheRefreshedEvent(com.netflix.discovery.CacheRefreshedEvent) Test(org.junit.Test)

Example 17 with EurekaClient

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);
}
Also used : DiscoveryEnabledNIWSServerList(com.netflix.niws.loadbalancer.DiscoveryEnabledNIWSServerList) DiscoveryEnabledServer(com.netflix.niws.loadbalancer.DiscoveryEnabledServer) ZoneAffinityServerListFilter(com.netflix.loadbalancer.ZoneAffinityServerListFilter) EurekaClient(com.netflix.discovery.EurekaClient) RandomRule(com.netflix.loadbalancer.RandomRule) IRule(com.netflix.loadbalancer.IRule) ServerListUpdater(com.netflix.loadbalancer.ServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) EurekaNotificationServerListUpdater(com.netflix.niws.loadbalancer.EurekaNotificationServerListUpdater) AvailabilityFilteringRule(com.netflix.loadbalancer.AvailabilityFilteringRule) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl)

Example 18 with EurekaClient

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")));
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient) Test(org.junit.Test)

Example 19 with EurekaClient

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"));
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient) CloudEurekaClient(org.springframework.cloud.netflix.eureka.CloudEurekaClient) ConfigClientProperties(org.springframework.cloud.config.client.ConfigClientProperties) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 20 with EurekaClient

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();
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) MyDataCenterInstanceConfig(com.netflix.appinfo.MyDataCenterInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager)

Aggregations

EurekaClient (com.netflix.discovery.EurekaClient)21 Test (org.junit.Test)13 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)7 DiscoveryClient (com.netflix.discovery.DiscoveryClient)6 ServerListUpdater (com.netflix.loadbalancer.ServerListUpdater)6 EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)5 InstanceInfo (com.netflix.appinfo.InstanceInfo)5 CacheRefreshedEvent (com.netflix.discovery.CacheRefreshedEvent)5 EurekaEventListener (com.netflix.discovery.EurekaEventListener)5 Capture (org.easymock.Capture)5 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)4 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)2 Injector (com.google.inject.Injector)1 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1