当前位置: 首页>>代码示例>>Java>>正文


Java GraphWriter类代码示例

本文整理汇总了Java中org.apache.tinkerpop.gremlin.structure.io.GraphWriter的典型用法代码示例。如果您正苦于以下问题:Java GraphWriter类的具体用法?Java GraphWriter怎么用?Java GraphWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


GraphWriter类属于org.apache.tinkerpop.gremlin.structure.io包,在下文中一共展示了GraphWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * Thorough types verification for Vertex ids, Vertex props, Edge ids, Edge props
 */
@Test
public void shouldDeserializeGraphSONIntoTinkerGraphKeepingTypes() throws IOException {
    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Graph sampleGraph1 = TinkerFactory.createModern();
    final Vertex v1 = sampleGraph1.addVertex(T.id, 100, "name", "kevin", "theUUID", UUID.randomUUID());
    final Vertex v2 = sampleGraph1.addVertex(T.id, 101L, "name", "henri", "theUUID", UUID.randomUUID());
    v1.addEdge("hello", v2, T.id, 101L,
            "uuid", UUID.randomUUID());

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, sampleGraph1);
        final String json = out.toString();

        final TinkerGraph read = reader.readObject(new ByteArrayInputStream(json.getBytes()), TinkerGraph.class);
        assertTrue(approximateGraphsCheck(sampleGraph1, read));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:23,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例2: shouldLoseTypesWithGraphSONNoTypesForVertexIds

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:20,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例3: shouldLoseTypesWithGraphSONNoTypesForVertexProps

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:21,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例4: shouldLoseTypesWithGraphSONNoTypesForEdgeIds

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:21,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例5: shouldLoseTypesWithGraphSONNoTypesForEdgeProps

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * 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));
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:22,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例6: deserializersTestsVertex

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void deserializersTestsVertex() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));
    v.property("dead", LocalDateTime.of(1971, 1, 7, 20, 50));

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, v);
        final String json = out.toString();

        // Object works, because there's a type in the payload now
        // Vertex.class would work as well
        // Anything else would not because we check the type in param here with what's in the JSON, for safety.
        final Vertex vRead = (Vertex)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertEquals(v, vRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:26,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例7: deserializersTestsEdge

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void deserializersTestsEdge() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    final Edge ed = v.addEdge("knows", v2, "time", LocalDateTime.now());

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, ed);
        final String json = out.toString();

        // Object works, because there's a type in the payload now
        // Edge.class would work as well
        // Anything else would not because we check the type in param here with what's in the JSON, for safety.
        final Edge eRead = (Edge)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertEquals(ed, eRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:27,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例8: deserializersTestsTinkerGraph

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void deserializersTestsTinkerGraph() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");
    final Vertex v2 = tg.addVertex("vertexTest");

    v.addEdge("knows", v2);

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, tg);
        final String json = out.toString();

        final Graph gRead = (Graph)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        assertTrue(approximateGraphsCheck(tg, gRead));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:24,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例9: deserializersTestsVertexProperty

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void deserializersTestsVertexProperty() {
    final TinkerGraph tg = TinkerGraph.open();

    final Vertex v = tg.addVertex("vertexTest");

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final VertexProperty prop = v.property("born", LocalDateTime.of(1971, 1, 2, 20, 50));

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, prop);
        final String json = out.toString();

        final VertexProperty vPropRead = (VertexProperty)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //only classes and ids are checked, that's ok, full vertex property ser/de
        //is checked elsewhere.
        assertEquals(prop, vPropRead);
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例10: deserializersTestsTraversalMetrics

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void deserializersTestsTraversalMetrics() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final TraversalMetrics tm = tg.traversal().V(1).as("a").has("name").as("b").
            out("knows").out("created").as("c").
            has("name", "ripple").values("name").as("d").
            identity().as("e").profile().next();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, tm);
        final String json = out.toString();

        final TraversalMetrics traversalMetricsRead = (TraversalMetrics)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        // toString should be enough to compare TraversalMetrics
        assertTrue(tm.toString().equals(traversalMetricsRead.toString()));
    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:25,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例11: deserializersTestsTree

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
@org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509")
public void deserializersTestsTree() {
    final TinkerGraph tg = TinkerFactory.createModern();

    final GraphWriter writer = getWriter(defaultMapperV2d0);
    final GraphReader reader = getReader(defaultMapperV2d0);

    final Tree t = tg.traversal().V().out().out().tree().next();

    try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        writer.writeObject(out, t);
        final String json = out.toString();

        final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class);
        //Map's equals should check each component of the tree recursively
        //on each it will call "equals()" which for Vertices will compare ids, which
        //is ok. Complete vertex deser is checked elsewhere.
        assertEquals(t, treeRead);

    } catch (IOException e) {
        e.printStackTrace();
        fail("Should not have thrown exception: " + e.getMessage());
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:26,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java

示例12: shouldReadWriteModern

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:rayokota,项目名称:hgraphdb,代码行数:27,代码来源:CustomTest.java

示例13: shouldToStringUnknownObjects

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Test
public void shouldToStringUnknownObjects() {
    GraphSONMapper gm20 = GraphSONMapper.build().version(GraphSONVersion.V2_0).create();
    GraphSONMapper gm10 = GraphSONMapper.build().version(GraphSONVersion.V1_0).create();

    GraphWriter writer = GraphSONWriter.build().mapper(gm20).create();
    // subsequent creations of GraphWriters and GraphSONMappers should not affect
    // each other.
    GraphWriter writer2 = GraphSONWriter.build().mapper(gm10).create();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        writer.writeObject(baos, new FunObject("value"));
        assertEquals(baos.toString(), "\"value\"");
    } catch (Exception e) {
        fail("should have succeeded serializing the unknown object to a string");
    }
}
 
开发者ID:apache,项目名称:tinkerpop,代码行数:19,代码来源:GraphSONMessageSerializerV2d0Test.java

示例14: data

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
@Parameterized.Parameters(name = "{0}")
public static Iterable<Object[]> data() {
    return Arrays.asList(new Object[][]{
            {"graphson-v1", false, false,
                    (Function<Graph,GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().create()},
            {"graphson-v1-embedded", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V1_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v2", false, false,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.NO_TYPES).create()).create()},
            {"graphson-v2-embedded", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V2_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()},
            {"graphson-v3", true, true,
                    (Function<Graph, GraphReader>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).reader().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GraphSONIo.build(GraphSONVersion.V3_0)).writer().mapper(g.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().create()).create()},
            {"gryo-v1", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V1_0)).writer().create()},
            {"gryo-v3", true, true,
                    (Function<Graph,GraphReader>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).reader().create(),
                    (Function<Graph, GraphWriter>) g -> g.io(GryoIo.build(GryoVersion.V3_0)).writer().create()}
    });
}
 
开发者ID:pietermartin,项目名称:sqlg,代码行数:27,代码来源:TestIoEdge.java

示例15: shouldDeserializeGraphSONIntoTinkerGraphWithPartialTypes

import org.apache.tinkerpop.gremlin.structure.io.GraphWriter; //导入依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:ShiftLeftSecurity,项目名称:tinkergraph-gremlin,代码行数:18,代码来源:TinkerGraphGraphSONSerializerV2d0Test.java


注:本文中的org.apache.tinkerpop.gremlin.structure.io.GraphWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。