org.apache.tinkerpop.gremlin.structure.io.IoTest Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.IoTest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistWithRelativePath() {
    final String graphLocation = TestHelper.convertToRelative(TinkerGraphTest.class,
                                                              TestHelper.makeTestDataPath(TinkerGraphTest.class))
                                 + "shouldPersistToGryoRelative.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #2
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistWithRelativePath() {
    final String graphLocation = TestHelper.convertToRelative(TinkerGraphTest.class,
            new File(TestHelper.makeTestDataDirectory(TinkerGraphTest.class)))  + "shouldPersistToGryoRelative.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #3
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGryoAndHandleMultiProperties() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGryoMulti.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateTheCrew(graph);
    graph.close();

    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.toString());
    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertCrewGraph(reloadedGraph, false);
    reloadedGraph.close();
}
 
Example #4
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGryo() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGryo.kryo";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #5
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGraphSON() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphSON.json";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphson");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #6
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGraphML() {
    final String graphLocation = TestHelper.makeTestDataDirectory(TinkerGraphTest.class) + "shouldPersistToGraphML.xml";
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, true);
    reloadedGraph.close();
}
 
Example #7
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGraphML() {
    final String graphLocation = TestHelper.makeTestDataFile(TinkerGraphTest.class, "shouldPersistToGraphML.xml");
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphml");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, true);
    reloadedGraph.close();
}
 
Example #8
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGraphSON() {
    final String graphLocation = TestHelper.makeTestDataFile(TinkerGraphTest.class, "shouldPersistToGraphSON.json");
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "graphson");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #9
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGryo() {
    final String graphLocation = TestHelper.makeTestDataFile(TinkerGraphTest.class, "shouldPersistToGryo.kryo");
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateModern(graph);
    graph.close();

    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertModernGraph(reloadedGraph, true, false);
    reloadedGraph.close();
}
 
Example #10
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPersistToGryoAndHandleMultiProperties() {
    final String graphLocation = TestHelper.makeTestDataFile(TinkerGraphTest.class, "shouldPersistToGryoMulti.kryo");
    final File f = new File(graphLocation);
    if (f.exists() && f.isFile()) f.delete();

    final Configuration conf = new BaseConfiguration();
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_FORMAT, "gryo");
    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_GRAPH_LOCATION, graphLocation);
    final TinkerGraph graph = TinkerGraph.open(conf);
    TinkerFactory.generateTheCrew(graph);
    graph.close();

    conf.setProperty(TinkerGraph.GREMLIN_TINKERGRAPH_DEFAULT_VERTEX_PROPERTY_CARDINALITY, VertexProperty.Cardinality.list.toString());
    final TinkerGraph reloadedGraph = TinkerGraph.open(conf);
    IoTest.assertCrewGraph(reloadedGraph, false);
    reloadedGraph.close();
}
 
Example #11
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create();
        writer.writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final GraphReader reader = GraphSONReader.build().mapper(mapper).create();
            final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #12
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_readXjsonX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphSONResourceAccess.class, "tinkerpop-modern-v3d0.json", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_readXjsonX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #13
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphWithMultiPropertiesToGraphSON() throws Exception {
    final TinkerGraph graph = TinkerFactory.createTheCrew();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.graphson()).writer().create().writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final TinkerGraph target = graph.io(IoCore.graphson()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertCrewGraph(target, false);
        }
    }
}
 
Example #14
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGraphSON() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.graphson()).writer().create().writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final TinkerGraph target = graph.io(IoCore.graphson()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #15
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphWithMultiPropertiesToGryo() throws Exception {
    final TinkerGraph graph = TinkerFactory.createTheCrew();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.gryo()).writer().create().writeObject(out, graph);
        final byte[] b = out.toByteArray();
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(b)) {
            final TinkerGraph target = graph.io(IoCore.gryo()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertCrewGraph(target, false);
        }
    }
}
 
Example #16
Source File: TinkerGraphTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGryo() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.gryo()).writer().create().writeObject(out, graph);
        final byte[] b = out.toByteArray();
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(b)) {
            final TinkerGraph target = graph.io(IoCore.gryo()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #17
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the graph has been fully ser/deser without types.
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphWithoutTypes() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph baseModern = TinkerFactory.createModern();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, baseModern);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        IoTest.assertModernGraph(read, true, false);
    }
}
 
Example #18
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the graph has been fully ser/deser with types.
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphWithPartialTypes() throws IOException {
    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);
    final  TinkerGraph baseModern = TinkerFactory.createModern();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, baseModern);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        IoTest.assertModernGraph(read, true, false);
    }
}
 
