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()));
}
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));
}
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));
}
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));
}
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_")));
}
Aggregations