@Test @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldReadWriteVerticesNoEdgesToGraphSONManual() throws Exception { assumeThat(ioType, startsWith("graphson")); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(os.toByteArray())))) { String line = br.readLine(); reader.readVertex(new ByteArrayInputStream(line.getBytes()), attachable -> { called.incrementAndGet(); return mock(Vertex.class); }); line = br.readLine(); reader.readVertex(new ByteArrayInputStream(line.getBytes()), detachedVertex -> { called.incrementAndGet(); return mock(Vertex.class); }); } assertEquals(2, called.get()); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldReadWriteVerticesNoEdges() throws Exception { try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) { final Iterator<Vertex> itty = reader.readVertices(bais, attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }, null, null); assertNotNull(itty.next()); assertNotNull(itty.next()); assertFalse(itty.hasNext()); } assertEquals(2, called.get()); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldReadWriteVerticesNoEdgesToGryoManual() throws Exception { assumeThat(ioType, is("gryo")); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final VertexByteArrayInputStream vbais = new VertexByteArrayInputStream(new ByteArrayInputStream(os.toByteArray()))) { final byte[] y = vbais.readVertexBytes().toByteArray(); reader.readVertex(new ByteArrayInputStream(y), attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }); final byte[] z = vbais.readVertexBytes().toByteArray(); reader.readVertex(new ByteArrayInputStream(z), attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }); } assertEquals(2, called.get()); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldReadWriteVerticesNoEdgesToGraphSONManual() throws Exception { assumeThat(ioType, startsWith("graphson")); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(os.toByteArray())))) { String line = br.readLine(); reader.readVertex(new ByteArrayInputStream(line.getBytes()), attachable -> { called.incrementAndGet(); return mock(Vertex.class); }); line = br.readLine(); reader.readVertex(new ByteArrayInputStream(line.getBytes()), detachedVertex -> { called.incrementAndGet(); return mock(Vertex.class); }); } assertEquals(2, called.get()); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldReadWriteVerticesNoEdges() throws Exception { try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) { final Iterator<Vertex> itty = reader.readVertices(bais, attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }, null, null); assertNotNull(itty.next()); assertNotNull(itty.next()); assertFalse(itty.hasNext()); } assertEquals(2, called.get()); } }
@Test @LoadGraphWith(LoadGraphWith.GraphData.CLASSIC) public void shouldReadWriteVerticesNoEdgesToGryoManual() throws Exception { assumeThat(ioType, is("gryo")); try (final ByteArrayOutputStream os = new ByteArrayOutputStream()) { final GraphWriter writer = writerMaker.apply(graph); writer.writeVertices(os, g.V().has("age", P.gt(30))); final AtomicInteger called = new AtomicInteger(0); final GraphReader reader = readerMaker.apply(graph); try (final VertexByteArrayInputStream vbais = new VertexByteArrayInputStream(new ByteArrayInputStream(os.toByteArray()))) { final byte[] y = vbais.readVertexBytes().toByteArray(); reader.readVertex(new ByteArrayInputStream(y), attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }); final byte[] z = vbais.readVertexBytes().toByteArray(); reader.readVertex(new ByteArrayInputStream(z), attachable -> { final Vertex detachedVertex = attachable.get(); called.incrementAndGet(); return detachedVertex; }); } assertEquals(2, called.get()); } }