Search in sources :

Example 36 with Application

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

the class EurekaJacksonCodecTest method testApplicationXStreamEncodeJacksonDecode.

@Test
public void testApplicationXStreamEncodeJacksonDecode() throws Exception {
    Application original = APPLICATION_1;
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    new EntityBodyConverter().write(original, captureStream, MediaType.APPLICATION_JSON_TYPE);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Application decoded = codec.readValue(Application.class, source);
    assertTrue(EurekaEntityComparators.equal(decoded, original));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 37 with Application

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

the class EurekaJacksonCodecTest method testApplicationJacksonEncodeXStreamDecode.

@Test
public void testApplicationJacksonEncodeXStreamDecode() throws Exception {
    // Encode
    ByteArrayOutputStream captureStream = new ByteArrayOutputStream();
    codec.writeTo(APPLICATION_1, captureStream);
    byte[] encoded = captureStream.toByteArray();
    // Decode
    InputStream source = new ByteArrayInputStream(encoded);
    Application decoded = (Application) new EntityBodyConverter().read(source, Application.class, MediaType.APPLICATION_JSON_TYPE);
    assertTrue(EurekaEntityComparators.equal(decoded, APPLICATION_1));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Application(com.netflix.discovery.shared.Application) Test(org.junit.Test)

Example 38 with Application

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

the class EurekaJsonAndXmlJacksonCodecTest method doApplicationEncodeDecode.

private void doApplicationEncodeDecode(AbstractEurekaJacksonCodec codec) throws Exception {
    Application application = new Application("testApp");
    application.addInstance(infoIterator.next());
    application.addInstance(infoIterator.next());
    String encodedString = codec.getObjectMapper(Application.class).writeValueAsString(application);
    Application decodedValue = codec.getObjectMapper(Application.class).readValue(encodedString, Application.class);
    assertThat(EurekaEntityComparators.equal(application, decodedValue), is(true));
}
Also used : Application(com.netflix.discovery.shared.Application)

Example 39 with Application

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

the class EurekaEntityComparators method equal.

public static boolean equal(Applications first, Applications second) {
    if (first == second) {
        return true;
    }
    if (first == null || first == null && second != null) {
        return false;
    }
    List<Application> firstApps = first.getRegisteredApplications();
    List<Application> secondApps = second.getRegisteredApplications();
    if (firstApps == null && secondApps == null) {
        return true;
    }
    if (firstApps == null || secondApps == null || firstApps.size() != secondApps.size()) {
        return false;
    }
    for (Application firstApp : firstApps) {
        Application secondApp = second.getRegisteredApplications(firstApp.getName());
        if (!equal(firstApp, secondApp)) {
            return false;
        }
    }
    return true;
}
Also used : Application(com.netflix.discovery.shared.Application)

Example 40 with Application

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

the class EurekaEntityFunctions method toApplicationMap.

public static Map<String, Application> toApplicationMap(List<InstanceInfo> instances) {
    Map<String, Application> applicationMap = new HashMap<String, Application>();
    for (InstanceInfo instance : instances) {
        String appName = instance.getAppName();
        Application application = applicationMap.get(appName);
        if (application == null) {
            applicationMap.put(appName, application = new Application(appName));
        }
        application.addInstance(instance);
    }
    return applicationMap;
}
Also used : HashMap(java.util.HashMap) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo)

Aggregations

Application (com.netflix.discovery.shared.Application)60 InstanceInfo (com.netflix.appinfo.InstanceInfo)35 Applications (com.netflix.discovery.shared.Applications)25 Test (org.junit.Test)18 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)7 HashMap (java.util.HashMap)7 Response (javax.ws.rs.core.Response)7 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)6 Lease (com.netflix.eureka.lease.Lease)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 EurekaHttpResponseBuilder (com.netflix.discovery.shared.transport.EurekaHttpResponse.EurekaHttpResponseBuilder)2 PeerEurekaNode (com.netflix.eureka.cluster.PeerEurekaNode)2 Map (java.util.Map)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)1 ApplicationInfoManager (com.netflix.appinfo.ApplicationInfoManager)1