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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations