Search in sources :

Example 56 with Applications

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

the class DiscoveryClientEventBusTest method testStatusChangeEvent.

@Test
public void testStatusChangeEvent() throws Exception {
    final CountDownLatch eventLatch = new CountDownLatch(1);
    final List<StatusChangeEvent> receivedEvents = new ArrayList<StatusChangeEvent>();
    EventBus eventBus = discoveryClientResource.getEventBus();
    eventBus.registerSubscriber(new Object() {

        @Subscribe
        public void consume(StatusChangeEvent event) {
            receivedEvents.add(event);
            eventLatch.countDown();
        }
    });
    Applications initialApps = toApplications(discoveryClientResource.getMyInstanceInfo());
    when(requestHandler.getApplications()).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    // Activates the client
    discoveryClientResource.getClient();
    assertThat(eventLatch.await(10, TimeUnit.SECONDS), is(true));
    assertThat(receivedEvents.size(), is(equalTo(1)));
    assertThat(receivedEvents.get(0), is(notNullValue()));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) ArrayList(java.util.ArrayList) EventBus(com.netflix.eventbus.spi.EventBus) Subscribe(com.netflix.eventbus.spi.Subscribe) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 57 with Applications

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

the class DiscoveryClientRedirectTest method testClientQueryFollowsRedirectsAndPinsToTargetServer.

@Test
public void testClientQueryFollowsRedirectsAndPinsToTargetServer() throws Exception {
    Applications fullFetchApps = dataGenerator.takeDelta(1);
    String fullFetchJson = toJson(fullFetchApps);
    Applications deltaFetchApps = dataGenerator.takeDelta(1);
    String deltaFetchJson = toJson(deltaFetchApps);
    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/")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(fullFetchJson));
    targetServerMockClient.client.when(request().withMethod("GET").withPath("/eureka/v2/apps/delta")).respond(response().withStatusCode(200).withHeader(new Header("Content-Type", "application/json")).withBody(deltaFetchJson));
    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(0));
    targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/"), exactly(1));
    targetServerMockClient.client.verify(request().withMethod("GET").withPath("/eureka/v2/apps/delta"), atLeast(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 58 with Applications

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

the class DiscoveryClientRegistryTest method testGetInvalidVIP.

@Test
public void testGetInvalidVIP() throws Exception {
    Applications applications = InstanceInfoGenerator.newBuilder(1, "testApp").build().toApplications();
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, applications).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient client = discoveryClientResource.getClient();
    assertThat(countInstances(client.getApplications()), is(equalTo(1)));
    List<InstanceInfo> instancesByVipAddress = client.getInstancesByVipAddress("XYZ", false);
    assertThat(instancesByVipAddress.isEmpty(), is(true));
}
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 59 with Applications

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

the class DiscoveryClientRegistryTest method prepareRemoteRegionRegistry.

/**
     * There is a bug, because of which remote registry data structures are not initialized during full registry fetch, only during delta.
     */
private void prepareRemoteRegionRegistry() throws Exception {
    Applications localApplications = InstanceInfoGenerator.newBuilder(4, "app1", "app2").build().toApplications();
    Applications remoteApplications = InstanceInfoGenerator.newBuilder(4, "remote1", "remote2").withZone(TEST_REMOTE_ZONE).build().toApplications();
    Applications allApplications = mergeApplications(localApplications, remoteApplications);
    // Load remote data in delta, to go around exiting bug in DiscoveryClient
    Applications delta = copyApplications(remoteApplications);
    delta.setAppsHashCode(allApplications.getAppsHashCode());
    when(requestHandler.getApplications(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, localApplications).type(MediaType.APPLICATION_JSON_TYPE).build());
    when(requestHandler.getDelta(TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, delta).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(discoveryClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
}
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)

Example 60 with Applications

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

the class DiscoveryClientRegistryTest method testAppsHashCodeAfterRefresh.

@Test
public void testAppsHashCodeAfterRefresh() 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)).setStatus(InstanceStatus.DOWN).build();
    Applications delta = toApplications(second);
    delta.setAppsHashCode("DOWN_1_UP_1_");
    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_1_")));
}
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) InstanceInfo(com.netflix.appinfo.InstanceInfo) 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