use of com.netflix.discovery.util.InstanceInfoGenerator 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.util.InstanceInfoGenerator 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.util.InstanceInfoGenerator 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)));
}
use of com.netflix.discovery.util.InstanceInfoGenerator in project eureka by Netflix.
the class AbstractVIPResourceTest method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
InstanceInfoGenerator instanceInfos = InstanceInfoGenerator.newBuilder(6, 1).build();
testApplication = instanceInfos.toApplications().getRegisteredApplications().get(0);
resource = new AbstractVIPResource(serverContext) {
@Override
protected Response getVipResponse(String version, String entityName, String acceptHeader, EurekaAccept eurekaAccept, Key.EntityType entityType) {
return super.getVipResponse(version, entityName, acceptHeader, eurekaAccept, entityType);
}
};
vipName = testApplication.getName() + "#VIP";
for (InstanceInfo instanceInfo : testApplication.getInstances()) {
InstanceInfo changed = new InstanceInfo.Builder(instanceInfo).setASGName(// null asgName to get around AwsAsgUtil check
null).setVIPAddress(// use the same vip address for all the instances in this test
vipName).build();
registry.register(changed, false);
}
}
use of com.netflix.discovery.util.InstanceInfoGenerator 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