use of com.netflix.discovery.junit.resource.DiscoveryClientResource in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testEurekaClientPeriodicHeartbeat.
@Test
public void testEurekaClientPeriodicHeartbeat() throws Exception {
DiscoveryClientResource registeringClientResource = discoveryClientResource.fork().withRegistration(true).withRegistryFetch(false).build();
InstanceInfo instance = registeringClientResource.getMyInstanceInfo();
when(requestHandler.register(any(InstanceInfo.class))).thenReturn(EurekaHttpResponse.status(204));
when(requestHandler.sendHeartBeat(instance.getAppName(), instance.getId(), null, null)).thenReturn(anEurekaHttpResponse(200, InstanceInfo.class).build());
// Initialize
registeringClientResource.getClient();
verify(requestHandler, timeout(5 * 1000).atLeast(2)).sendHeartBeat(instance.getAppName(), instance.getId(), null, null);
}
use of com.netflix.discovery.junit.resource.DiscoveryClientResource in project eureka by Netflix.
the class DiscoveryClientRegistryTest method testCacheRefreshSingleAppForLocalRegion.
@Test
public void testCacheRefreshSingleAppForLocalRegion() throws Exception {
InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
Applications initialApps = instanceGen.takeDelta(1);
String vipAddress = initialApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress();
DiscoveryClientResource vipClientResource = discoveryClientResource.fork().withVipFetch(vipAddress).build();
// Take first portion
when(requestHandler.getVip(vipAddress, TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
EurekaClient vipClient = vipClientResource.getClient();
assertThat(countInstances(vipClient.getApplications()), is(equalTo(1)));
// Now second one
when(requestHandler.getVip(vipAddress, TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.toApplications()).type(MediaType.APPLICATION_JSON_TYPE).build());
assertThat(vipClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
assertThat(countInstances(vipClient.getApplications()), is(equalTo(2)));
}
Aggregations