Search in sources :

Example 11 with DecoderWrapper

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

the class ApplicationResourceTest method testMiniAppGet.

@Test
public void testMiniAppGet() throws Exception {
    Response response = applicationResource.getApplication(Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.compact.name());
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Application decodedApp = decoder.decode(json, Application.class);
    // 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));
    }
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 12 with DecoderWrapper

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

the class EurekaCodecCompatibilityTest method testInstanceInfoEncodeDecodeJsonWithEmptyMetadataMap.

@Test
public void testInstanceInfoEncodeDecodeJsonWithEmptyMetadataMap() throws Exception {
    final InstanceInfo base = infoIterator.next();
    final InstanceInfo instanceInfo = new InstanceInfo.Builder(base).setMetadata(Collections.EMPTY_MAP).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.equal(instanceInfo, decodedValue), 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 DecoderWrapper

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

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

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

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