Search in sources :

Example 1 with CodecWrapper

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);
}
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 2 with CodecWrapper

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);
}
Also used : ReplicationInstance(com.netflix.eureka.cluster.protocol.ReplicationInstance) CodecWrapper(com.netflix.discovery.converters.wrappers.CodecWrapper) ArrayList(java.util.ArrayList) ReplicationList(com.netflix.eureka.cluster.protocol.ReplicationList) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 3 with CodecWrapper

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);
}
Also used : ReplicationListResponse(com.netflix.eureka.cluster.protocol.ReplicationListResponse) CodecWrapper(com.netflix.discovery.converters.wrappers.CodecWrapper) ReplicationInstanceResponse(com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse) ArrayList(java.util.ArrayList) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Aggregations

CodecWrapper (com.netflix.discovery.converters.wrappers.CodecWrapper)3 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)3 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)3 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 InstanceInfo (com.netflix.appinfo.InstanceInfo)1 Applications (com.netflix.discovery.shared.Applications)1 ReplicationInstance (com.netflix.eureka.cluster.protocol.ReplicationInstance)1 ReplicationInstanceResponse (com.netflix.eureka.cluster.protocol.ReplicationInstanceResponse)1 ReplicationList (com.netflix.eureka.cluster.protocol.ReplicationList)1 ReplicationListResponse (com.netflix.eureka.cluster.protocol.ReplicationListResponse)1