use of com.netflix.discovery.converters.wrappers.CodecWrapper 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.converters.wrappers.CodecWrapper 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.CodecWrapper in project eureka by Netflix.
the class EurekaCodecCompatibilityTest method testBatchResponseEncoding.
@Test
public void testBatchResponseEncoding() throws Exception {
List<ReplicationInstanceResponse> responseList = new ArrayList<>();
responseList.add(new ReplicationInstanceResponse(200, InstanceInfoGenerator.takeOne()));
final ReplicationListResponse replicationListResponse = new ReplicationListResponse(responseList);
Action2 codingAction = new Action2() {
@Override
public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
String encodedString = encodingCodec.encode(replicationListResponse);
ReplicationListResponse decodedValue = decodingCodec.decode(encodedString, ReplicationListResponse.class);
assertThat(decodedValue.getResponseList().size(), is(equalTo(1)));
}
};
// In replication channel we use JSON only
List<CodecWrapper> jsonCodes = Arrays.asList(new CodecWrappers.JacksonJson(), new CodecWrappers.LegacyJacksonJson());
verifyAllPairs(codingAction, ReplicationListResponse.class, jsonCodes);
}
Aggregations