Java Code Examples for org.apache.tinkerpop.gremlin.structure.io.GraphWriter#writeGraph()

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.GraphWriter#writeGraph() . 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: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Vertex ids.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexIds() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);
    sampleGraph1.addVertex(T.id, 100L, "name", "kevin");
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized vertex Id.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 2
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Vertex props.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexProps() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);

    sampleGraph1.addVertex(T.id, 100, "name", "kevin", "uuid", UUID.randomUUID());
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized vertex prop.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 3
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Edge ids.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeIds() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);
    final  Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
    v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101L);
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized edge Id.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 4
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Edge props.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final Graph sampleGraph1 = TinkerFactory.createModern();

    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
    v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
            "uuid", UUID.randomUUID());
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized edge prop.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 5
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Vertex ids.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexIds() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);
    sampleGraph1.addVertex(T.id, 100L, "name", "kevin");
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized vertex Id.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 6
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Vertex props.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForVertexProps() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);

    sampleGraph1.addVertex(T.id, 100, "name", "kevin", "uuid", UUID.randomUUID());
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized vertex prop.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 7
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Edge ids.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeIds() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final TinkerGraph sampleGraph1 = TinkerGraph.open();
    TinkerFactory.generateModern(sampleGraph1);
    final  Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
    v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101L);
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized edge Id.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 8
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Asserts the approximateGraphsChecks function fails when expected. Edge props.
 */
@Test
public void shouldLoseTypesWithGraphSONNoTypesForEdgeProps() throws IOException {
    final GraphWriter writer = getWriter(noTypesMapperV2d0);
    final GraphReader reader = getReader(noTypesMapperV2d0);
    final Graph sampleGraph1 = TinkerFactory.createModern();

    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin");
    v1.addEdge("hello", sampleGraph1.traversal().V().has("name", "marko").next(), T.id, 101,
            "uuid", UUID.randomUUID());
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, sampleGraph1);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        // Should fail on deserialized edge prop.
        assertFalse(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
Example 9
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 10
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 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 11
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * Those kinds of types are declared differently in the GraphSON type deserializer, check that all are handled
 * properly.
 */
@Test
public void shouldKeepTypesWhenDeserializingSerializedTinkerGraph() throws IOException {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final UUID uuidProp = UUID.randomUUID();
    final Duration durationProp = Duration.ofHours(3);
    final Long longProp = 2L;
    final ByteBuffer byteBufferProp = ByteBuffer.wrap("testbb".getBytes());
    final InetAddress inetAddressProp = InetAddress.getByName("10.10.10.10");

    // One Java util type natively supported by Jackson
    v.property("uuid", uuidProp);
    // One custom time type added by the GraphSON module
    v.property("duration", durationProp);
    // One Java native type not handled by JSON natively
    v.property("long", longProp);
    // One Java util type added by GraphSON
    v.property("bytebuffer", byteBufferProp);
    v.property("inetaddress", inetAddressProp);


    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, tg);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        final Vertex vRead = read.traversal().V().hasLabel("vertexTest").next();
        assertEquals(vRead.property("uuid").value(), uuidProp);
        assertEquals(vRead.property("duration").value(), durationProp);
        assertEquals(vRead.property("long").value(), longProp);
        assertEquals(vRead.property("bytebuffer").value(), byteBufferProp);
        assertEquals(vRead.property("inetaddress").value(), inetAddressProp);
    }
}
 
Example 12
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 13
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 14
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 15
Source File: TinkerGraphGraphSONSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * Those kinds of types are declared differently in the GraphSON type deserializer, check that all are handled
 * properly.
 */
@Test
public void shouldKeepTypesWhenDeserializingSerializedTinkerGraph() throws IOException {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final UUID uuidProp = UUID.randomUUID();
    final Duration durationProp = Duration.ofHours(3);
    final Long longProp = 2L;
    final ByteBuffer byteBufferProp = ByteBuffer.wrap("testbb".getBytes());
    final InetAddress inetAddressProp = InetAddress.getByName("10.10.10.10");

    // One Java util type natively supported by Jackson
    v.property("uuid", uuidProp);
    // One custom time type added by the GraphSON module
    v.property("duration", durationProp);
    // One Java native type not handled by JSON natively
    v.property("long", longProp);
    // One Java util type added by GraphSON
    v.property("bytebuffer", byteBufferProp);
    v.property("inetaddress", inetAddressProp);


    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);
    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeGraph(out, tg);
        final String json = out.toString();
        final TinkerGraph read = TinkerGraph.open();
        reader.readGraph(new ByteArrayInputStream(json.getBytes()), read);
        final Vertex vRead = read.traversal().V().hasLabel("vertexTest").next();
        assertEquals(vRead.property("uuid").value(), uuidProp);
        assertEquals(vRead.property("duration").value(), durationProp);
        assertEquals(vRead.property("long").value(), longProp);
        assertEquals(vRead.property("bytebuffer").value(), byteBufferProp);
        assertEquals(vRead.property("inetaddress").value(), inetAddressProp);
    }
}