Search in sources :

Example 6 with DecoderWrapper

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

the class EurekaCodecCompatibilityTest method verifyAllPairs.

public void verifyAllPairs(Action2 codingAction, Class<?> typeToEncode, List<CodecWrapper> codecHolders) throws Exception {
    for (EncoderWrapper encodingCodec : codecHolders) {
        for (DecoderWrapper decodingCodec : codecHolders) {
            String pair = "{" + encodingCodec.codecName() + ',' + decodingCodec.codecName() + '}';
            System.out.println("Encoding " + typeToEncode.getSimpleName() + " using " + pair);
            try {
                codingAction.call(encodingCodec, decodingCodec);
            } catch (Exception ex) {
                throw new Exception("Encoding failure for codec pair " + pair, ex);
            }
        }
    }
}
Also used : DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) IOException(java.io.IOException) EncoderWrapper(com.netflix.discovery.converters.wrappers.EncoderWrapper)

Example 7 with DecoderWrapper

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

the class EurekaCodecCompatibilityTest method testApplicationsEncodeDecode.

@Test
public void testApplicationsEncodeDecode() throws Exception {
    final Applications applications = infoGenerator.takeDelta(2);
    Action2 codingAction = new Action2() {

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

Example 8 with DecoderWrapper

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

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

the class AbstractVIPResourceTest method testMiniVipGet.

@Test
public void testMiniVipGet() throws Exception {
    Response response = resource.getVipResponse(Version.V2.name(), vipName, MediaType.APPLICATION_JSON, EurekaAccept.compact, Key.EntityType.VIP);
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Applications decodedApps = decoder.decode(json, Applications.class);
    Application decodedApp = decodedApps.getRegisteredApplications(testApplication.getName());
    // 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) Applications(com.netflix.discovery.shared.Applications) Application(com.netflix.discovery.shared.Application) InstanceInfo(com.netflix.appinfo.InstanceInfo) CodecWrappers(com.netflix.discovery.converters.wrappers.CodecWrappers) Test(org.junit.Test)

Example 10 with DecoderWrapper

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

the class ApplicationResourceTest method testFullAppGet.

@Test
public void testFullAppGet() throws Exception {
    Response response = applicationResource.getApplication(Version.V2.name(), MediaType.APPLICATION_JSON, EurekaAccept.full.name());
    String json = String.valueOf(response.getEntity());
    DecoderWrapper decoder = CodecWrappers.getDecoder(CodecWrappers.LegacyJacksonJson.class);
    Application decodedApp = decoder.decode(json, Application.class);
    assertThat(EurekaEntityComparators.equal(testApplication, decodedApp), is(true));
}
Also used : Response(javax.ws.rs.core.Response) DecoderWrapper(com.netflix.discovery.converters.wrappers.DecoderWrapper) Application(com.netflix.discovery.shared.Application) 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