Search in sources :

Example 66 with Input

use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.

the class PairSerdeTest method simpleSerdeTest.

@Test
public void simpleSerdeTest() {
    PairSerde<String, Integer> serdePair = new PairSerde<>(new StringSerde(), new IntSerde());
    Pair<String, Integer> pair = new ImmutablePair<>("abc", 123);
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    serdePair.serialize(pair, buffer);
    Slice slice = buffer.toSlice();
    Pair<String, Integer> deserializedPair = serdePair.deserialize(new Input(slice.buffer, slice.offset, slice.length));
    Assert.assertEquals(pair, deserializedPair);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) ImmutablePair(org.apache.commons.lang3.tuple.ImmutablePair) Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 67 with Input

use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.

the class SpillableTestUtils method checkValue.

public static <T> void checkValue(SpillableStateStore store, long bucketId, byte[] bytes, T expectedValue, int offset, Serde<T> serde) {
    Slice slice = store.getSync(bucketId, new Slice(bytes));
    if (slice == null || slice.length == 0) {
        if (expectedValue != null) {
            Assert.assertEquals(expectedValue, slice);
        } else {
            return;
        }
    }
    T string = serde.deserialize(new Input(slice.buffer, slice.offset + offset, slice.length));
    Assert.assertEquals(expectedValue, string);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice)

Example 68 with Input

use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.

the class GenericSerdeTest method timeWindowSerdeTest.

@Test
public void timeWindowSerdeTest() {
    GenericSerde<Window.TimeWindow>[] serdes = new GenericSerde[] { new GenericSerde<>(Window.TimeWindow.class), GenericSerde.DEFAULT };
    for (GenericSerde<Window.TimeWindow> serde : serdes) {
        Window.TimeWindow pojo = new Window.TimeWindow(System.currentTimeMillis(), 1000);
        SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
        serde.serialize(pojo, buffer);
        Slice slice = buffer.toSlice();
        Window.TimeWindow deserializedPojo = serde.deserialize(new Input(slice.buffer, slice.offset, slice.length));
        Assert.assertEquals(pojo, deserializedPojo);
    }
}
Also used : Window(org.apache.apex.malhar.lib.window.Window) Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 69 with Input

use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.

the class GenericSerdeTest method stringListTest.

@Test
public void stringListTest() {
    GenericSerde<ArrayList> serdeList = new GenericSerde<>(ArrayList.class);
    ArrayList<String> stringList = Lists.newArrayList("a", "b", "c");
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    serdeList.serialize(stringList, buffer);
    Slice slice = buffer.toSlice();
    List<String> deserializedList = serdeList.deserialize(new Input(slice.buffer, slice.offset, slice.length));
    Assert.assertEquals(stringList, deserializedList);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 70 with Input

use of com.esotericsoftware.kryo.io.Input in project apex-malhar by apache.

the class SerdeGeneralTest method testSerdeInt.

@Test
public void testSerdeInt() {
    IntSerde intSerde = new IntSerde();
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    int value = 123;
    intSerde.serialize(value, buffer);
    Slice slice = buffer.toSlice();
    int deserializedValue = intSerde.deserialize(new Input(slice.buffer, slice.offset, slice.length));
    Assert.assertEquals(value, deserializedValue);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Aggregations

Input (com.esotericsoftware.kryo.io.Input)73 Kryo (com.esotericsoftware.kryo.Kryo)37 Output (com.esotericsoftware.kryo.io.Output)28 ByteArrayInputStream (java.io.ByteArrayInputStream)23 ByteArrayOutputStream (java.io.ByteArrayOutputStream)21 Test (org.junit.Test)19 Slice (com.datatorrent.netlet.util.Slice)9 Test (org.testng.annotations.Test)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 StdInstantiatorStrategy (org.objenesis.strategy.StdInstantiatorStrategy)4 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 HashMap (java.util.HashMap)3 Schema (co.cask.cdap.api.data.schema.Schema)2 SAMFileHeader (htsjdk.samtools.SAMFileHeader)2 ObjectInput (java.io.ObjectInput)2