Example #19
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_read_withXreader_graphmlX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphMLResourceAccess.class, "tinkerpop-modern.xml", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_read_withXreader_graphmlX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #20
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_readXxmlX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphMLResourceAccess.class, "tinkerpop-modern.xml", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_readXxmlX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #21
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_read_withXreader_graphsonX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GraphSONResourceAccess.class, "tinkerpop-modern-v3d0.json", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_read_withXreader_graphsonX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #22
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * Checks that the graph has been fully ser/deser with types.
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphWithPartialTypes() throws IOException {
    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);
    final  TinkerGraph baseModern = TinkerFactory.createModern();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, baseModern);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        IoTest.assertModernGraph(read, true, false);
    }
}
 
Example #23
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_read_withXreader_gryoX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_read_withXreader_gryoX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #24
Source File: ReadTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.GraphFeatures.class, feature = Graph.Features.GraphFeatures.FEATURE_IO_READ)
public void g_io_readXkryoX() throws IOException {
    final String fileToRead = TestHelper.generateTempFileFromResource(ReadTest.class, GryoResourceAccess.class, "tinkerpop-modern-v3d0.kryo", "").getAbsolutePath().replace('\\', '/');
    final Traversal<Object,Object> traversal = get_g_io_readXkryoX(fileToRead);
    printTraversalForm(traversal);
    traversal.iterate();

    if (graph instanceof RemoteGraph) {
        assertEquals(6L, g.V().count().next().longValue());
        assertEquals(6L, g.E().count().next().longValue());
    } else {
        IoTest.assertModernGraph(graph, false, true);
    }
}
 
Example #25
Source File: GremlinResultSetIntegrateTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldHandleTinkerGraphResult() throws Exception {
    final ResultSet results = client.submit("modern");
    final Graph graph = results.all().get().get(0).get(TinkerGraph.class);

    // test is "lossy for id" because TinkerGraph is configured by default to use the ANY id manager
    // and doesn't coerce to specific types - which is how it is on the server as well so we can expect
    // some id shiftiness
    IoTest.assertModernGraph(graph, true, true);
}
 
Example #26
Source File: CustomTest.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Ignore
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
public void shouldReadWriteModern() throws Exception {
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        ((HBaseGraph) graph).createIndex(ElementType.EDGE, "knows", "weight");
        final GraphWriter writer = graph.io(ioBuilderToTest).writer().create();
        writer.writeGraph(os, graph);

        final Configuration configuration = graphProvider.newGraphConfiguration("readGraph", this.getClass(), name.getMethodName(), LoadGraphWith.GraphData.MODERN);
        graphProvider.clear(configuration);
        final Graph g1 = graphProvider.openTestGraph(configuration);
        ((HBaseGraph) g1).createIndex(ElementType.EDGE, "knows", "weight");
        final GraphReader reader = graph.io(ioBuilderToTest).reader().create();
        //((HBaseGraph) graph).dump();
        //((HBaseGraph) g1).dump();
        try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
            reader.readGraph(bais, g1);
        }

        // modern uses double natively so always assert as such
        IoTest.assertModernGraph(g1, true, lossyForId);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #27
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGraphSONWithTypes() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    final Mapper<ObjectMapper> mapper = graph.io(IoCore.graphson()).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        final GraphWriter writer = GraphSONWriter.build().mapper(mapper).create();
        writer.writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final GraphReader reader = GraphSONReader.build().mapper(mapper).create();
            final TinkerGraph target = reader.readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #28
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphWithMultiPropertiesToGraphSON() throws Exception {
    final TinkerGraph graph = TinkerFactory.createTheCrew();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.graphson()).writer().create().writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final TinkerGraph target = graph.io(IoCore.graphson()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertCrewGraph(target, false);
        }
    }
}
 
Example #29
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphToGraphSON() throws Exception {
    final TinkerGraph graph = TinkerFactory.createModern();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.graphson()).writer().create().writeObject(out, graph);
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(out.toByteArray())) {
            final TinkerGraph target = graph.io(IoCore.graphson()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertModernGraph(target, true, false);
        }
    }
}
 
Example #30
Source File: TinkerGraphTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSerializeTinkerGraphWithMultiPropertiesToGryo() throws Exception {
    final TinkerGraph graph = TinkerFactory.createTheCrew();
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        graph.io(IoCore.gryo()).writer().create().writeObject(out, graph);
        final byte[] b = out.toByteArray();
        try (final ByteArrayInputStream inputStream = new ByteArrayInputStream(b)) {
            final TinkerGraph target = graph.io(IoCore.gryo()).reader().create().readObject(inputStream, TinkerGraph.class);
            IoTest.assertCrewGraph(target, false);
        }
    }
}