private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }
@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); }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
@Test public void testGeoShapeSerializationReadWriteAsGryo() throws Exception { GraphOfTheGodsFactory.loadWithoutMixedIndex(graph, true); graph.io(IoCore.gryo()).writeGraph("/tmp/test.kryo"); clearGraph(config); open(config); graph.io(IoCore.gryo()).readGraph("/tmp/test.kryo"); TitanIndexTest.assertGraphOfTheGods(graph); } }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ {"graphml", IoCore.graphml(), false, true, ".xml"}, {"graphsonv1d0", GraphSONIo.build(GraphSONVersion.V1_0), true, true, ".json"}, {"graphsonv2d0", GraphSONIo.build(GraphSONVersion.V2_0), true, true, ".json"}, {"graphsonv3d0", GraphSONIo.build(GraphSONVersion.V3_0), true, true, ".json"}, {"gryo-v3", GryoIo.build(GryoVersion.V1_0), false, false, ".kryo"}, {"gryo-v3", GryoIo.build(GryoVersion.V3_0), false, false, ".kryo"} }); }
@Before public void setupBeforeEachTest() { graphson = graphson(); }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
@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()} }); }
@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 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.graphml()).writer().create().writeGraph(os, source); try (ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray())) { target.io(IoCore.graphml()).reader().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())); }
private void saveGraph() { final File f = new File(graphLocation); if (f.exists()) { f.delete(); } else { final File parent = f.getParentFile(); // the parent would be null in the case of an relative path if the graphLocation was simply: "f.gryo" if (parent != null && !parent.exists()) { parent.mkdirs(); } } try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).writeGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).writeGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).writeGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).writeGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not save graph at %s with %s", graphLocation, graphFormat), ex); } }
@Before public void setupBeforeEachTest() { graphson = graphson(); }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { graph.io(IoCore.gryo()).writer().create().writeObject(outputStream, starGraph); return Pair.with(graph.io(IoCore.gryo()).reader().create().readObject(new ByteArrayInputStream(outputStream.toByteArray()), StarGraph.class), outputStream.size()); } catch (IOException ioe) { throw new RuntimeException(ioe); } } }
/** * flush the cache * * @throws Exception */ public void flush() throws Exception { getSystem().graph().io(IoCore.graphml()).writeGraph(file.getPath()); }
private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }
@Before public void setupBeforeEachTest() { graphson = graphson(); }
@Override protected void processGraph(String documentSourceName, Graph graph) { WriterBuilder<? extends GraphWriter> writer; switch (format) { case GYRO: writer = graph.io(IoCore.gryo()).writer(); break; case GRAPHSON: writer = graph.io(IoCore.graphson()).writer(); break; case GRAPHML: // FALL THROUGH default: writer = graph.io(IoCore.graphml()).writer().normalize(true); break; } try (final OutputStream os = createOutputStream(documentSourceName)) { writer.create().writeGraph(os, graph); } catch (IOException e) { getMonitor().error("Error writing graph", e); } }
/** * Generate the graph in {@link #createGratefulDead()} into an existing graph. */ public static void generateGratefulDead(final TinkerGraph graph) { final InputStream stream = TinkerFactory.class.getResourceAsStream("grateful-dead.kryo"); try { graph.io(gryo()).reader().create().readGraph(stream, graph); } catch (Exception ex) { throw new IllegalStateException(ex); } }
@Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ {"graphml", IoCore.graphml(), false, true, ".xml"}, {"graphsonv1d0", GraphSONIo.build(GraphSONVersion.V1_0), true, true, ".json"}, {"graphsonv2d0", GraphSONIo.build(GraphSONVersion.V2_0), true, true, ".json"}, {"graphsonv3d0", GraphSONIo.build(GraphSONVersion.V3_0), true, true, ".json"}, {"gryo-v3", GryoIo.build(GryoVersion.V1_0), false, false, ".kryo"}, {"gryo-v3", GryoIo.build(GryoVersion.V3_0), false, false, ".kryo"} }); }
private void loadGraph() { final File f = new File(graphLocation); if (f.exists() && f.isFile()) { try { if (graphFormat.equals("graphml")) { io(IoCore.graphml()).readGraph(graphLocation); } else if (graphFormat.equals("graphson")) { io(IoCore.graphson()).readGraph(graphLocation); } else if (graphFormat.equals("gryo")) { io(IoCore.gryo()).readGraph(graphLocation); } else { io(IoCore.createIoBuilder(graphFormat)).readGraph(graphLocation); } } catch (Exception ex) { throw new RuntimeException(String.format("Could not load graph at %s with %s", graphLocation, graphFormat), ex); } } }