org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper Java Examples

The following examples show how to use org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper. 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: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModernWrappedInJsonObject() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V1_0).create();
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(graphson()).writer().wrapAdjacencyList(true).mapper(mapper).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);
        final GraphReader reader = graph.io(graphson()).reader().mapper(mapper).unwrapAdjacencyList(true).create();
        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, true);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #2
Source File: GraphSONTranslator.java    From tinkergraph-gremlin with Apache License 2.0 6 votes vote down vote up
public GraphSONTranslator(final JavaTranslator<S, T> wrappedTranslator, final GraphSONVersion version) {
    this.wrappedTranslator = wrappedTranslator;
    final GraphSONMapper mapper;
    if (version == GraphSONVersion.V2_0) {
        mapper = GraphSONMapper.build()
                .addCustomModule(GraphSONXModuleV2d0.build().create(false)).version(GraphSONVersion.V2_0).create();
    } else if (version == GraphSONVersion.V3_0) {
        mapper = GraphSONMapper.build()
                .addCustomModule(GraphSONXModuleV3d0.build().create(false)).version(GraphSONVersion.V3_0).create();
    } else {
        throw new IllegalArgumentException("GraphSONVersion." + version.name() + " is not supported for testing");
    }

    writer = GraphSONWriter.build().mapper(mapper).create();
    reader = GraphSONReader.build().mapper(mapper).create();
}
 
Example #3
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #4
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeAndDeserializeRequestMessageFromObjectMapper() throws IOException {
    final ObjectMapper om = GraphSONMapper.build().version(GraphSONVersion.V2_0)
            .addCustomModule(new GraphSONMessageSerializerGremlinV2d0.GremlinServerModule())
            .create().createMapper();

    final Map<String, Object> requestBindings = new HashMap<>();
    requestBindings.put("x", 1);

    final Map<String, Object> requestAliases = new HashMap<>();
    requestAliases.put("g", "social");

    final RequestMessage requestMessage = RequestMessage.build("eval").processor("session").
            overrideRequestId(UUID.fromString("cb682578-9d92-4499-9ebc-5c6aa73c5397")).
            add("gremlin", "social.V(x)", "bindings", requestBindings, "language", "gremlin-groovy", "aliases", requestAliases, "session", UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).create();

    final String json = om.writeValueAsString(requestMessage);
    final RequestMessage readRequestMessage = om.readValue(json, RequestMessage.class);

    assertEquals(requestMessage.getOp(), readRequestMessage.getOp());
    assertEquals(requestMessage.getProcessor(), readRequestMessage.getProcessor());
    assertEquals(requestMessage.getRequestId(), readRequestMessage.getRequestId());
    assertEquals(requestMessage.getArgs(), readRequestMessage.getArgs());
}
 
Example #5
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldSerializeAndDeserializeResponseMessageFromObjectMapper() throws IOException {
    final ObjectMapper om = GraphSONMapper.build().version(GraphSONVersion.V2_0)
            .addCustomModule(new GraphSONMessageSerializerGremlinV2d0.GremlinServerModule())
            .create().createMapper();
    final Graph graph = TinkerFactory.createModern();

    final ResponseMessage responseMessage = ResponseMessage.build(UUID.fromString("41d2e28a-20a4-4ab0-b379-d810dede3786")).
            code(org.apache.tinkerpop.gremlin.driver.message.ResponseStatusCode.SUCCESS).
            result(Collections.singletonList(graph.vertices().next())).create();

    final String respJson = om.writeValueAsString(responseMessage);
    final ResponseMessage responseMessageRead = om.readValue(respJson, ResponseMessage.class);

    assertEquals(responseMessage.getRequestId(), responseMessageRead.getRequestId());
    assertEquals(responseMessage.getResult().getMeta(), responseMessageRead.getResult().getMeta());
    assertEquals(responseMessage.getResult().getData(), responseMessageRead.getResult().getData());
    assertEquals(responseMessage.getStatus().getAttributes(), responseMessageRead.getStatus().getAttributes());
    assertEquals(responseMessage.getStatus().getCode().getValue(), responseMessageRead.getStatus().getCode().getValue());
    assertEquals(responseMessage.getStatus().getCode().isSuccess(), responseMessageRead.getStatus().getCode().isSuccess());
    assertEquals(responseMessage.getStatus().getMessage(), responseMessageRead.getStatus().getMessage());
}
 
