Search in sources :

Example 1 with GraphSONReader

use of org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader in project janusgraph by JanusGraph.

the class JanusGraphSONModuleTest method graphsonSerializationTest.

private void graphsonSerializationTest(GraphTraversal[] traversals, GraphSONVersion version) throws Exception {
    final GraphSONMapper mapper = GraphSONMapper.build().version(version).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.instance()).create();
    final GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
    final GraphSONReader reader = GraphSONReader.build().mapper(mapper).create();
    for (GraphTraversal traversal : traversals) {
        Bytecode expectedBytecode = traversal.asAdmin().getBytecode();
        ByteArrayOutputStream serializationStream = new ByteArrayOutputStream();
        writer.writeObject(serializationStream, expectedBytecode);
        ByteArrayInputStream inputStream = new ByteArrayInputStream(serializationStream.toByteArray());
        Bytecode result = reader.readObject(inputStream, Bytecode.class);
        assertEquals(expectedBytecode, result);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) GraphSONMapper(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper) GraphSONWriter(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter) GraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal) Bytecode(org.apache.tinkerpop.gremlin.process.traversal.Bytecode) GraphSONReader(org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Bytecode (org.apache.tinkerpop.gremlin.process.traversal.Bytecode)1 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)1 GraphSONMapper (org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper)1 GraphSONReader (org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader)1 GraphSONWriter (org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter)1