Search in sources :

Example 6 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientEventBusTest method testCacheRefreshEvent.

@Test
public void testCacheRefreshEvent() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    // Initial full fetch
    Applications initialApps = instanceGen.takeDelta(1);
    when(requestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    // Activates the client
    discoveryClientResource.getClient();
    // Delta update
    Applications delta = instanceGen.takeDelta(1);
    when(requestHandler.getDelta()).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(10, TimeUnit.SECONDS), is(true));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) Test(org.junit.Test)

Example 7 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRedirectTest method testClientFallsBackToOriginalServerOnError.

@Test
public void testClientFallsBackToOriginalServerOnError() throws Exception {
    Applications fullFetchApps1 = dataGenerator.takeDelta(1);
    String fullFetchJson1 = toJson(fullFetchApps1);
    Applications fullFetchApps2 = EurekaEntityFunctions.mergeApplications(fullFetchApps1, dataGenerator.takeDelta(1));
    String fullFetchJson2 = toJson(fullFetchApps2);
    redirectServerMockClient.when(request().withMethod("GET").withPath("/eureka/v2/apps/")).respond(response().withStatusCode(302).withHeader(new Header("Location", targetServerBaseUri + "/eureka/v2/apps/")));
    targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/"), Times.exactly(1)).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson1));
    targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), Times.exactly(1)).respond(response().withStatusCode(500));
    redirectServerMockClient.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson2));
    final EurekaClient client = registryFetchClientRule.getClient();
    await(new Callable<Boolean>() {

        @Override
        public Boolean call() throws Exception {
            List<Application> applicationList = client.getApplications().getRegisteredApplications();
            return !applicationList.isEmpty() && applicationList.get(0).getInstances().size() == 2;
        }
    }, 1, TimeUnit.MINUTES);
    redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
    redirectServerMockClient.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), exactly(1));
    targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
    targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), exactly(1));
}
Also used : Applications(com.netflix.discovery.shared.Applications) Header(org.mockserver.model.Header) List(java.util.List) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) Test(org.junit.Test)

Example 8 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull.

@Test
public void testApplyDeltaWithBadInstanceInfoDataCenterInfoAsNull() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    // Full fetch with one item
    InstanceInfo first = instanceGen.first();
    Applications initial = toApplications(first);
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initial).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("UP_1_")));
    // Delta with one add
    InstanceInfo second = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo1").setStatus(InstanceStatus.DOWN).setDataCenterInfo(null).build();
    InstanceInfo third = new InstanceInfo.Builder(instanceGen.take(1)).setInstanceId("foo2").setStatus(InstanceStatus.UP).setDataCenterInfo(new DataCenterInfo() {

        @Override
        public Name getName() {
            return null;
        }
    }).build();
    Applications delta = toApplications(second, third);
    delta.setAppsHashCode("DOWN_1_UP_2_");
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(client.getApplications().getAppsHashCode(), is(equalTo("DOWN_1_UP_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) DataCenterInfo(com.netflix.appinfo.DataCenterInfo) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 9 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testGetByVipInLocalRegion.

@Test
public void testGetByVipInLocalRegion() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(4, "app1", "app2").build().toApplications();
    InstanceInfo instance = applications.getRegisteredApplications("app1").getInstances().get(0);
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, applications).type(MediaType.APPLICATION_JSON_TYPE).build());
    List<InstanceInfo> result = discoveryClientResource.getClient().getInstancesByVipAddress(instance.getVIPAddress(), false);
    assertThat(result.size(), is(equalTo(2)));
    assertThat(result.get(0).getVIPAddress(), is(equalTo(instance.getVIPAddress())));
}
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) InstanceInfo(com.netflix.appinfo.InstanceInfo) Test(org.junit.Test)

Example 10 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testEurekaClientPeriodicCacheRefresh.

@Test
public void testEurekaClientPeriodicCacheRefresh() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(3, 1).build();
    Applications initialApps = instanceGen.takeDelta(1);
    // Full fetch
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(countInstances(client.getApplications()), is(equalTo(1)));
    // Delta 1
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.takeDelta(1)).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    // Delta 2
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.takeDelta(1)).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(countInstances(client.getApplications()), is(equalTo(3)));
}
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) Test(org.junit.Test)

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