Example #6
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void shouldFailOnMessageSerializerWithMapperIfNoGremlinServerModule() {
    org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(AbstractGraphSONMessageSerializerV2d0.class);
    Level previousLevel = logger.getLevel();

    // Disable temporarily logging for this test
    logger.setLevel(Level.OFF);

    GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV2d0.build().create(false));
    GraphSONMessageSerializerV2d0 graphSONMessageSerializerV2d0 = new GraphSONMessageSerializerV2d0(builder.create());

    try {
        convert("hello", graphSONMessageSerializerV2d0);
        fail("Serialization should have failed since no GremlinServerModule registered.");
    } catch (SerializationException e) {
        assertTrue(e.getMessage().contains("Could not find a type identifier for the class"));
        assertTrue(e.getCause() instanceof JsonMappingException);
        assertTrue(e.getCause().getCause() instanceof IllegalArgumentException);
    }

    // Put logger level back to its original value
    logger.setLevel(previousLevel);
}
 
Example #7
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers.
 */
@Test
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldWriteNormalizedGraphSON() throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V1_0).normalize(true).create();
        final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create();
        w.writeGraph(bos, graph);

        final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v1d0.json"));
        assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
    }
}
 
Example #8
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V1_0).create();
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphson()).writer().mapper(mapper).create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphson()).reader().mapper(mapper).create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
Example #9
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers.
 */
@Test
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldWriteNormalizedGraphSON() throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).normalize(true).create();
        final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create();
        w.writeGraph(bos, graph);

        final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v2d0.json"));
        assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
    }
}
 
Example #10
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V2_0).create();
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphson()).writer().mapper(mapper).create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphson()).reader().mapper(mapper).create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
Example #11
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
/**
 * Only need to execute this test with TinkerGraph or other graphs that support user supplied identifiers.
 */
@Test
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = VertexPropertyFeatures.class, feature = FEATURE_INTEGER_VALUES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = EdgePropertyFeatures.FEATURE_FLOAT_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_NUMERIC_IDS)
@FeatureRequirement(featureClass = Graph.Features.VertexPropertyFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
@FeatureRequirement(featureClass = Graph.Features.VariableFeatures.class, feature = FEATURE_VARIABLES)
@LoadGraphWith(LoadGraphWith.GraphData.CLASSIC)
public void shouldWriteNormalizedGraphSON() throws Exception {
    try (ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
        final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V3_0).normalize(true).create();
        final GraphSONWriter w = graph.io(graphson).writer().mapper(mapper).create();
        w.writeGraph(bos, graph);

        final String expected = streamToString(getResourceAsStream(GraphSONResourceAccess.class, "tinkerpop-classic-normalized-v3d0.json"));
        assertEquals(expected.replace("\n", "").replace("\r", ""), bos.toString().replace("\n", "").replace("\r", ""));
    }
}
 
Example #12
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@LoadGraphWith(LoadGraphWith.GraphData.MODERN)
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteModernWrappedInJsonObject() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V3_0).create();
    try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        final GraphWriter writer = graph.io(graphson()).writer().wrapAdjacencyList(true).mapper(mapper).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);
        final GraphReader reader = graph.io(graphson()).reader().mapper(mapper).unwrapAdjacencyList(true).create();
        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, true);

        graphProvider.clear(g1, configuration);
    }
}
 
Example #13
Source File: IoTest.java    From tinkerpop with Apache License 2.0 6 votes vote down vote up
@Test
@FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
@FeatureRequirement(featureClass = EdgePropertyFeatures.class, feature = FEATURE_STRING_VALUES)
@FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
public void shouldReadWriteSelfLoopingEdges() throws Exception {
    final GraphSONMapper mapper = graph.io(graphson).mapper().version(GraphSONVersion.V3_0).create();
    final Graph source = graph;
    final Vertex v1 = source.addVertex();
    final Vertex v2 = source.addVertex();
    v1.addEdge("CONTROL", v2);
    v1.addEdge("SELFLOOP", v1);

    final Configuration targetConf = graphProvider.newGraphConfiguration("target", this.getClass(), name.getMethodName(), null);
    final Graph target = graphProvider.openTestGraph(targetConf);
    try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
        source.io(IoCore.graphson()).writer().mapper(mapper).create().writeGraph(os, source);
        try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) {
            target.io(IoCore.graphson()).reader().mapper(mapper).create().readGraph(is, target);
        }
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    assertEquals(IteratorUtils.count(source.vertices()), IteratorUtils.count(target.vertices()));
    assertEquals(IteratorUtils.count(source.edges()), IteratorUtils.count(target.edges()));
}
 
