Search in sources :

Example 11 with EncoderWrapper

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

the class EurekaCodecCompatibilityTest method testApplicationEncodeDecode.

@Test
public void testApplicationEncodeDecode() throws Exception {
    final Application application = new Application("testApp");
    application.addInstance(infoIterator.next());
    application.addInstance(infoIterator.next());
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(application);
            Application decodedValue = decodingCodec.decode(encodedString, Application.class);
            assertThat(EurekaEntityComparators.equal(application, decodedValue), is(true));
        }
    };
    verifyAllPairs(codingAction, Application.class, availableJsonWrappers);
    verifyAllPairs(codingAction, Application.class, availableXmlWrappers);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Application(com.netflix.discovery.shared.Application) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) Test(org.junit.Test)

Example 12 with EncoderWrapper

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

the class EurekaCodecCompatibilityTest method testInstanceInfoEncodeDecodeCompatibilityDueToOverriddenStatusRenamingV1.

// https://github.com/Netflix/eureka/issues/1051
// test going from camel case to lower case
@Test
public void testInstanceInfoEncodeDecodeCompatibilityDueToOverriddenStatusRenamingV1() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    new InstanceInfo.Builder(instanceInfo).setOverriddenStatus(InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            // sed to older naming to test
            encodedString = encodedString.replace("overriddenStatus", "overriddenstatus");
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue), is(true));
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue, new EurekaEntityComparators.RawIdEqualFunc()), is(true));
        }
    };
    verifyAllPairs(codingAction, Application.class, availableJsonWrappers);
    verifyAllPairs(codingAction, Application.class, availableXmlWrappers);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) Test(org.junit.Test)

Example 13 with EncoderWrapper

use of com.netflix.discovery.converters.wrappers.EncoderWrapper 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)

Example 14 with EncoderWrapper

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

the class EurekaCodecCompatibilityTest method testInstanceInfoEncodeDecode.

@Test
public void testInstanceInfoEncodeDecode() 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.equal(instanceInfo, decodedValue), is(true));
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue, new EurekaEntityComparators.RawIdEqualFunc()), is(true));
        }
    };
    verifyAllPairs(codingAction, InstanceInfo.class, availableJsonWrappers);
    verifyAllPairs(codingAction, InstanceInfo.class, availableXmlWrappers);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) Test(org.junit.Test)

Example 15 with EncoderWrapper

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

the class EurekaCodecCompatibilityTest method testInstanceInfoEncodeDecodeCompatibilityDueToOverriddenStatusRenamingV2.

// same as the above, but go from lower case to camel case
@Test
public void testInstanceInfoEncodeDecodeCompatibilityDueToOverriddenStatusRenamingV2() throws Exception {
    final InstanceInfo instanceInfo = infoIterator.next();
    new InstanceInfo.Builder(instanceInfo).setOverriddenStatus(InstanceInfo.InstanceStatus.OUT_OF_SERVICE);
    Action2 codingAction = new Action2() {

        @Override
        public void call(EncoderWrapper encodingCodec, DecoderWrapper decodingCodec) throws IOException {
            String encodedString = encodingCodec.encode(instanceInfo);
            // sed to older naming to test
            encodedString = encodedString.replace("overriddenstatus", "overriddenStatus");
            InstanceInfo decodedValue = decodingCodec.decode(encodedString, InstanceInfo.class);
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue), is(true));
            assertThat(EurekaEntityComparators.equal(instanceInfo, decodedValue, new EurekaEntityComparators.RawIdEqualFunc()), is(true));
        }
    };
    verifyAllPairs(codingAction, Application.class, availableJsonWrappers);
    verifyAllPairs(codingAction, Application.class, availableXmlWrappers);
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) InstanceInfo(com.netflix.appinfo.InstanceInfo) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper) Test(org.junit.Test)

Aggregations

EncoderWrapper (com.netflix.discovery.converters.wrappers.EncoderWrapper)16 DecoderWrapper (com.netflix.discovery.converters.wrappers.DecoderWrapper)14 Test (org.junit.Test)13 InstanceInfo (com.netflix.appinfo.InstanceInfo)9 CodecWrappers (com.netflix.discovery.converters.wrappers.CodecWrappers)7 CodecWrapper (com.netflix.discovery.converters.wrappers.CodecWrapper)3 Applications (com.netflix.discovery.shared.Applications)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MyDataCenterInfo (com.netflix.appinfo.MyDataCenterInfo)1 Application (com.netflix.discovery.shared.Application)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 WebApplicationException (javax.ws.rs.WebApplicationException)1