Search in sources :

Example 1 with Bytecode

use of org.apache.tinkerpop.gremlin.process.traversal.Bytecode in project janusgraph by JanusGraph.

the class JanusGraphIoRegistryTest method serializationTest.

private void serializationTest(GraphTraversal[] traversals) throws SerializationException {
    Builder mapper = GryoMapper.build().addRegistry(JanusGraphIoRegistry.getInstance());
    MessageSerializer binarySerializer = new GryoMessageSerializerV1d0(mapper);
    for (GraphTraversal traversal : traversals) {
        Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
        RequestMessage requestMessage = RequestMessage.build(Tokens.OPS_BYTECODE).processor("traversal").addArg(Tokens.ARGS_GREMLIN, expectedBytecode).create();
        ByteBuf bb = binarySerializer.serializeRequestAsBinary(requestMessage, allocator);
        final int mimeLen = bb.readByte();
        bb.readBytes(new byte[mimeLen]);
        RequestMessage deser = binarySerializer.deserializeRequest(bb);
        Bytecode result = (Bytecode) deser.getArgs().get(Tokens.ARGS_GREMLIN);
        assertEquals(expectedBytecode, result);
    }
}
Also used : MessageSerializer(org.apache.tinkerpop.gremlin.driver.MessageSerializer) Builder(org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper.Builder) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) RequestMessage(org.apache.tinkerpop.gremlin.driver.message.RequestMessage) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) ByteBuf(io.netty.buffer.ByteBuf) GryoMessageSerializerV1d0(org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)1 MessageSerializer (org.apache.tinkerpop.gremlin.driver.MessageSerializer)1 RequestMessage (org.apache.tinkerpop.gremlin.driver.message.RequestMessage)1 GryoMessageSerializerV1d0 (org.apache.tinkerpop.gremlin.driver.ser.GryoMessageSerializerV1d0)1 Bytecode (org.apache.tinkerpop.gremlin.process.traversal.Bytecode)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 Builder (org.apache.tinkerpop.gremlin.structure.io.gryo.GryoMapper.Builder)1