Search in sources :

Example 11 with Applications

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

the class EurekaCodecCompatibilityTest method testApplicationsJsonEncodeDecodeWithSingleAppItem.

/**
     * For backward compatibility with LegacyJacksonJson codec single item arrays shall not be unwrapped.
     */
@Test
public void testApplicationsJsonEncodeDecodeWithSingleAppItem() throws Exception {
    final Applications applications = infoGenerator.takeDelta(1);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(applications);
            assertThat(encodedString.contains("\"application\":[{"), is(true));
            Applications decodedValue = decodingCodec.decode(encodedString, Applications.class);
            assertThat(EurekaEntityComparators.equal(applications, decodedValue), is(true));
        }
    };
    List<CodecWrapper> jsonCodes = Arrays.asList(new CodecWrappers.LegacyJacksonJson(), new CodecWrappers.JacksonJson());
    verifyAllPairs(codingAction, Applications.class, jsonCodes);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) CodecWrapper(com.netflix.discovery.converters.wrappers.CodecWrapper) Applications(com.netflix.discovery.shared.Applications) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 12 with Applications

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

the class EurekaCodecCompatibilityTest method testApplicationsEncodeDecode.

@Test
public void testApplicationsEncodeDecode() throws Exception {
    final Applications applications = infoGenerator.takeDelta(2);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(applications);
            Applications decodedValue = decodingCodec.decode(encodedString, Applications.class);
            assertThat(EurekaEntityComparators.equal(applications, decodedValue), is(true));
        }
    };
    verifyAllPairs(codingAction, Applications.class, availableJsonWrappers);
    verifyAllPairs(codingAction, Applications.class, availableXmlWrappers);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Applications(com.netflix.discovery.shared.Applications) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) Test(org.junit.Test)

Example 13 with Applications

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

the class EurekaEntityFunctions method copyApplications.

public static Applications copyApplications(Applications source) {
    Applications result = new Applications();
    copyApplications(source, result);
    return updateMeta(result);
}
Also used : Applications(com.netflix.discovery.shared.Applications)

Example 14 with Applications

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

the class EurekaEntityFunctions method toApplications.

public static Applications toApplications(List<InstanceInfo> instances) {
    Applications result = new Applications();
    for (InstanceInfo instance : instances) {
        Application app = result.getRegisteredApplications(instance.getAppName());
        if (app == null) {
            app = new Application(instance.getAppName());
            result.addApplication(app);
        }
        app.addInstance(instance);
    }
    return updateMeta(result);
}
Also used : Applications(com.netflix.discovery.shared.Applications) InstanceInfo(com.netflix.appinfo.InstanceInfo) Application(com.netflix.discovery.shared.Application)

Example 15 with Applications

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

the class EurekaEntityFunctions method mergeApplications.

public static Applications mergeApplications(Applications first, Applications second) {
    Set<String> firstNames = selectApplicationNames(first);
    Set<String> secondNames = selectApplicationNames(second);
    Set<String> allNames = new HashSet<String>(firstNames);
    allNames.addAll(secondNames);
    Applications merged = new Applications();
    for (String appName : allNames) {
        if (firstNames.contains(appName)) {
            if (secondNames.contains(appName)) {
                merged.addApplication(mergeApplication(first.getRegisteredApplications(appName), second.getRegisteredApplications(appName)));
            } else {
                merged.addApplication(copyApplication(first.getRegisteredApplications(appName)));
            }
        } else {
            merged.addApplication(copyApplication(second.getRegisteredApplications(appName)));
        }
    }
    return updateMeta(merged);
}
Also used : Applications(com.netflix.discovery.shared.Applications) HashSet(java.util.HashSet)

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