use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.
the class EurekaCodecCompatibilityTest method verifyAllPairs.
public void verifyAllPairs(Action2 codingAction, Class<?> typeToEncode, List<CodecWrapper> codecHolders) throws Exception {
for (EncoderWrapper encodingCodec : codecHolders) {
for (DecoderWrapper decodingCodec : codecHolders) {
String pair = "{" + encodingCodec.codecName() + ',' + decodingCodec.codecName() + '}';
System.out.println("Encoding " + typeToEncode.getSimpleName() + " using " + pair);
try {
codingAction.call(encodingCodec, decodingCodec);
} catch (Exception ex) {
throw new Exception("Encoding failure for codec pair " + pair, ex);
}
}
}
}
use of com.netflix.discovery.converters.wrappers.DecoderWrapper 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.converters.wrappers.DecoderWrapper in project eureka by Netflix.
the class EurekaCodecCompatibilityTest method testBatchRequestEncoding.
@Test
public void testBatchRequestEncoding() throws Exception {
InstanceInfo instance = InstanceInfoGenerator.takeOne();
List<ReplicationInstance> replicationInstances = new ArrayList<>();
replicationInstances.add(new ReplicationInstance(instance.getAppName(), instance.getId(), System.currentTimeMillis(), null, instance.getStatus().name(), instance, Action.Register));
final ReplicationList replicationList = new ReplicationList(replicationInstances);
Action2 codingAction = new Action2() {
@Override
public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
String encodedString = encodingCodec.encode(replicationList);
ReplicationList decodedValue = decodingCodec.decode(encodedString, ReplicationList.class);
assertThat(decodedValue.getReplicationList().size(), is(equalTo(1)));
}
};
// In replication channel we use JSON only
List<CodecWrapper> jsonCodes = Arrays.asList(new CodecWrappers.JacksonJson(), new CodecWrappers.LegacyJacksonJson());
verifyAllPairs(codingAction, ReplicationList.class, jsonCodes);
}
use of com.netflix.discovery.converters.wrappers.DecoderWrapper 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));
}
}
use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.
the class ApplicationResourceTest method testFullAppGet.
@Test
public void testFullAppGet() throws Exception {
Response response = applicationResource.getApplication(Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.full.name());
String json = String.valueOf(response.getEntity());
DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
Application decodedApp = decoder.decode(json, Application.class);
assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(true));
}
Aggregations