use of com.netflix.discovery.shared.resolver.aws.AwsEndpoint in project eureka by Netflix.
the class EurekaHttpClientsTest method testCompositeBootstrapResolver.
@Test
public void testCompositeBootstrapResolver() throws Exception {
Applications applications = InstanceInfoGenerator.newBuilder(5, "eurekaWrite", "someOther").build().toApplications();
Applications applications2 = InstanceInfoGenerator.newBuilder(2, "eurekaWrite", "someOther").build().toApplications();
String vipAddress = applications.getRegisteredApplications("eurekaWrite").getInstances().get(0).getVIPAddress();
// setup client config to use fixed root ips for testing
when(clientConfig.shouldUseDnsForFetchingServiceUrls()).thenReturn(false);
// can use anything here
when(clientConfig.getEurekaServerServiceUrls(anyString())).thenReturn(Arrays.asList("http://foo:0"));
when(clientConfig.getRegion()).thenReturn("us-east-1");
when(transportConfig.getWriteClusterVip()).thenReturn(vipAddress);
when(transportConfig.getAsyncExecutorThreadPoolSize()).thenReturn(4);
when(transportConfig.getAsyncResolverRefreshIntervalMs()).thenReturn(400);
when(transportConfig.getAsyncResolverWarmUpTimeoutMs()).thenReturn(400);
ApplicationsResolver.ApplicationsSource applicationsSource = mock(ApplicationsResolver.ApplicationsSource.class);
when(applicationsSource.getApplications(anyInt(), eq(TimeUnit.SECONDS))).thenReturn(// first time
null).thenReturn(// second time
applications).thenReturn(// subsequent times
null);
EurekaHttpClient mockHttpClient = mock(EurekaHttpClient.class);
when(mockHttpClient.getVip(eq(vipAddress))).thenReturn(anEurekaHttpResponse(200, applications).build()).thenReturn(// contains diff number of servers
anEurekaHttpResponse(200, applications2).build());
TransportClientFactory transportClientFactory = mock(TransportClientFactory.class);
when(transportClientFactory.newClient(any(EurekaEndpoint.class))).thenReturn(mockHttpClient);
ClosableResolver<AwsEndpoint> resolver = null;
try {
resolver = EurekaHttpClients.compositeBootstrapResolver(clientConfig, transportConfig, transportClientFactory, applicationInfoManager.getInfo(), applicationsSource);
List endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications.getInstancesByVirtualHostName(vipAddress).size()));
// 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()));
// wait for the third cycle that triggers the mock http client (which is the third resolver cycle)
// for the third cycle we have mocked the application resolver to return null data so should fall back
// to calling the remote resolver again (which should return applications2)
verify(mockHttpClient, timeout(3000).times(3)).getVip(anyString());
endpoints = resolver.getClusterEndpoints();
assertThat(endpoints.size(), equalTo(applications2.getInstancesByVirtualHostName(vipAddress).size()));
} finally {
if (resolver != null) {
resolver.shutdown();
}
}
}
Aggregations