Search in sources :

Example 1 with TestEurekaHttpResolver

use of com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver 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(), randomizer);
        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)

Aggregations

Applications (com.netflix.discovery.shared.Applications)1 ClosableResolver (com.netflix.discovery.shared.resolver.ClosableResolver)1 ApplicationsResolver (com.netflix.discovery.shared.resolver.aws.ApplicationsResolver)1 EurekaHttpResolver (com.netflix.discovery.shared.resolver.aws.EurekaHttpResolver)1 TestEurekaHttpResolver (com.netflix.discovery.shared.resolver.aws.TestEurekaHttpResolver)1 List (java.util.List)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1