Search in sources :

Example 6 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.

the class EurekaModuleTest method setUp.

@Before
public void setUp() throws Exception {
    ConfigurationManager.getConfigInstance().setProperty("eureka.region", "default");
    ConfigurationManager.getConfigInstance().setProperty("eureka.shouldFetchRegistry", "false");
    ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
    ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:8080/eureka/v2");
    injector = InjectorBuilder.fromModule(new EurekaModule()).overrideWith(new AbstractModule() {

        @Override
        protected void configure() {
            // the default impl of EurekaInstanceConfig is CloudInstanceConfig, which we only want in an AWS
            // environment. Here we override that by binding MyDataCenterInstanceConfig to EurekaInstanceConfig.
            bind(EurekaInstanceConfig.class).toProvider(MyDataCenterInstanceConfigProvider.class).in(Scopes.SINGLETON);
        }
    }).createInjector();
}
Also used : EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) AbstractModule(com.google.inject.AbstractModule) Before(org.junit.Before)

Example 7 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.

the class EurekaModuleTest method testDI.

@SuppressWarnings("deprecation")
@Test
public void testDI() {
    InstanceInfo instanceInfo = injector.getInstance(InstanceInfo.class);
    Assert.assertEquals(ApplicationInfoManager.getInstance().getInfo(), instanceInfo);
    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);
    Binding<TransportClientFactories> binding = injector.getExistingBinding(Key.get(TransportClientFactories.class));
    // no bindings so defaulting to default of jersey1
    Assert.assertNull(binding);
}
Also used : EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) EurekaClient(com.netflix.discovery.EurekaClient) DiscoveryClient(com.netflix.discovery.DiscoveryClient) TransportClientFactories(com.netflix.discovery.shared.transport.jersey.TransportClientFactories) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 8 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project riposte by Nike-Inc.

the class EurekaHandlerTest method createEurekaInstanceConfig_returns_CloudInstanceConfig_when_datacenterType_is_amazon_or_netflix.

@DataProvider(value = { "Amazon", "Netflix" })
@Test
public void createEurekaInstanceConfig_returns_CloudInstanceConfig_when_datacenterType_is_amazon_or_netflix(String datacenterType) {
    // given
    doReturn(datacenterType).when(datacenterTypePropertySupplierMock).get();
    // when
    EurekaInstanceConfig instanceConfig = handlerSpy.createEurekaInstanceConfig();
    // then
    verify(handlerSpy).createCloudInstanceConfig(handlerSpy.eurekaNamespace);
    assertThat(instanceConfig).isSameAs(cloudInstanceConfigMock);
}
Also used : EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 9 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project riposte by Nike-Inc.

the class EurekaHandlerTest method register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP.

@Test
public void register_uses_createEurekaInstanceConfig_then_calls_initDiscoveryManager_with_it_and_sets_instance_status_UP() {
    // given
    EurekaInstanceConfig instanceConfigMock = mock(EurekaInstanceConfig.class);
    doReturn(instanceConfigMock).when(handlerSpy).createEurekaInstanceConfig();
    assertThat(handlerSpy.registered.get()).isFalse();
    // when
    handlerSpy.register();
    // then
    assertThat(handlerSpy.registered.get()).isTrue();
    verify(handlerSpy).createEurekaInstanceConfig();
    ArgumentCaptor<EurekaClientConfig> clientConfigCaptor = ArgumentCaptor.forClass(EurekaClientConfig.class);
    verify(handlerSpy).initDiscoveryManager(eq(instanceConfigMock), clientConfigCaptor.capture());
    EurekaClientConfig clientConfigUsed = clientConfigCaptor.getValue();
    assertThat(clientConfigUsed).isInstanceOf(DefaultEurekaClientConfig.class);
    assertThat(Whitebox.getInternalState(clientConfigUsed, "namespace")).isEqualTo(handlerSpy.eurekaClientNamespace);
    verify(handlerSpy).setEurekaInstanceStatus(InstanceStatus.UP);
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaClientConfig(com.netflix.discovery.EurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig) Test(org.junit.Test)

Example 10 with EurekaInstanceConfig

use of com.netflix.appinfo.EurekaInstanceConfig in project riposte by Nike-Inc.

the class EurekaHandler method register.

public void register() {
    if (isEurekaDisabled()) {
        logger.info("Eureka is disabled, skipping instance's eureka registration.");
        return;
    }
    if (!registered.compareAndSet(false, true)) {
        logger.info("Eureka handler already registered, skipping registration.");
        return;
    }
    EurekaInstanceConfig eurekaInstanceConfig = createEurekaInstanceConfig();
    initDiscoveryManager(eurekaInstanceConfig, new DefaultEurekaClientConfig(eurekaClientNamespace));
    setEurekaInstanceStatus(InstanceInfo.InstanceStatus.UP);
}
Also used : DefaultEurekaClientConfig(com.netflix.discovery.DefaultEurekaClientConfig) EurekaInstanceConfig(com.netflix.appinfo.EurekaInstanceConfig)

Aggregations

EurekaInstanceConfig (com.netflix.appinfo.EurekaInstanceConfig)16 Test (org.junit.Test)8 EurekaClientConfig (com.netflix.discovery.EurekaClientConfig)6 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)5 DiscoveryClient (com.netflix.discovery.DiscoveryClient)5 AbstractModule (com.google.inject.AbstractModule)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)4 DefaultEurekaClientConfig (com.netflix.discovery.DefaultEurekaClientConfig)4 EurekaClient (com.netflix.discovery.EurekaClient)4 MyDataCenterInstanceConfig (com.netflix.appinfo.MyDataCenterInstanceConfig)3 Archaius2VipAddressResolver (com.netflix.appinfo.providers.Archaius2VipAddressResolver)2 VipAddressResolver (com.netflix.appinfo.providers.VipAddressResolver)2 TransportClientFactories (com.netflix.discovery.shared.transport.jersey.TransportClientFactories)2 LifecycleInjector (com.netflix.governator.LifecycleInjector)2 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)2 Before (org.junit.Before)2 AmazonInfo (com.netflix.appinfo.AmazonInfo)1 CloudInstanceConfig (com.netflix.appinfo.CloudInstanceConfig)1 DataCenterInfo (com.netflix.appinfo.DataCenterInfo)1 Ec2EurekaArchaius2InstanceConfig (com.netflix.appinfo.Ec2EurekaArchaius2InstanceConfig)1