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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations