use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.
the class BackUpRegistryTest method setUp.
public void setUp(boolean enableRemote) throws Exception {
ConfigurationManager.getConfigInstance().setProperty("eureka.client.refresh.interval", CLIENT_REFRESH_RATE);
ConfigurationManager.getConfigInstance().setProperty("eureka.registration.enabled", "false");
if (enableRemote) {
ConfigurationManager.getConfigInstance().setProperty("eureka.fetchRemoteRegionsRegistry", REMOTE_REGION);
}
ConfigurationManager.getConfigInstance().setProperty("eureka.myregion.availabilityZones", REMOTE_ZONE);
ConfigurationManager.getConfigInstance().setProperty("eureka.backupregistry", MockBackupRegistry.class.getName());
ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + NOT_AVAILABLE_EUREKA_PORT + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
builder.setIPAddr("10.10.101.00");
builder.setHostName("Hosttt");
builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
builder.setDataCenterInfo(new DataCenterInfo() {
@Override
public Name getName() {
return Name.MyOwn;
}
});
ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
backupRegistry = new MockBackupRegistry();
setupBackupMock();
client = new DiscoveryClient(applicationInfoManager, new DefaultEurekaClientConfig(), null, Providers.of((BackupRegistry) backupRegistry));
}
use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.
the class AbstractTester method setUp.
@Before
public void setUp() throws Exception {
ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion.global.appWhiteList");
ConfigurationManager.getConfigInstance().setProperty("eureka.responseCacheAutoExpirationInSeconds", "10");
ConfigurationManager.getConfigInstance().clearProperty("eureka.remoteRegion." + REMOTE_REGION_NAME + ".appWhiteList");
ConfigurationManager.getConfigInstance().setProperty("eureka.deltaRetentionTimerIntervalInMs", "600000");
ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegion.registryFetchIntervalInSeconds", "5");
populateRemoteRegistryAtStartup();
mockRemoteEurekaServer = newMockRemoteServer();
mockRemoteEurekaServer.start();
ConfigurationManager.getConfigInstance().setProperty("eureka.remoteRegionUrlsWithName", REMOTE_REGION_NAME + ";http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
serverConfig = spy(new DefaultEurekaServerConfig());
InstanceInfo.Builder builder = InstanceInfo.Builder.newBuilder();
builder.setIPAddr("10.10.101.00");
builder.setHostName("Hosttt");
builder.setAppName("EurekaTestApp-" + UUID.randomUUID());
builder.setLeaseInfo(LeaseInfo.Builder.newBuilder().build());
builder.setDataCenterInfo(getDataCenterInfo());
ConfigurationManager.getConfigInstance().setProperty("eureka.serviceUrl.default", "http://localhost:" + mockRemoteEurekaServer.getPort() + MockRemoteEurekaServer.EUREKA_API_BASE_PATH);
DefaultEurekaClientConfig clientConfig = new DefaultEurekaClientConfig();
// setup config in advance, used in initialize converter
ApplicationInfoManager applicationInfoManager = new ApplicationInfoManager(new MyDataCenterInstanceConfig(), builder.build());
client = new DiscoveryClient(applicationInfoManager, clientConfig);
ServerCodecs serverCodecs = new DefaultServerCodecs(serverConfig);
registry = makePeerAwareInstanceRegistry(serverConfig, clientConfig, serverCodecs, client);
serverContext = new DefaultEurekaServerContext(serverConfig, serverCodecs, registry, mock(PeerEurekaNodes.class), applicationInfoManager);
serverContext.initialize();
}
use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.
the class ExampleEurekaClient method main.
public static void main(String[] args) {
ExampleEurekaClient sampleClient = new ExampleEurekaClient();
// create the client
ApplicationInfoManager applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
EurekaClient client = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
// use the client
sampleClient.sendRequestToServiceUsingEureka(client);
// shutdown the client
eurekaClient.shutdown();
}
use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.
the class ExampleEurekaClient method initializeApplicationInfoManager.
private static synchronized ApplicationInfoManager initializeApplicationInfoManager(EurekaInstanceConfig instanceConfig) {
if (applicationInfoManager == null) {
InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
}
return applicationInfoManager;
}
use of com.netflix.appinfo.ApplicationInfoManager in project eureka by Netflix.
the class StatusUtilTest method getStatusUtil.
/**
* @param replicas the number of replicas to mock
* @param instances the number of instances to mock
* @param minimum the minimum number of peers
* @return the status utility with the mocked replicas/instances
*/
private StatusUtil getStatusUtil(int replicas, int instances, int minimum) {
EurekaServerContext mockEurekaServerContext = mock(EurekaServerContext.class);
List<InstanceInfo> mockInstanceInfos = getMockInstanceInfos(instances);
Application mockApplication = mock(Application.class);
when(mockApplication.getInstances()).thenReturn(mockInstanceInfos);
ApplicationInfoManager mockAppInfoManager = mock(ApplicationInfoManager.class);
when(mockAppInfoManager.getInfo()).thenReturn(mockInstanceInfos.get(0));
when(mockEurekaServerContext.getApplicationInfoManager()).thenReturn(mockAppInfoManager);
PeerAwareInstanceRegistry mockRegistry = mock(PeerAwareInstanceRegistry.class);
when(mockRegistry.getApplication("stuff", false)).thenReturn(mockApplication);
when(mockEurekaServerContext.getRegistry()).thenReturn(mockRegistry);
List<PeerEurekaNode> mockNodes = getMockNodes(replicas);
EurekaTransportConfig mockTransportConfig = mock(EurekaTransportConfig.class);
when(mockTransportConfig.applicationsResolverUseIp()).thenReturn(false);
EurekaClientConfig mockClientConfig = mock(EurekaClientConfig.class);
when(mockClientConfig.getTransportConfig()).thenReturn(mockTransportConfig);
EurekaServerConfig mockServerConfig = mock(EurekaServerConfig.class);
when(mockServerConfig.getHealthStatusMinNumberOfAvailablePeers()).thenReturn(minimum);
PeerEurekaNodes peerEurekaNodes = new PeerEurekaNodes(mockRegistry, mockServerConfig, mockClientConfig, null, mockAppInfoManager);
PeerEurekaNodes spyPeerEurekaNodes = spy(peerEurekaNodes);
when(spyPeerEurekaNodes.getPeerEurekaNodes()).thenReturn(mockNodes);
when(mockEurekaServerContext.getPeerEurekaNodes()).thenReturn(spyPeerEurekaNodes);
return new StatusUtil(mockEurekaServerContext);
}
Aggregations