org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.structure.io.gryo.GryoReader.
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: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Tree before = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Tree after = gryoReader.readObject(inputStream, Tree.class); assertNotNull(after); //The following assertions should be sufficent. assertThat("Type does not match", after, instanceOf(Tree.class)); assertEquals("The objects differ", after, before); }
Example #2
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTraversalMetrics() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final TraversalMetrics before = (TraversalMetrics) g.V().both().profile().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final TraversalMetrics after = gryoReader.readObject(inputStream, TraversalMetrics.class); assertNotNull(after); assertEquals(before.getMetrics().size(), after.getMetrics().size()); assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS)); assertEquals(before.getMetrics(0).getCounts(), after.getMetrics().stream().findFirst().get().getCounts()); }
Example #3
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
Example #4
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexPropertyAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty vertexProperty = graph.vertices(convertToVertexId("marko")).next().property("name"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); }
Example #5
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializePropertyAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Property property = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, property); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Property detached = gryoReader.readObject(inputStream, DetachedProperty.class); assertNotNull(detached); assertEquals(property.key(), detached.key()); assertEquals(property.value(), detached.value()); }
Example #6
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdgeAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, e); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Edge detached = gryoReader.readObject(inputStream, DetachedEdge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
Example #7
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, v); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Vertex detached = gryoReader.readObject(inputStream, DetachedVertex.class); assertNotNull(detached); assertEquals(v.label(), detached.label()); assertEquals(v.id(), detached.id()); assertEquals(v.value("name").toString(), detached.value("name")); assertEquals((Integer) v.value("age"), detached.value("age")); }
Example #8
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Tree before = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Tree after = gryoReader.readObject(inputStream, Tree.class); assertNotNull(after); //The following assertions should be sufficent. assertThat("Type does not match", after, instanceOf(Tree.class)); assertEquals("The objects differ", after, before); }
Example #9
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTraversalMetrics() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final TraversalMetrics before = g.V().both().profile().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final TraversalMetrics after = gryoReader.readObject(inputStream, TraversalMetrics.class); assertNotNull(after); assertEquals(before.getMetrics().size(), after.getMetrics().size()); assertEquals(before.getDuration(TimeUnit.MILLISECONDS), after.getDuration(TimeUnit.MILLISECONDS)); assertEquals(before.getMetrics(0).getCounts(), after.getMetrics().stream().findFirst().get().getCounts()); }
Example #10
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.CREW) public void shouldSerializeVertexPropertyWithPropertiesAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty<?> vertexProperty = IteratorUtils.filter(graph.vertices(convertToVertexId("marko")).next().properties("location"), p -> p.value().equals("brussels")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty<?> detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); assertEquals(vertexProperty.values("startTime").next(), detached.values("startTime").next()); assertEquals(vertexProperty.properties("startTime").next().key(), detached.properties("startTime").next().key()); assertEquals(vertexProperty.values("endTime").next(), detached.values("endTime").next()); assertEquals(vertexProperty.properties("endTime").next().key(), detached.properties("endTime").next().key()); }
Example #11
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexPropertyAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final VertexProperty vertexProperty = graph.vertices(convertToVertexId("marko")).next().property("name"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, vertexProperty); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final VertexProperty detached = gryoReader.readObject(inputStream, DetachedVertexProperty.class); assertNotNull(detached); assertEquals(vertexProperty.label(), detached.label()); assertEquals(vertexProperty.id(), detached.id()); assertEquals(vertexProperty.value(), detached.value()); }
Example #12
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializePropertyAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Property property = g.E(convertToEdgeId("marko", "knows", "vadas")).next().property("weight"); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, property); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Property detached = gryoReader.readObject(inputStream, DetachedProperty.class); assertNotNull(detached); assertEquals(property.key(), detached.key()); assertEquals(property.value(), detached.value()); }
Example #13
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeEdgeAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Edge e = g.E(convertToEdgeId("marko", "knows", "vadas")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, e); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Edge detached = gryoReader.readObject(inputStream, DetachedEdge.class); assertNotNull(detached); assertEquals(e.label(), detached.label()); assertEquals(e.id(), detached.id()); assertEquals((Double) e.value("weight"), detached.value("weight")); }
Example #14
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeVertexAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Vertex v = graph.vertices(convertToVertexId("marko")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, v); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Vertex detached = gryoReader.readObject(inputStream, DetachedVertex.class); assertNotNull(detached); assertEquals(v.label(), detached.label()); assertEquals(v.id(), detached.id()); assertEquals(v.value("name").toString(), detached.value("name")); assertEquals((Integer) v.value("age"), detached.value("age")); }
Example #15
Source File: GryoRecordReader.java From tinkerpop with Apache License 2.0 | 6 votes |
@Override public void initialize(final InputSplit genericSplit, final TaskAttemptContext context) throws IOException { final FileSplit split = (FileSplit) genericSplit; final Configuration configuration = context.getConfiguration(); if (configuration.get(Constants.GREMLIN_HADOOP_GRAPH_FILTER, null) != null) this.graphFilter = VertexProgramHelper.deserialize(ConfUtil.makeApacheConfiguration(configuration), Constants.GREMLIN_HADOOP_GRAPH_FILTER); this.gryoReader = GryoReader.build().mapper( GryoMapper.build().addRegistries(IoRegistryHelper.createRegistries(ConfUtil.makeApacheConfiguration(configuration))).create()).create(); long start = split.getStart(); final Path file = split.getPath(); if (null != new CompressionCodecFactory(configuration).getCodec(file)) { throw new IllegalStateException("Compression is not supported for the (binary) Gryo format"); } // open the file and seek to the start of the split this.inputStream = file.getFileSystem(configuration).open(split.getPath()); this.splitLength = split.getLength(); if (this.splitLength > 0) this.splitLength -= (seekToHeader(this.inputStream, start) - start); }
Example #16
Source File: TinkerpopTest.java From sqlg with MIT License | 6 votes |
@Test public void testTail() throws IOException { Graph graph = this.sqlgGraph; final GraphReader reader = GryoReader.build() .mapper(graph.io(GryoIo.build()).mapper().create()) .create(); try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) { reader.readGraph(stream, graph); } assertModernGraph(graph, true, false); GraphTraversalSource g = graph.traversal(); int tail = 0; for (int i = 1; i < 72; i++) { tail = i; List<Vertex> vertices = g.V().repeat(both()).times(3).tail(tail).toList(); if (tail != vertices.size()) { System.out.println("expected " + tail + " found " + vertices.size()); } } }
Example #17
Source File: TinkerIoRegistryV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #18
Source File: TinkerpopTest.java From sqlg with MIT License | 5 votes |
public void g_V_chooseXlabel_eq_person__unionX__out_lang__out_nameX__in_labelX() throws IOException { Graph graph = this.sqlgGraph; final GraphReader reader = GryoReader.build() .mapper(graph.io(GryoIo.build()).mapper().create()) .create(); try (final InputStream stream = AbstractGremlinTest.class.getResourceAsStream("/tinkerpop-modern.kryo")) { reader.readGraph(stream, graph); } assertModernGraph(graph, true, false); GraphTraversalSource g = graph.traversal(); List<Vertex> traversala2 = g.V().hasId(convertToVertexId("marko")).toList(); Assert.assertEquals(1, traversala2.size()); Assert.assertEquals(convertToVertex(graph, "marko"), traversala2.get(0)); }
Example #19
Source File: ToyGraphInputRDD.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public JavaPairRDD<Object, VertexWritable> readGraphRDD(final Configuration configuration, final JavaSparkContext sparkContext) { KryoShimServiceLoader.applyConfiguration(TinkerGraph.open().configuration()); final List<VertexWritable> vertices; if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("modern")) vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createModern().vertices(), VertexWritable::new)); else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("classic")) vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createClassic().vertices(), VertexWritable::new)); else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("crew")) vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createTheCrew().vertices(), VertexWritable::new)); else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("sink")) vertices = IteratorUtils.list(IteratorUtils.map(TinkerFactory.createKitchenSink().vertices(), VertexWritable::new)); else if (configuration.getString(Constants.GREMLIN_HADOOP_INPUT_LOCATION).contains("grateful")) { try { final Graph graph = TinkerGraph.open(); final GraphReader reader = GryoReader.build().mapper(graph.io(GryoIo.build()).mapper().create()).create(); try (final InputStream stream = GryoResourceAccess.class.getResourceAsStream("grateful-dead-v3d0.kryo")) { reader.readGraph(stream, graph); } vertices = IteratorUtils.list(IteratorUtils.map(graph.vertices(), VertexWritable::new)); } catch (final IOException e) { throw new IllegalStateException(e.getMessage(), e); } } else throw new IllegalArgumentException("No legal toy graph was provided to load: " + configuration.getProperty(Constants.GREMLIN_HADOOP_INPUT_LOCATION)); return sparkContext.parallelize(vertices).mapToPair(vertex -> new Tuple2<>(vertex.get().id(), vertex)); }
Example #20
Source File: AbstractGraphBenchmark.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Opens a new {@link TinkerGraph} instance and optionally preloads it with one of the test data sets enumerated * in {@link LoadGraphWith}. * * @throws IOException on failure to load graph */ @Setup public void prepare() throws IOException { graph = TinkerGraph.open(); g = graph.traversal(); final LoadGraphWith[] loadGraphWiths = this.getClass().getAnnotationsByType(LoadGraphWith.class); final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0]; final LoadGraphWith.GraphData loadGraphWithData = null == loadGraphWith ? null : loadGraphWith.value(); String graphFile; if(loadGraphWithData != null) { if (loadGraphWithData.equals(LoadGraphWith.GraphData.GRATEFUL)) { graphFile = "grateful-dead-v3d0.kryo"; } else if (loadGraphWithData.equals(LoadGraphWith.GraphData.MODERN)) { graphFile = "tinkerpop-modern-v3d0.kryo"; } else if (loadGraphWithData.equals(LoadGraphWith.GraphData.CLASSIC)) { graphFile = "tinkerpop-classic-v3d0.kryo"; } else if (loadGraphWithData.equals(LoadGraphWith.GraphData.CREW)) { graphFile = "tinkerpop-crew-v3d0.kryo"; } else { throw new RuntimeException("Could not load graph with " + loadGraphWithData); } final GraphReader reader = GryoReader.build().create(); try (final InputStream stream = AbstractGraphBenchmark.class. getResourceAsStream(PATH + graphFile)) { reader.readGraph(stream, graph); } } }
Example #21
Source File: TinkerIoRegistryV1d0.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #22
Source File: TinkerIoRegistryV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #23
Source File: TinkerIoRegistryV1d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #24
Source File: TinkerIoRegistryV2d0.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #25
Source File: TinkerIoRegistryV3d0.java From tinkergraph-gremlin with Apache License 2.0 | 5 votes |
@Override public TinkerGraph read(final Kryo kryo, final Input input, final Class<TinkerGraph> tinkerGraphClass) { final Configuration conf = new BaseConfiguration(); conf.setProperty("gremlin.tinkergraph.defaultVertexPropertyCardinality", "list"); final TinkerGraph graph = TinkerGraph.open(conf); final int len = input.readInt(); final byte[] bytes = input.readBytes(len); try (final ByteArrayInputStream stream = new ByteArrayInputStream(bytes)) { GryoReader.build().mapper(() -> kryo).create().readGraph(stream, graph); } catch (Exception io) { throw new RuntimeException(io); } return graph; }
Example #26
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializePathAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path() .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, p); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Path detached = gryoReader.readObject(inputStream, DetachedPath.class); assertNotNull(detached); assertEquals(p.labels().size(), detached.labels().size()); assertEquals(p.labels().get(0).size(), detached.labels().get(0).size()); assertEquals(p.labels().get(1).size(), detached.labels().get(1).size()); assertEquals(p.labels().get(2).size(), detached.labels().get(2).size()); assertTrue(p.labels().stream().flatMap(Collection::stream).allMatch(detached::hasLabel)); final Vertex vOut = p.get("a"); final Vertex detachedVOut = detached.get("a"); assertEquals(vOut.label(), detachedVOut.label()); assertEquals(vOut.id(), detachedVOut.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedVOut.properties().hasNext()); final Edge e = p.get("b"); final Edge detachedE = detached.get("b"); assertEquals(e.label(), detachedE.label()); assertEquals(e.id(), detachedE.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedE.properties().hasNext()); final Vertex vIn = p.get("c"); final Vertex detachedVIn = detached.get("c"); assertEquals(vIn.label(), detachedVIn.label()); assertEquals(vIn.id(), detachedVIn.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedVIn.properties().hasNext()); }
Example #27
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 4 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializePathAsDetached() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Path p = g.V(convertToVertexId("marko")).as("a").outE().as("b").inV().as("c").path() .filter(t -> ((Vertex) t.get().objects().get(2)).value("name").equals("lop")).next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, p); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Path detached = gryoReader.readObject(inputStream, DetachedPath.class); assertNotNull(detached); assertEquals(p.labels().size(), detached.labels().size()); assertEquals(p.labels().get(0).size(), detached.labels().get(0).size()); assertEquals(p.labels().get(1).size(), detached.labels().get(1).size()); assertEquals(p.labels().get(2).size(), detached.labels().get(2).size()); assertTrue(p.labels().stream().flatMap(Collection::stream).allMatch(detached::hasLabel)); final Vertex vOut = p.get("a"); final Vertex detachedVOut = detached.get("a"); assertEquals(vOut.label(), detachedVOut.label()); assertEquals(vOut.id(), detachedVOut.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedVOut.properties().hasNext()); final Edge e = p.get("b"); final Edge detachedE = detached.get("b"); assertEquals(e.label(), detachedE.label()); assertEquals(e.id(), detachedE.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedE.properties().hasNext()); final Vertex vIn = p.get("c"); final Vertex detachedVIn = detached.get("c"); assertEquals(vIn.label(), detachedVIn.label()); assertEquals(vIn.id(), detachedVIn.id()); // this is a SimpleTraverser so no properties are present in detachment assertFalse(detachedVIn.properties().hasNext()); }