Search in sources :

Example 6 with EurekaClient

use of com.netflix.discovery.EurekaClient in project ribbon by Netflix.

the class EurekaDynamicServerListLoadBalancerTest method setUpEurekaClientMock.

private EurekaClient setUpEurekaClientMock(List<InstanceInfo> servers) {
    final EurekaClient eurekaClientMock = PowerMock.createMock(EurekaClient.class);
    EasyMock.expect(eurekaClientMock.getInstancesByVipAddress(EasyMock.anyString(), EasyMock.anyBoolean(), EasyMock.anyString())).andReturn(servers.subList(0, initialServerListSize)).times(1).andReturn(servers.subList(initialServerListSize, servers.size())).anyTimes();
    EasyMock.expectLastCall();
    EasyMock.expect(eurekaClientMock.unregisterEventListener(EasyMock.isA(EurekaEventListener.class))).andReturn(true).anyTimes();
    return eurekaClientMock;
}
Also used : EurekaClient(com.netflix.discovery.EurekaClient)

Example 7 with EurekaClient

use of com.netflix.discovery.EurekaClient in project iep by Netflix.

the class EurekaModuleTest method getEurekaClient.

@Test
public void getEurekaClient() throws Exception {
    Injector injector = Guice.createInjector(new EurekaModule());
    EurekaClient client = injector.getInstance(EurekaClient.class);
    Assert.assertNotNull(client);
}
Also used : Injector(com.google.inject.Injector) EurekaClient(com.netflix.discovery.EurekaClient) Test(org.junit.Test)

Example 8 with EurekaClient

use of com.netflix.discovery.EurekaClient in project hazelcast-eureka by hazelcast.

the class HazelcastClientTestCase method testInstanceRegistrationUsingProvidedEurekaClient.

@Test
public void testInstanceRegistrationUsingProvidedEurekaClient() {
    EurekaClient eurekaClient = mock(EurekaClient.class);
    ApplicationInfoManager applicationInfoManager = mock(ApplicationInfoManager.class);
    EurekaInstanceConfig eurekaInstanceConfig = mock(EurekaInstanceConfig.class);
    when(eurekaClient.getApplicationInfoManager()).thenReturn(applicationInfoManager);
    when(eurekaClient.getApplication(anyString())).thenReturn(new Application(APP_NAME));
    when(applicationInfoManager.getEurekaInstanceConfig()).thenReturn(eurekaInstanceConfig);
    when(eurekaInstanceConfig.getAppname()).thenReturn(APP_NAME);
    // use provided EurekaClient
    EurekaOneDiscoveryStrategyFactory.setEurekaClient(eurekaClient);
    HazelcastInstance hz1 = factory.newHazelcastInstance();
    HazelcastInstance hz2 = factory.newHazelcastInstance();
    verify(eurekaClient, times(2)).getApplicationInfoManager();
    verify(eurekaClient, times(2)).getApplication(APP_NAME);
    verify(applicationInfoManager, never()).setInstanceStatus(InstanceStatus.UP);
    verify(applicationInfoManager, never()).setInstanceStatus(any(InstanceStatus.class));
    assertClusterSizeEventually(2, hz1);
    assertClusterSizeEventually(2, hz2);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) InstanceStatus(com.netflix.appinfo.InstanceInfo.InstanceStatus) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) Application(com.netflix.discovery.shared.Application) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 9 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class Ec2EurekaClientModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
    Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Assert.assertTrue(eurekaInstanceConfig instanceof Ec2EurekaArchaius2InstanceConfig);
    ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
    InstanceInfo myInfo = applicationInfoManager.getInfo();
    Assert.assertTrue(myInfo.getDataCenterInfo() instanceof AmazonInfo);
    Assert.assertEquals(DataCenterInfo.Name.Amazon, myInfo.getDataCenterInfo().getName());
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) Ec2EurekaArchaius2InstanceConfig(com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) VipAddressResolver(com.netflix.appinfo.providers.VipAddressResolver) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) AmazonInfo(com.netflix.appinfo.AmazonInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

Example 10 with EurekaClient

use of com.netflix.discovery.EurekaClient in project eureka by Netflix.

the class NonEc2EurekaClientModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    VipAddressResolver vipAddressResolver = injector.getInstance(VipAddressResolver.class);
    Assert.assertTrue(vipAddressResolver instanceof Archaius2VipAddressResolver);
    EurekaClient eurekaClient = injector.getInstance(EurekaClient.class);
    DiscoveryClient discoveryClient = injector.getInstance(DiscoveryClient.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClient(), eurekaClient);
    Assert.assertEquals(DiscoveryManager.getInstance().getDiscoveryClient(), discoveryClient);
    Assert.assertEquals(eurekaClient, discoveryClient);
    EurekaClientConfig eurekaClientConfig = injector.getInstance(EurekaClientConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaClientConfig(), eurekaClientConfig);
    EurekaInstanceConfig eurekaInstanceConfig = injector.getInstance(EurekaInstanceConfig.class);
    Assert.assertEquals(DiscoveryManager.getInstance().getEurekaInstanceConfig(), eurekaInstanceConfig);
    Assert.assertTrue(eurekaInstanceConfig instanceof EurekaArchaius2InstanceConfig);
    ApplicationInfoManager applicationInfoManager = injector.getInstance(ApplicationInfoManager.class);
    InstanceInfo myInfo = applicationInfoManager.getInfo();
    Assert.assertEquals(DataCenterInfo.Name.MyOwn, myInfo.getDataCenterInfo().getName());
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaArchaius2InstanceConfig(com.netflix.appinfo.EurekaArchaius2InstanceConfig) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) VipAddressResolver(com.netflix.appinfo.providers.VipAddressResolver) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) InstanceInfo(com.netflix.appinfo.InstanceInfo) Archaius2VipAddressResolver(com.netflix.appinfo.providers.Archaius2VipAddressResolver) ApplicationInfoManager(com.netflix.appinfo.ApplicationInfoManager) Test(org.junit.Test)

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