Search in sources :

Example 1 with DecoderWrapper

use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testInstanceInfoFullEncodeMiniDecodeJackson.

/**
     * During deserialization process in compact mode not all fields might be filtered out. If JVM memory
     * is an issue, compact version of the encoder should be used on the server side.
     */
@Test
public void testInstanceInfoFullEncodeMiniDecodeJackson() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.JacksonJson(), new CodecWrappers.JacksonJsonMini());
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 2 with DecoderWrapper

use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testInstanceInfoMiniEncodeMiniDecodeJackson.

@Test
public void testInstanceInfoMiniEncodeMiniDecodeJackson() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.JacksonJsonMini(), new CodecWrappers.JacksonJsonMini());
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 3 with DecoderWrapper

use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testInstanceInfoFullEncodeMiniDecodeJacksonWithMyOwnDataCenterInfo.

@Test
public void testInstanceInfoFullEncodeMiniDecodeJacksonWithMyOwnDataCenterInfo() throws Exception {
    final InstanceInfo base = infoIterator.next();
    final InstanceInfo instanceInfo = new InstanceInfo.Builder(base).setDataCenterInfo(new MyDataCenterInfo(DataCenterInfo.Name.MyOwn)).build();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equalMini(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.JacksonJson(), new CodecWrappers.JacksonJsonMini());
}
Also used : MyDataCenterInfo(com.netflix.appinfo.MyDataCenterInfo) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 4 with DecoderWrapper

use of com.netflix.discovery.converters.wrappers.DecoderWrapper 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 5 with DecoderWrapper

use of com.netflix.discovery.converters.wrappers.DecoderWrapper in project eureka by Netflix.

the class EurekaCodecCompatibilityTest method testInstanceInfoEncodeDecodeLegacyJacksonToJackson.

/**
     * @deprecated see to do note in {@link com.netflix.appinfo.LeaseInfo} and delete once legacy is removed
     */
@Deprecated
@Test
public void testInstanceInfoEncodeDecodeLegacyJacksonToJackson() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            // convert the field from the json string to what the legacy json would encode as
            encodedString = encodedString.replaceFirst("lastRenewalTimestamp", "renewalTimestamp");
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue, new EurekaEntityComparators.RawIdEqualFunc()), is(true));
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue), is(true));
        }
    };
    verifyForPair(codingAction, InstanceInfo.class, new CodecWrappers.LegacyJacksonJson(), new CodecWrappers.JacksonJson());
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Aggregations

DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)18 Test (org.junit.Test)17 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)13 EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)12 InstanceInfo (com.netflix.appinfo.InstanceInfo)10 Application (com.netflix.discovery.shared.Application)7 Applications (com.netflix.discovery.shared.Applications)6 Response (javax.ws.rs.core.Response)6 CodecWrapper (com.netflix.discovery.converters.wrappers.CodecWrapper)3 ArrayList (java.util.ArrayList)2 MyDataCenterInfo (com.netflix.appinfo.MyDataCenterInfo)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 IOException (java.io.IOException)1