use of com.netflix.discovery.DiscoveryManager in project ribbon by Netflix.
the class DiscoveryEnabledLoadBalancerSupportsPortOverrideTest method setupMock.
@Before
public void setupMock() {
List<InstanceInfo> dummyII = getDummyInstanceInfo("dummy", "http://www.host.com", "1.1.1.1", 8001);
List<InstanceInfo> secureDummyII = getDummyInstanceInfo("secureDummy", "http://www.host.com", "1.1.1.1", 8002);
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(dummyII).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("secureDummy", true, "region")).andReturn(secureDummyII).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
use of com.netflix.discovery.DiscoveryManager in project chassis by Kixeye.
the class EurekaConfiguration method eurekaDiscoveryManager.
/***
* Initializes Eureka Client Library (aka DiscoveryManager)
*
* @return discovery manager bean
*/
@Bean(destroyMethod = "shutdownComponent")
public DiscoveryManager eurekaDiscoveryManager(MetadataCollector metadataCollector) {
final DiscoveryManager bean = DiscoveryManager.getInstance();
if (!disableEureka) {
// set eureka.port via http.port if not already set
int httpPort = ConfigurationManager.getConfigInstance().getInt("http.port", -1);
int httpsPort = ConfigurationManager.getConfigInstance().getInt("https.port", -1);
int eurekaPort = ConfigurationManager.getConfigInstance().getInt("eureka.port", -1);
int eurekaSecurePort = ConfigurationManager.getConfigInstance().getInt("eureka.securePort", -1);
boolean httpPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("http.enabled", false);
boolean httpsPortEnabled = ConfigurationManager.getConfigInstance().getBoolean("https.enabled", false);
if (httpPort != -1 && eurekaPort == -1) {
ConfigurationManager.getConfigInstance().setProperty("eureka.port", httpPort);
ConfigurationManager.getConfigInstance().setProperty("eureka.port.enabled", httpPortEnabled);
}
if (httpsPort != -1 && eurekaSecurePort == -1) {
ConfigurationManager.getConfigInstance().setProperty("eureka.securePort", httpsPort);
ConfigurationManager.getConfigInstance().setProperty("eureka.securePort.enabled", httpsPortEnabled);
}
// set eureka.name and eureka.vipAddress with @SpringApp name if not already set
String appName = ConfigurationManager.getConfigInstance().getString("app.name", null);
String eurekaName = ConfigurationManager.getConfigInstance().getString("eureka.name", null);
String eurekaVip = ConfigurationManager.getConfigInstance().getString("eureka.vipAddress", null);
String eurekaSecureVipAddress = ConfigurationManager.getConfigInstance().getString("eureka.secureVipAddress", null);
if (appName != null && eurekaName == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.name", appName);
}
if (appName != null && eurekaVip == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.vipAddress", appName);
}
if (appName != null && eurekaSecureVipAddress == null) {
ConfigurationManager.getConfigInstance().setProperty("eureka.secureVipAddress", appName);
}
// initialize DiscoveryManager if it hasn't already been done
if (ApplicationInfoManager.getInstance().getInfo() == null) {
EurekaInstanceConfig config;
switch(datacenter.toLowerCase()) {
case "amazon":
case "cloud":
config = new KixeyeCloudInstanceConfig(metadataCollector);
break;
default:
config = new KixeyeMyDataCenterInstanceConfig(metadataCollector);
break;
}
bean.initComponent(config, new DefaultEurekaClientConfig());
}
}
return bean;
}
use of com.netflix.discovery.DiscoveryManager in project ribbon by Netflix.
the class DiscoveryEnabledLoadBalancerSupportsUseIpAddrTest method setupMock.
@Before
public void setupMock() {
List<InstanceInfo> servers = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST1, IP1, 8080);
List<InstanceInfo> servers2 = DiscoveryEnabledLoadBalancerSupportsPortOverrideTest.getDummyInstanceInfo("dummy", HOST2, IP2, 8080);
servers.addAll(servers2);
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy", false, "region")).andReturn(servers).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
use of com.netflix.discovery.DiscoveryManager in project ribbon by Netflix.
the class LBBuilderTest method setupMock.
@Before
public void setupMock() {
List<InstanceInfo> instances = getDummyInstanceInfo("dummy", expected.getHost(), expected.getPort());
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress("dummy:7001", false, null)).andReturn(instances).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
use of com.netflix.discovery.DiscoveryManager in project ribbon by Netflix.
the class MockedDiscoveryServerListTest method setupMock.
@Before
public void setupMock() {
List<InstanceInfo> instances = getDummyInstanceInfo("dummy", getMockServerList());
PowerMock.mockStatic(DiscoveryManager.class);
PowerMock.mockStatic(DiscoveryClient.class);
DiscoveryClient mockedDiscoveryClient = createMock(DiscoveryClient.class);
DiscoveryManager mockedDiscoveryManager = createMock(DiscoveryManager.class);
expect(DiscoveryClient.getZone((InstanceInfo) EasyMock.anyObject())).andReturn("dummyZone").anyTimes();
expect(DiscoveryManager.getInstance()).andReturn(mockedDiscoveryManager).anyTimes();
expect(mockedDiscoveryManager.getDiscoveryClient()).andReturn(mockedDiscoveryClient).anyTimes();
expect(mockedDiscoveryClient.getInstancesByVipAddress(getVipAddress(), false, null)).andReturn(instances).anyTimes();
replay(DiscoveryManager.class);
replay(DiscoveryClient.class);
replay(mockedDiscoveryManager);
replay(mockedDiscoveryClient);
}
Aggregations