Search in sources :

Example 36 with Applications

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());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 37 with Applications

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());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 38 with Applications

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));
    }
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 39 with Applications

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();
        }
    }
}
Also used : JerseyReplicationClient(com.netflix.eureka.transport.JerseyReplicationClient) Applications(com.netflix.discovery.shared.Applications) DefaultEurekaServerConfig(com.netflix.eureka.DefaultEurekaServerConfig) DefaultEurekaServerConfig(com.netflix.eureka.DefaultEurekaServerConfig) EurekaServerConfig(com.netflix.eureka.EurekaServerConfig) DefaultServerCodecs(com.netflix.eureka.resources.DefaultServerCodecs)

Example 40 with Applications

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);
}
Also used : Applications(com.netflix.discovery.shared.Applications) 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