use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class InstanceRegistryTest method testGetAppsDeltaFromAllRemoteRegions.
@Test
public void testGetAppsDeltaFromAllRemoteRegions() throws Exception {
/// local delta
registerInstanceLocally(createLocalInstance(LOCAL_REGION_INSTANCE_2_HOSTNAME));
waitForDeltaToBeRetrieved();
Applications appDelta = registry.getApplicationDeltasFromMultipleRegions(null);
List<Application> registeredApplications = appDelta.getRegisteredApplications();
Assert.assertEquals("Apps size from remote regions do not match", 2, registeredApplications.size());
Application localApplication = null;
Application remApplication = null;
for (Application registeredApplication : registeredApplications) {
if (registeredApplication.getName().equalsIgnoreCase(LOCAL_REGION_APP_NAME)) {
localApplication = registeredApplication;
}
if (registeredApplication.getName().equalsIgnoreCase(REMOTE_REGION_APP_NAME)) {
remApplication = registeredApplication;
}
}
Assert.assertNotNull("Did not find local registry app in delta.", localApplication);
Assert.assertEquals("Local registry app instance count in delta not as expected.", 1, localApplication.getInstances().size());
Assert.assertNotNull("Did not find remote registry app in delta", remApplication);
Assert.assertEquals("Remote registry app instance count in delta not as expected.", 1, remApplication.getInstances().size());
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class InstanceRegistryTest method testGetAppsFromLocalRegionOnly.
@Test
public void testGetAppsFromLocalRegionOnly() throws Exception {
registerInstanceLocally(createLocalInstance(LOCAL_REGION_INSTANCE_1_HOSTNAME));
Applications apps = registry.getApplicationsFromLocalRegionOnly();
List<Application> registeredApplications = apps.getRegisteredApplications();
Assert.assertEquals("Apps size from local region do not match", 1, registeredApplications.size());
Application app = registeredApplications.iterator().next();
Assert.assertEquals("Added app did not return from local registry", LOCAL_REGION_APP_NAME, app.getName());
Assert.assertEquals("Returned app did not have the instance", 1, app.getInstances().size());
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class AbstractVIPResourceTest method testMiniVipGet.
@Test
public void testMiniVipGet() throws Exception {
Response response = resource.getVipResponse(Version.V2.name(), vipName, MediaType.APPLICATION_JSON, EurekaAccept.compact, Key.EntityType.VIP);
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Applications decodedApps = decoder.decode(json, Applications.class);
Application decodedApp = decodedApps.getRegisteredApplications(testApplication.getName());
// assert false as one is mini, so should NOT equal
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(false));
for (InstanceInfo instanceInfo : testApplication.getInstances()) {
InstanceInfo decodedInfo = decodedApp.getByInstanceId(instanceInfo.getId());
assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedInfo), is(true));
}
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class DiagnosticClient method main.
public static void main(String[] args) throws InterruptedException {
String discoveryURL = args[0];
long startTime = System.currentTimeMillis();
EurekaServerConfig serverConfig = new DefaultEurekaServerConfig("eureka.");
JerseyReplicationClient client = JerseyReplicationClient.createReplicationClient(serverConfig, new DefaultServerCodecs(serverConfig), discoveryURL);
Applications applications = client.getApplications().getEntity();
System.out.println("Applications count=" + applications.getRegisteredApplications().size());
System.out.println("Instance count=" + countInstances(applications));
while (true) {
long delay = System.currentTimeMillis() - startTime;
if (delay >= 30000) {
System.out.println("Processing delay exceeds 30sec; we may be out of sync");
} else {
long waitTime = 30 * 1000 - delay;
System.out.println("Waiting " + waitTime / 1000 + "sec before next fetch...");
Thread.sleep(15 * 1000);
}
startTime = System.currentTimeMillis();
Applications delta = client.getDelta().getEntity();
Applications merged = EurekaEntityFunctions.mergeApplications(applications, delta);
if (merged.getAppsHashCode().equals(delta.getAppsHashCode())) {
System.out.println("Hash codes match: " + delta.getAppsHashCode() + "(delta count=" + countInstances(delta) + ')');
applications = merged;
} else {
System.out.println("ERROR: hash codes do not match (" + delta.getAppsHashCode() + "(delta) != " + merged.getAppsHashCode() + " (merged) != " + applications.getAppsHashCode() + "(old apps)" + "(delta count=" + countInstances(delta) + ')');
applications = client.getApplications().getEntity();
}
}
}
use of com.netflix.discovery.shared.Applications in project eureka by Netflix.
the class EurekaHttpClientCompatibilityTestSuite method testGetApplicationsRequest.
@Test
public void testGetApplicationsRequest() throws Exception {
Applications apps = InstanceInfoGenerator.newBuilder(2, 1).build().toApplications();
when(requestHandler.getApplications()).thenReturn(createResponse(apps));
EurekaHttpResponse<Applications> httpResponse = getEurekaHttpClient().getApplications();
verifyResponseOkWithEntity(apps, httpResponse);
}
Aggregations