Search in sources :

Example 21 with Applications

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());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Test(org.junit.Test)

Example 22 with Applications

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());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 23 with Applications

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();
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 24 with Applications

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();
        }
    }
}
Also used : ClosableResolver(com.netflix.discovery.shared.resolver.ClosableResolver) ApplicationsResolver(com.netflix.discovery.shared.resolver.aws.ApplicationsResolver) EurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver) TestEurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver) Applications(com.netflix.discovery.shared.Applications) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) TestEurekaHttpResolver(com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver) Test(org.junit.Test)

Example 25 with Applications

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);
    }
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

Applications (com.netflix.discovery.shared.Applications)85 Test (org.junit.Test)43 Application (com.netflix.discovery.shared.Application)25 InstanceInfo (com.netflix.appinfo.InstanceInfo)22 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)11 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)10 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)8 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)6 List (java.util.List)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)5 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 Response (javax.ws.rs.core.Response)4 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 Map (java.util.Map)3