@Test public void testGeoShapeSerializationReadWriteAsGraphSONEmbedded() throws Exception { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); GraphSONMapper m = graph.io(IoCore.graphson()).mapper().embedTypes(true).create(); GraphWriter writer = graph.io(IoCore.graphson()).writer().mapper(m).create(); FileOutputStream fos = new FileOutputStream("/tmp/test.json"); writer.writeGraph(fos, graph); clearGraph(config); open(config); GraphReader reader = graph.io(IoCore.graphson()).reader().mapper(m).create(); FileInputStream fis = new FileInputStream("/tmp/test.json"); reader.readGraph(fis, graph); TitanIndexTest.assertGraphOfTheGods(graph); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithProperties() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); assertEquals(vp.values("startTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("startTime")); assertEquals(vp.values("endTime").next(), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("endTime")); }
@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(); }
public AbstractGraphSONMessageSerializerV2d0() { final GraphSONMapper.Builder builder = configureBuilder(initBuilder(null)); mapper = builder.create().createMapper(); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Property detached = mapper.readValue(json, Property.class); assertNotNull(detached); assertEquals(p.key(), detached.key()); assertEquals(p.value(), detached.value()); }
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(); }
public LegacyGraphSONReader create() { final GraphSONMapper.Builder builder = GraphSONMapper.build(); customModules.forEach(builder::addCustomModule); final GraphSONMapper mapper = builder.typeInfo(embedTypes ? TypeInfo.PARTIAL_TYPES : TypeInfo.NO_TYPES) .loadCustomModules(loadCustomModules).create(); return new LegacyGraphSONReader(mapper.createMapper(), batchSize); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Property detached = mapper.readValue(json, Property.class); assertNotNull(detached); assertEquals(p.key(), detached.key()); assertEquals(p.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V3_0)).mapper().version(GraphSONVersion.V3_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Edge detached = mapper.readValue(json, Edge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
/** * {@inheritDoc} */ @Override public GraphSONWriter.Builder writer() { return GraphSONWriter.build().mapper(mapper().create()); }
/** * {@inheritDoc} */ @Override public GraphSONReader.Builder reader() { return GraphSONReader.build().mapper(mapper().create()); }
@Override public void configure(final Map<String, Object> config, final Map<String, Graph> graphs) { final GraphSONMapper.Builder initialBuilder = initBuilder(null); addIoRegistries(config, initialBuilder); mapper = configureBuilder(initialBuilder).create().createMapper(); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(vp.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals(vp.value(), m.get(GraphSONTokens.VALUE)); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Property p = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final String json = mapper.writeValueAsString(p); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(p.value(), m.get(GraphSONTokens.VALUE)); assertEquals(p.key(), m.get(GraphSONTokens.KEY)); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Map<String, Object> m = mapper.readValue(json, mapTypeReference); assertEquals(GraphSONTokens.EDGE, m.get(GraphSONTokens.TYPE)); assertEquals(e.label(), m.get(GraphSONTokens.LABEL)); assertNotNull(m.get(GraphSONTokens.ID)); assertEquals((Double) e.value("weight"), ((Map) m.get(GraphSONTokens.PROPERTIES)).get("weight")); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexProperty() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final VertexProperty vp = graph.vertices(convertToVertexId("marko")).next().property("name"); final String json = mapper.writeValueAsString(vp); final VertexProperty detached = mapper.readValue(json, VertexProperty.class); assertNotNull(detached); assertEquals(vp.label(), detached.label()); assertEquals(vp.id(), detached.id()); assertEquals(vp.value(), detached.value()); }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdge() throws Exception { final ObjectMapper mapper = graph.io(GraphSONIo.build(GraphSONVersion.V2_0)).mapper().version(GraphSONVersion.V2_0).create().createMapper(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final String json = mapper.writeValueAsString(e); final Edge detached = mapper.readValue(json, Edge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
@Override public void configure(final Map<String, Object> config, final Map<String, Graph> graphs) { final GraphSONMapper.Builder initialBuilder = initBuilder(null); addIoRegistries(config, initialBuilder); mapper = configureBuilder(initialBuilder).create().createMapper(); }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { final GraphSONMapper v1mapper = GraphSONMapper.build().version(GraphSONVersion.V1_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistryV1d0.getInstance()).create(); final GraphSONMapper v2mapper = GraphSONMapper.build().version(GraphSONVersion.V2_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); final GraphSONMapper v3mapper = GraphSONMapper.build().version(GraphSONVersion.V3_0).typeInfo(TypeInfo.PARTIAL_TYPES).addRegistry(JanusGraphIoRegistry.getInstance()).create(); return Arrays.asList(new Object[][]{ {"graphson-v1-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v1mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v1mapper).create()}, {"graphson-v2-embedded", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v2mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v2mapper).create()}, {"graphson-v3", (Function<Graph, GraphReader>) g -> GraphSONReader.build().mapper(v3mapper).create(), (Function<Graph, GraphWriter>) g -> GraphSONWriter.build().mapper(v3mapper).create()}, {"gryo", (Function<Graph, GraphReader>) g -> g.io(IoCore.gryo()).reader().mapper(g.io(IoCore.gryo()).mapper().create()).create(), (Function<Graph, GraphWriter>) g -> g.io(IoCore.gryo()).writer().mapper(g.io(IoCore.gryo()).mapper().create()).create()} }); }