Search in sources :

Example 1 with ProtobufDataCodec

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

the class TestProtobufDataDecoder method testNumbers.

@Test(dataProvider = "numbersData", dataProviderClass = CodecDataProviders.class)
public void testNumbers(Object number) throws Exception {
    DataMap dataMap = new DataMap();
    dataMap.put("number", number);
    byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
    assertEquals(decode(bytes, 20), dataMap);
}
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 2 with ProtobufDataCodec

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

the class TestProtobufDataDecoder method testIntValues.

@Test
public void testIntValues() throws Exception {
    int inc = (Integer.MAX_VALUE - Integer.MAX_VALUE / 100) / 10000;
    for (int i = Integer.MAX_VALUE / 100; i <= Integer.MAX_VALUE && i > 0; i += inc) {
        DataMap dataMap = new DataMap();
        dataMap.put("int", i);
        byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
        DataMap decodedMap = (DataMap) decode(bytes, 20);
        assertEquals(decodedMap.getInteger("int"), Integer.valueOf(i));
    }
    for (int i = Integer.MIN_VALUE; i <= Integer.MIN_VALUE / 100 && i < 0; i += inc) {
        DataMap dataMap = new DataMap();
        dataMap.put("int", i);
        byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataMap);
        DataMap decodedMap = (DataMap) decode(bytes, 20);
        assertEquals(decodedMap.getInteger("int"), Integer.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 3 with ProtobufDataCodec

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

the class TestSymbolTableSerializer method data.

@DataProvider
public static Object[][] data() {
    List<Object[]> list = new ArrayList<>();
    List<DataCodec> codecs = new ArrayList<>();
    codecs.add(new BsonDataCodec());
    codecs.add(new JacksonDataCodec());
    codecs.add(new JacksonSmileDataCodec());
    codecs.add(new JacksonLICORDataCodec(false));
    codecs.add(new JacksonLICORDataCodec(true));
    codecs.add(new ProtobufDataCodec());
    for (DataCodec codec : codecs) {
        list.add(new Object[] { codec, true });
        list.add(new Object[] { codec, false });
    }
    return list.toArray(new Object[][] {});
}
Also used : JacksonSmileDataCodec(com.linkedin.data.codec.JacksonSmileDataCodec) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) DataCodec(com.linkedin.data.codec.DataCodec) JacksonLICORDataCodec(com.linkedin.data.codec.JacksonLICORDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) JacksonDataCodec(com.linkedin.data.codec.JacksonDataCodec) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) JacksonLICORDataCodec(com.linkedin.data.codec.JacksonLICORDataCodec) BsonDataCodec(com.linkedin.data.codec.BsonDataCodec) ArrayList(java.util.ArrayList) JacksonSmileDataCodec(com.linkedin.data.codec.JacksonSmileDataCodec) DataProvider(org.testng.annotations.DataProvider)

Example 4 with ProtobufDataCodec

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

the class TestProtobufDataDecoder method testInvalidMap.

@Test
public void testInvalidMap() throws Exception {
    DataList dataList = new DataList();
    dataList.add(1);
    dataList.add(2);
    dataList.add(4);
    byte[] bytes = TestUtil.dataComplexToBytes(new ProtobufDataCodec(new ProtobufCodecOptions.Builder().build()), dataList);
    decode(bytes, 3);
    try {
        decodeMap(bytes);
        fail("Parsing list as map.");
    } catch (ExecutionException e) {
    // Expected.
    }
}
Also used : DataList(com.linkedin.data.DataList) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) ProtobufCodecOptions(com.linkedin.data.codec.ProtobufCodecOptions) ExecutionException(java.util.concurrent.ExecutionException) Test(org.testng.annotations.Test)

Example 5 with ProtobufDataCodec

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

the class TestProtobufDataDecoder method testDecoder.

@Test(dataProvider = "streamCodecData", dataProviderClass = CodecDataProviders.class)
public void testDecoder(String testName, DataComplex dataComplex, int chunkSize) throws Exception {
    ProtobufDataCodec codec = new ProtobufDataCodec(new ProtobufCodecOptions.Builder().setEnableASCIIOnlyStrings(true).build());
    byte[] bytes = TestUtil.dataComplexToBytes(codec, dataComplex);
    DataComplex decodedDataComplex = decode(bytes, chunkSize);
    assertEquals(TestUtil.dataComplexToBytes(codec, decodedDataComplex), bytes);
}
Also used : DataComplex(com.linkedin.data.DataComplex) ProtobufDataCodec(com.linkedin.data.codec.ProtobufDataCodec) ProtobufCodecOptions(com.linkedin.data.codec.ProtobufCodecOptions) 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