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