Search in sources :

Example 1 with DiscoveryClientResource

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);
}
Also used : DiscoveryClientResource(com.netflix.discovery.junit.resource.DiscoveryClientResource) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 2 with DiscoveryClientResource

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)));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) DiscoveryClientResource(com.netflix.discovery.junit.resource.DiscoveryClientResource) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

DiscoveryClientResource (com.netflix.discovery.junit.resource.DiscoveryClientResource)2 Test (org.junit.Test)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Applications (com.netflix.discovery.shared.Applications)1 EurekaEntityFunctions.copyApplications (com.netflix.discovery.util.EurekaEntityFunctions.copyApplications)1 EurekaEntityFunctions.mergeApplications (com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications)1 EurekaEntityFunctions.toApplications (com.netflix.discovery.util.EurekaEntityFunctions.toApplications)1 InstanceInfoGenerator (com.netflix.discovery.util.InstanceInfoGenerator)1 Matchers.anyString (org.mockito.Matchers.anyString)1