use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.
the class EurekaClientModuleConfigurationTest method testBindEurekaInstanceConfigFactory.
@Test
public void testBindEurekaInstanceConfigFactory() {
final EurekaInstanceConfigFactory mockFactory = Mockito.mock(EurekaInstanceConfigFactory.class);
final EurekaInstanceConfig mockConfig = Mockito.mock(EurekaInstanceConfig.class);
final ApplicationInfoManager mockInfoManager = Mockito.mock(ApplicationInfoManager.class);
Mockito.when(mockFactory.get()).thenReturn(mockConfig);
LifecycleInjector injector = InjectorBuilder.fromModules(new ArchaiusModule(), new EurekaClientModule() {
@Override
protected void configureEureka() {
bindEurekaInstanceConfigFactory().toInstance(mockFactory);
}
}).overrideWith(new AbstractModule() {
@Override
protected void configure() {
// this is usually bound as an eager singleton that can trigger other parts to
// initialize, so do an override to a mock here to prevent that.
bind(ApplicationInfoManager.class).toInstance(mockInfoManager);
}
}).createInjector();
EurekaInstanceConfig config = injector.getInstance(EurekaInstanceConfig.class);
Assert.assertEquals(mockConfig, config);
}
use of com.netflix.appinfo.EurekaInstanceConfig 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());
}
use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.
the class Jersey2EurekaModuleTest 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 Jersey2EurekaModule()).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 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());
}
use of com.netflix.appinfo.EurekaInstanceConfig in project eureka by Netflix.
the class EurekaBootStrap method initEurekaServerContext.
/**
* init hook for server context. Override for custom logic.
*/
protected void initEurekaServerContext() throws Exception {
EurekaServerConfig eurekaServerConfig = new DefaultEurekaServerConfig();
// For backward compatibility
JsonXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
XmlXStream.getInstance().registerConverter(new V1AwareInstanceInfoConverter(), XStream.PRIORITY_VERY_HIGH);
logger.info("Initializing the eureka client...");
logger.info(eurekaServerConfig.getJsonCodecName());
ServerCodecs serverCodecs = new DefaultServerCodecs(eurekaServerConfig);
ApplicationInfoManager applicationInfoManager = null;
if (eurekaClient == null) {
EurekaInstanceConfig instanceConfig = isCloud(ConfigurationManager.getDeploymentContext()) ? new CloudInstanceConfig() : new MyDataCenterInstanceConfig();
applicationInfoManager = new ApplicationInfoManager(instanceConfig, new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get());
EurekaClientConfig eurekaClientConfig = new DefaultEurekaClientConfig();
eurekaClient = new DiscoveryClient(applicationInfoManager, eurekaClientConfig);
} else {
applicationInfoManager = eurekaClient.getApplicationInfoManager();
}
PeerAwareInstanceRegistry registry;
if (isAws(applicationInfoManager.getInfo())) {
registry = new AwsInstanceRegistry(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
awsBinder = new AwsBinderDelegate(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), registry, applicationInfoManager);
awsBinder.start();
} else {
registry = new PeerAwareInstanceRegistryImpl(eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, eurekaClient);
}
PeerEurekaNodes peerEurekaNodes = getPeerEurekaNodes(registry, eurekaServerConfig, eurekaClient.getEurekaClientConfig(), serverCodecs, applicationInfoManager);
serverContext = new DefaultEurekaServerContext(eurekaServerConfig, serverCodecs, registry, peerEurekaNodes, applicationInfoManager);
EurekaServerContextHolder.initialize(serverContext);
serverContext.initialize();
logger.info("Initialized server context");
// Copy registry from neighboring eureka node
int registryCount = registry.syncUp();
registry.openForTraffic(applicationInfoManager, registryCount);
// Register all monitoring statistics.
EurekaMonitors.registerAllStats();
}
Aggregations