Search in sources :

Example 6 with ProtobufDataCodec

use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.

the class TestProtobufDataDecoder method testDecoder.

@Test(dataProvider = "protobufCodecData", dataProviderClass = CodecDataProviders.class)
public void testDecoder(String testName, DataComplex dataComplex, boolean enableFixedLengthFloatDoubles) throws Exception {
    ProtobufDataCodec codec = new ProtobufDataCodec(new ProtobufCodecOptions.Builder().setEnableFixedLengthFloatDoubles(enableFixedLengthFloatDoubles).setEnableASCIIOnlyStrings(true).build());
    byte[] bytes = TestUtil.dataComplexToBytes(codec, dataComplex);
    DataComplex decodedDataComplex = decode(bytes, 20);
    assertEquals(TestUtil.dataComplexToBytes(codec, decodedDataComplex), bytes);
}
Also used : DataComplex(com.linkedin.data.DataComplex) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) Test(org.testng.annotations.Test)

Example 7 with ProtobufDataCodec

use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.

the class TestProtobufDataDecoder method testLongValues.

@Test
public void testLongValues() throws Exception {
    long longInc = (Long.MAX_VALUE - Long.MAX_VALUE / 100L) / 10000L;
    for (long i = Long.MAX_VALUE / 100L; i <= Long.MAX_VALUE && i > 0; i += longInc) {
        DataMap dataMap = new DataMap();
        dataMap.put("long", i);
        byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
        DataMap decodedMap = (DataMap) decode(bytes, 20);
        assertEquals(decodedMap.getLong("long"), Long.valueOf(i));
    }
    for (long i = Long.MIN_VALUE; i <= Long.MIN_VALUE / 100L && i < 0; i += longInc) {
        DataMap dataMap = new DataMap();
        dataMap.put("long", i);
        byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
        DataMap decodedMap = (DataMap) decode(bytes, 20);
        assertEquals(decodedMap.getLong("long"), Long.valueOf(i));
    }
}
Also used : ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) ProtobufCodecOptions(com.linkedin.data.codec.ProtobufCodecOptions) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Example 8 with ProtobufDataCodec

use of com.linkedin.data.codec.ProtobufDataCodec in project rest.li by linkedin.

the class TestProtobufDataDecoder method testInvalidList.

@Test
public void testInvalidList() throws Exception {
    DataMap dataMap = new DataMap();
    dataMap.put("key", true);
    byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
    decode(bytes, 3);
    try {
        decodeList(bytes);
        fail("Parsing map as list");
    } catch (ExecutionException e) {
    // Expected.
    }
}
Also used : ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) ProtobufCodecOptions(com.linkedin.data.codec.ProtobufCodecOptions) ExecutionException(java.util.concurrent.ExecutionException) DataMap(com.linkedin.data.DataMap) Test(org.testng.annotations.Test)

Aggregations

ProtobufDataCodec (com.linkedin.data.codec.ProtobufDataCodec)8 Test (org.testng.annotations.Test)7 ProtobufCodecOptions (com.linkedin.data.codec.ProtobufCodecOptions)6 DataMap (com.linkedin.data.DataMap)4 DataComplex (com.linkedin.data.DataComplex)2 ExecutionException (java.util.concurrent.ExecutionException)2 DataList (com.linkedin.data.DataList)1 BsonDataCodec (com.linkedin.data.codec.BsonDataCodec)1 DataCodec (com.linkedin.data.codec.DataCodec)1 JacksonDataCodec (com.linkedin.data.codec.JacksonDataCodec)1 JacksonLICORDataCodec (com.linkedin.data.codec.JacksonLICORDataCodec)1 JacksonSmileDataCodec (com.linkedin.data.codec.JacksonSmileDataCodec)1 ArrayList (java.util.ArrayList)1 DataProvider (org.testng.annotations.DataProvider)1