Example #14
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphAsGraphSONV2d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-typed-v2d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #15
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphNormalizedAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-normalized-v3d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).normalize(true).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #16
Source File: GraphSONMessageSerializerV2d0Test.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldRegisterGremlinServerModuleAutomaticallyWithMapper() throws SerializationException {
    GraphSONMapper.Builder builder = GraphSONMapper.build().addCustomModule(GraphSONXModuleV2d0.build().create(false));
    GraphSONMessageSerializerV2d0 graphSONMessageSerializerV2d0 = new GraphSONMessageSerializerV2d0(builder);

    ResponseMessage rm = convert("hello", graphSONMessageSerializerV2d0);
    assertEquals(rm.getRequestId(), requestId);
    assertEquals(rm.getResult().getData(), "hello");
}
 
Example #17
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteModernGraphAsGraphSOV2d0NNoTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern-v2d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create()
            .writeGraph(os, TinkerFactory.createModern());
    os.close();
}
 
Example #18
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphAsGraphSONV1d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-typed-v1d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).create())
            .create().writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #19
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic-v3d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #20
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTModernGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-modern.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createModern());
    os.close();
}
 
Example #21
Source File: GraphSONRecordWriter.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
public GraphSONRecordWriter(final DataOutputStream outputStream, final Configuration configuration) {
    this.outputStream = outputStream;
    this.hasEdges = configuration.getBoolean(Constants.GREMLIN_HADOOP_GRAPH_WRITER_HAS_EDGES, true);
    this.graphsonWriter = GraphSONWriter.build().mapper(
            GraphSONMapper.build().
                    version(GraphSONVersion.valueOf(configuration.get(Constants.GREMLIN_HADOOP_GRAPHSON_VERSION, "V3_0"))).
                    typeInfo(TypeInfo.PARTIAL_TYPES).
                    addRegistries(IoRegistryHelper.createRegistries(ConfUtil.makeApacheConfiguration(configuration))).create()).create();
}
 
Example #22
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTModernGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-modern.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createModern());
    os.close();
}
 
Example #23
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTClassicGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-classic.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #24
Source File: GraphSONRecordReader.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException {
    this.lineRecordReader.initialize(genericSplit, context);
    this.hasEdges = context.getConfiguration().getBoolean(Constants.GREMLIN_HADOOP_GRAPH_READER_HAS_EDGES, true);
    this.graphsonReader = GraphSONReader.build().mapper(
            GraphSONMapper.build().
                    version(GraphSONVersion.valueOf(context.getConfiguration().get(Constants.GREMLIN_HADOOP_GRAPHSON_VERSION, "V3_0"))).
                    typeInfo(TypeInfo.PARTIAL_TYPES).
                    addRegistries(IoRegistryHelper.createRegistries(ConfUtil.makeApacheConfiguration(context.getConfiguration()))).create()).create();
}
 
Example #25
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTSinkGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createKitchenSink());
    os.close();
}
 
Example #26
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteCrewGraphAsGraphSONV2d0WithTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-crew-typed-v2d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).create()).create()
            .writeGraph(os, TinkerFactory.createTheCrew());
    os.close();
}
 
Example #27
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteClassicGraphNormalizedAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-classic-normalized-v3d0.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).normalize(true).create()).create()
            .writeGraph(os, TinkerFactory.createClassic());
    os.close();
}
 
Example #28
Source File: IoDataGenerationTest.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions.  Just write out the graph for convenience.
 */
@Test
public void shouldWriteDEFAULTSinkGraphAsGraphSONV3d0() throws IOException {
    final OutputStream os = new FileOutputStream(tempPath + "tinkerpop-sink.json");
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V3_0).create()).create()
            .writeGraph(os, TinkerFactory.createKitchenSink());
    os.close();
}
 
Example #29
Source File: IoDataGenerationTest.java    From tinkerpop with Apache License 2.0 5 votes vote down vote up
/**
 * No assertions. Just write out the graph for convenience
 */
@Test
public void shouldWriteKitchenSinkAsGraphSONV2d0NoTypes() throws IOException {
    final OutputStream os = new FileOutputStream(new File(tempPath, "tinkerpop-sink-v2d0.json"));
    GraphSONWriter.build().mapper(GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.NO_TYPES).create()).create()
            .writeGraph(os, TinkerFactory.createKitchenSink());
    os.close();
}
 
Example #30
Source File: AtlasGraphSONReader.java    From atlas with Apache License 2.0 5 votes vote down vote up
public AtlasGraphSONReader create() {
    setDefaults();
    if(bulkLoadGraph == null) {
        bulkLoadGraph = graph;
    }

    final GraphSONMapper.Builder builder = GraphSONMapper.build();
    final GraphSONMapper         mapper  = builder.typeInfo(TypeInfo.NO_TYPES).create();

    return new AtlasGraphSONReader(mapper.createMapper(), relationshipCache, graph, bulkLoadGraph,
                                                            numWorkers, batchSize, suppliedStartIndex);
}