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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations