Search in sources :

Example 61 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testAllAppsForRegions.

@Test
public void testAllAppsForRegions() throws Exception {
    prepareRemoteRegionRegistry();
    EurekaClient client = discoveryClientResource.getClient();
    Applications appsForRemoteRegion = client.getApplicationsForARegion(TEST_REMOTE_REGION);
    assertThat(countInstances(appsForRemoteRegion), is(equalTo(4)));
    Applications appsForLocalRegion = client.getApplicationsForARegion(TEST_LOCAL_REGION);
    assertThat(countInstances(appsForLocalRegion), is(equalTo(4)));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) Test(org.junit.Test)

Example 62 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class DiscoveryClientRegistryTest method testCacheRefreshSingleAppForLocalRegion.

@Test
public void testCacheRefreshSingleAppForLocalRegion() throws Exception {
    InstanceInfoGenerator instanceGen = InstanceInfoGenerator.newBuilder(2, "testApp").build();
    Applications initialApps = instanceGen.takeDelta(1);
    String vipAddress = initialApps.getRegisteredApplications().get(0).getInstances().get(0).getVIPAddress();
    DiscoveryClientResource vipClientResource = discoveryClientResource.fork().withVipFetch(vipAddress).build();
    // Take first portion
    when(requestHandler.getVip(vipAddress, TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, initialApps).type(MediaType.APPLICATION_JSON_TYPE).build());
    EurekaClient vipClient = vipClientResource.getClient();
    assertThat(countInstances(vipClient.getApplications()), is(equalTo(1)));
    // Now second one
    when(requestHandler.getVip(vipAddress, TEST_REMOTE_REGION)).thenReturn(anEurekaHttpResponse(200, instanceGen.toApplications()).type(MediaType.APPLICATION_JSON_TYPE).build());
    assertThat(vipClientResource.awaitCacheUpdate(5, TimeUnit.SECONDS), is(true));
    assertThat(countInstances(vipClient.getApplications()), is(equalTo(2)));
}
Also used : Applications(com.netflix.discovery.shared.Applications) EurekaEntityFunctions.toApplications(com.netflix.discovery.util.EurekaEntityFunctions.toApplications) EurekaEntityFunctions.mergeApplications(com.netflix.discovery.util.EurekaEntityFunctions.mergeApplications) EurekaEntityFunctions.copyApplications(com.netflix.discovery.util.EurekaEntityFunctions.copyApplications) InstanceInfoGenerator(com.netflix.discovery.util.InstanceInfoGenerator) DiscoveryClientResource(com.netflix.discovery.junit.resource.DiscoveryClientResource) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 63 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class BackUpRegistryTest method setupBackupMock.

private void setupBackupMock() {
    Application localApp = createLocalApps();
    Applications localApps = new Applications();
    localApps.addApplication(localApp);
    backupRegistry.setLocalRegionApps(localApps);
    Application remoteApp = createRemoteApps();
    Applications remoteApps = new Applications();
    remoteApps.addApplication(remoteApp);
    backupRegistry.getRemoteRegionVsApps().put(REMOTE_REGION, remoteApps);
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application)

Example 64 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class BackUpRegistryTest method testRemoteEnabledAndQueried.

@Test
public void testRemoteEnabledAndQueried() throws Exception {
    setUp(true);
    Applications applications = client.getApplicationsForARegion(REMOTE_REGION);
    List<Application> registeredApplications = applications.getRegisteredApplications();
    Assert.assertNotNull("Remote region apps not found.", registeredApplications);
    Assert.assertEquals("Remote apps size not as expected.", 1, registeredApplications.size());
    Assert.assertEquals("Remote region apps not present.", REMOTE_REGION_APP_NAME, registeredApplications.get(0).getName());
}
Also used : Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 65 with Applications

use of com.netflix.discovery.shared.Applications in project eureka by Netflix.

the class EurekaJacksonCodecTest method testApplicationsJacksonEncodeXStreamDecode.

@Test
public void testApplicationsJacksonEncodeXStreamDecode() throws Exception {
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(APPLICATIONS, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Applications decoded = (Applications) new EntityBodyConverter().read(source, Applications.class, MediaType.APPLICATION_JSON_TYPE);
    assertTrue(EurekaEntityComparators.equal(decoded, APPLICATIONS));
}
Also used : Applications(com.netflix.discovery.shared.Applications) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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