use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class BackUpRegistryTest method testAppsHashCode.
@Test
public void testAppsHashCode() throws Exception {
setUp(true);
Applications applications = client.getApplications();
Assert.assertEquals("UP_1_", applications.getAppsHashCode());
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class BackUpRegistryTest method testRemoteEnabledButLocalOnlyQueried.
@Test
public void testRemoteEnabledButLocalOnlyQueried() throws Exception {
setUp(true);
Applications applications = client.getApplications();
List<Application> registeredApplications = applications.getRegisteredApplications();
Assert.assertNotNull("Local region apps not found.", registeredApplications);
// Remote region comes with no instances.
Assert.assertEquals("Local apps size not as expected.", 2, registeredApplications.size());
Application localRegionApp = null;
Application remoteRegionApp = null;
for (Application registeredApplication : registeredApplications) {
if (registeredApplication.getName().equals(LOCAL_REGION_APP_NAME)) {
localRegionApp = registeredApplication;
} else if (registeredApplication.getName().equals(REMOTE_REGION_APP_NAME)) {
remoteRegionApp = registeredApplication;
}
}
Assert.assertNotNull("Local region apps not present.", localRegionApp);
Assert.assertTrue("Remote region instances returned for local query.", null == remoteRegionApp || remoteRegionApp.getInstances().isEmpty());
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpResolverTest method testNoValidDataFromRemoteServer.
@Test
public void testNoValidDataFromRemoteServer() {
Applications newApplications = new Applications();
for (Application application : applications.getRegisteredApplications()) {
if (!application.getInstances().get(0).getVIPAddress().equals(vipAddress)) {
newApplications.addApplication(application);
}
}
when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, newApplications).build());
List<AwsEndpoint> endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.isEmpty(), is(true));
verify(httpClient, times(1)).shutdown();
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpClientsTest method testCanonicalResolver.
@Test
public void testCanonicalResolver() throws Exception {
when(clientConfig.getEurekaServerURLContext()).thenReturn("context");
when(clientConfig.getRegion()).thenReturn("region");
when(transportConfig.getAsyncExecutorThreadPoolSize()).thenReturn(3);
when(transportConfig.getAsyncResolverRefreshIntervalMs()).thenReturn(400);
when(transportConfig.getAsyncResolverWarmUpTimeoutMs()).thenReturn(400);
Applications applications = InstanceInfoGenerator.newBuilder(5, "eurekaRead", "someOther").build().toApplications();
String vipAddress = applications.getRegisteredApplications("eurekaRead").getInstances().get(0).getVIPAddress();
ApplicationsResolver.ApplicationsSource applicationsSource = mock(ApplicationsResolver.ApplicationsSource.class);
when(applicationsSource.getApplications(anyInt(), eq(TimeUnit.SECONDS))).thenReturn(// first time
null).thenReturn(// subsequent times
applications);
EurekaHttpClientFactory remoteResolverClientFactory = mock(EurekaHttpClientFactory.class);
EurekaHttpClient httpClient = mock(EurekaHttpClient.class);
when(remoteResolverClientFactory.newClient()).thenReturn(httpClient);
when(httpClient.getVip(vipAddress)).thenReturn(EurekaHttpResponse.anEurekaHttpResponse(200, applications).build());
EurekaHttpResolver remoteResolver = spy(new TestEurekaHttpResolver(clientConfig, transportConfig, remoteResolverClientFactory, vipAddress));
when(transportConfig.getReadClusterVip()).thenReturn(vipAddress);
ApplicationsResolver localResolver = spy(new ApplicationsResolver(clientConfig, transportConfig, applicationsSource, transportConfig.getReadClusterVip()));
ClosableResolver resolver = null;
try {
resolver = EurekaHttpClients.compositeQueryResolver(remoteResolver, localResolver, clientConfig, transportConfig, applicationInfoManager.getInfo());
List endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
verify(remoteResolver, times(1)).getClusterEndpoints();
verify(localResolver, times(1)).getClusterEndpoints();
// wait for the second cycle that hits the app source
verify(applicationsSource, timeout(3000).times(2)).getApplications(anyInt(), eq(TimeUnit.SECONDS));
endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
verify(remoteResolver, times(1)).getClusterEndpoints();
verify(localResolver, times(2)).getClusterEndpoints();
} finally {
if (resolver != null) {
resolver.shutdown();
}
}
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class PeerAwareInstanceRegistryImpl method updateRenewalThreshold.
/**
* Updates the <em>renewal threshold</em> based on the current number of
* renewals. The threshold is a percentage as specified in
* {@link EurekaServerConfig#getRenewalPercentThreshold()} of renewals
* received per minute {@link #getNumOfRenewsInLastMin()}.
*/
private void updateRenewalThreshold() {
try {
Applications apps = eurekaClient.getApplications();
int count = 0;
for (Application app : apps.getRegisteredApplications()) {
for (InstanceInfo instance : app.getInstances()) {
if (this.isRegisterable(instance)) {
++count;
}
}
}
synchronized (lock) {
// current expected threshold of if the self preservation is disabled.
if ((count * 2) > (serverConfig.getRenewalPercentThreshold() * numberOfRenewsPerMinThreshold) || (!this.isSelfPreservationModeEnabled())) {
this.expectedNumberOfRenewsPerMin = count * 2;
this.numberOfRenewsPerMinThreshold = (int) ((count * 2) * serverConfig.getRenewalPercentThreshold());
}
}
logger.info("Current renewal threshold is : {}", numberOfRenewsPerMinThreshold);
} catch (Throwable e) {
logger.error("Cannot update renewal threshold", e);
}
}
Aggregations