Search in sources :

Example 51 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class StoreOperator method insertValueToStore.

private void insertValueToStore(KeyValPair<byte[], byte[]> tuple) {
    Slice key = new Slice(tuple.getKey());
    Slice value = new Slice(tuple.getValue());
    store.put(System.currentTimeMillis(), key, value);
}
Also used : Slice(com.datatorrent.netlet.util.Slice)

Example 52 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class StoreOperator method processTuple.

private void processTuple(KeyValPair<byte[], byte[]> tuple) {
    switch(execMode) {
        case UPDATE_ASYNC:
            // handle it specially
            updateAsync(tuple);
            break;
        case UPDATE_SYNC:
            keySliceForRead.buffer = tuple.getKey();
            keySliceForRead.offset = 0;
            keySliceForRead.length = tuple.getKey().length;
            store.getSync(getTimeByKey(tuple.getKey()), keySliceForRead);
            insertValueToStore(tuple);
            break;
        case GET_SYNC:
            store.getSync(getTimeByKey(tuple.getKey()), new Slice(tuple.getKey()));
            break;
        case DO_NOTHING:
            break;
        default:
            // insert
            insertValueToStore(tuple);
    }
    ++tupleCount;
}
Also used : Slice(com.datatorrent.netlet.util.Slice)

Example 53 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class AffixSerdeTest method simpleTest.

@Test
public void simpleTest() {
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    AffixSerde<String> serde = new AffixSerde<>(new byte[] { 1, 2, 3 }, new StringSerde(), new byte[] { 9 });
    final String orgValue = "abc";
    serde.serialize(orgValue, buffer);
    Slice slice = buffer.toSlice();
    String value = serde.deserialize(new Input(slice.buffer, slice.offset, slice.length));
    Assert.assertEquals(orgValue, value);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Example 54 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class CollectionSerdeTest method testSerdeList.

@Test
public void testSerdeList() {
    CollectionSerde<String, List<String>> serdeList = new CollectionSerde<>(new StringSerde(), (Class) ArrayList.class);
    List<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) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 55 with Slice

use of com.datatorrent.netlet.util.Slice in project apex-malhar by apache.

the class GenericSerdeTest method pojoTest.

@Test
public void pojoTest() {
    GenericSerde<TestPojo> serdePojo = new GenericSerde<>();
    TestPojo pojo = new TestPojo(345, "xyz");
    SerializationBuffer buffer = new SerializationBuffer(new WindowedBlockStream());
    serdePojo.serialize(pojo, buffer);
    Slice slice = buffer.toSlice();
    TestPojo deserializedPojo = serdePojo.deserialize(new Input(slice.buffer, slice.offset, slice.length));
    Assert.assertEquals(pojo, deserializedPojo);
}
Also used : Input(com.esotericsoftware.kryo.io.Input) Slice(com.datatorrent.netlet.util.Slice) Test(org.junit.Test)

Aggregations

Slice (com.datatorrent.netlet.util.Slice)114 Test (org.junit.Test)65 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Input (com.esotericsoftware.kryo.io.Input)9 IOException (java.io.IOException)6 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 BufferSlice (org.apache.apex.malhar.lib.utils.serde.BufferSlice)4 Path (org.apache.hadoop.fs.Path)4 ObjectMapperString (com.datatorrent.common.util.ObjectMapperString)3 SerializationBuffer (org.apache.apex.malhar.lib.utils.serde.SerializationBuffer)3 StringSerde (org.apache.apex.malhar.lib.utils.serde.StringSerde)3 Attribute (com.datatorrent.api.Attribute)2 OperatorContext (com.datatorrent.api.Context.OperatorContext)2 Output (com.esotericsoftware.kryo.io.Output)2 RandomAccessFile (java.io.RandomAccessFile)2 Serializable (java.io.Serializable)2 HashSet (java.util.HashSet)2