@Test public void generateAppendsEachVersionOfAnEdgeOnlyOnce() { UUID relId = UUID.fromString("ff65089c-2ded-4af0-95e7-0476979f96b8"); GraphWrapper graphWrapper = newGraph() .withVertex("v1", v -> v.withTimId("id1") .withProperty("modified", getChangeStringWithTimestamp(1464346423L)) .withProperty("rev", 3) ) .withVertex("v2", v -> v.withTimId("id2") .withProperty("modified", getChangeStringWithTimestamp(1464346425L)) .withProperty("rev", 3) .withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(1) .withModified(changeWithTimestamp(1464346426L)) ) .withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(2) .withModified(changeWithTimestamp(1464346428L)) ) .withOutgoingRelation("relatedTo", "v1", r -> r.withTim_id(relId).withRev(2) .withModified(changeWithTimestamp(1464346428L)) ) ) .wrap(); DatabaseLog instance = createInstance(graphWrapper); instance.generate(); verify(logEntryFactory).createForEdge(argThat(likeEdge().withId(relId.toString()).withProperty("rev", 1))); verify(logEntryFactory, times(1)).createForEdge(argThat(likeEdge().withId(relId.toString()) .withProperty("rev", 2))); }
public void generate() { long prevTimestamp = 0L; @SuppressWarnings("unchecked") GraphTraversal<Vertex, ? extends Element> results = graphWrapper .getGraph() .traversal() .V().has("modified").has("rev").has("tim_id") .not(__.has(T.label, LabelP.of("searchresult"))) .not(__.bothE("NEXT_ITEM")) .union(__.identity(), __.outE().has("modified")) .dedup().by(__.valueMap("rev", "tim_id")) .order() .by("modified", new ChangeStringComparator()); List<Edge> edges = Lists.newArrayList(); List<Vertex> vertices = Lists.newArrayList(); logOutput.prepareToWrite(); for (; results.hasNext(); ) { Element element = results.next(); String modifiedString = element.value("modified"); try { long curTimestamp = getTimestampFromChangeString(modifiedString); if (prevTimestamp != curTimestamp) { vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); prevTimestamp = curTimestamp; } if (element instanceof Vertex) { vertices.add((Vertex) element); } else if (element instanceof Edge) { edges.add((Edge) element); } else { LOG.error("Element type {} not expected.", element.getClass()); } } catch (IOException e) { LOG.error("Change '{}' could nog be parsed.", modifiedString); } } vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); logOutput.finishWriting(); }
DatabaseLog { public void generate() { long prevTimestamp = 0L; @SuppressWarnings("unchecked") GraphTraversal<Vertex, ? extends Element> results = graphWrapper .getGraph() .traversal() .V().has("modified").has("rev").has("tim_id") .not(__.has(T.label, LabelP.of("searchresult"))) .not(__.bothE("NEXT_ITEM")) .union(__.identity(), __.outE().has("modified")) .dedup().by(__.valueMap("rev", "tim_id")) .order() .by("modified", new ChangeStringComparator()); List<Edge> edges = Lists.newArrayList(); List<Vertex> vertices = Lists.newArrayList(); logOutput.prepareToWrite(); for (; results.hasNext(); ) { Element element = results.next(); String modifiedString = element.value("modified"); try { long curTimestamp = getTimestampFromChangeString(modifiedString); if (prevTimestamp != curTimestamp) { vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); prevTimestamp = curTimestamp; } if (element instanceof Vertex) { vertices.add((Vertex) element); } else if (element instanceof Edge) { edges.add((Edge) element); } else { LOG.error("Element type {} not expected.", element.getClass()); } } catch (IOException e) { LOG.error("Change '{}' could nog be parsed.", modifiedString); } } vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); logOutput.finishWriting(); } }
DatabaseLog { public void generate() { long prevTimestamp = 0L; @SuppressWarnings("unchecked") GraphTraversal<Vertex, ? extends Element> results = graphWrapper .getGraph() .traversal() .V().has("modified").has("rev").has("tim_id") .not(__.has(T.label, LabelP.of("searchresult"))) .not(__.bothE("NEXT_ITEM")) .union(__.identity(), __.outE().has("modified")) .dedup().by(__.valueMap("rev", "tim_id")) .order() .by("modified", new ChangeStringComparator()); List<Edge> edges = Lists.newArrayList(); List<Vertex> vertices = Lists.newArrayList(); logOutput.prepareToWrite(); for (; results.hasNext(); ) { Element element = results.next(); String modifiedString = element.value("modified"); try { long curTimestamp = getTimestampFromChangeString(modifiedString); if (prevTimestamp != curTimestamp) { vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); prevTimestamp = curTimestamp; } if (element instanceof Vertex) { vertices.add((Vertex) element); } else if (element instanceof Edge) { edges.add((Edge) element); } else { LOG.error("Element type {} not expected.", element.getClass()); } } catch (IOException e) { LOG.error("Change '{}' could nog be parsed.", modifiedString); } } vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); logOutput.finishWriting(); } DatabaseLog(GraphWrapper graphWrapper);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory, LogOutput logOutput); }
DatabaseLog { public void generate() { long prevTimestamp = 0L; @SuppressWarnings("unchecked") GraphTraversal<Vertex, ? extends Element> results = graphWrapper .getGraph() .traversal() .V().has("modified").has("rev").has("tim_id") .not(__.has(T.label, LabelP.of("searchresult"))) .not(__.bothE("NEXT_ITEM")) .union(__.identity(), __.outE().has("modified")) .dedup().by(__.valueMap("rev", "tim_id")) .order() .by("modified", new ChangeStringComparator()); List<Edge> edges = Lists.newArrayList(); List<Vertex> vertices = Lists.newArrayList(); logOutput.prepareToWrite(); for (; results.hasNext(); ) { Element element = results.next(); String modifiedString = element.value("modified"); try { long curTimestamp = getTimestampFromChangeString(modifiedString); if (prevTimestamp != curTimestamp) { vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); prevTimestamp = curTimestamp; } if (element instanceof Vertex) { vertices.add((Vertex) element); } else if (element instanceof Edge) { edges.add((Edge) element); } else { LOG.error("Element type {} not expected.", element.getClass()); } } catch (IOException e) { LOG.error("Change '{}' could nog be parsed.", modifiedString); } } vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); logOutput.finishWriting(); } DatabaseLog(GraphWrapper graphWrapper);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory, LogOutput logOutput); void generate(); }
DatabaseLog { public void generate() { long prevTimestamp = 0L; @SuppressWarnings("unchecked") GraphTraversal<Vertex, ? extends Element> results = graphWrapper .getGraph() .traversal() .V().has("modified").has("rev").has("tim_id") .not(__.has(T.label, LabelP.of("searchresult"))) .not(__.bothE("NEXT_ITEM")) .union(__.identity(), __.outE().has("modified")) .dedup().by(__.valueMap("rev", "tim_id")) .order() .by("modified", new ChangeStringComparator()); List<Edge> edges = Lists.newArrayList(); List<Vertex> vertices = Lists.newArrayList(); logOutput.prepareToWrite(); for (; results.hasNext(); ) { Element element = results.next(); String modifiedString = element.value("modified"); try { long curTimestamp = getTimestampFromChangeString(modifiedString); if (prevTimestamp != curTimestamp) { vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); prevTimestamp = curTimestamp; } if (element instanceof Vertex) { vertices.add((Vertex) element); } else if (element instanceof Edge) { edges.add((Edge) element); } else { LOG.error("Element type {} not expected.", element.getClass()); } } catch (IOException e) { LOG.error("Change '{}' could nog be parsed.", modifiedString); } } vertices.forEach(vertex -> logEntryFactory.createForVertex(vertex).appendToLog(logOutput)); vertices.clear(); edges.forEach(edge -> logEntryFactory.createForEdge(edge).appendToLog(logOutput)); edges.clear(); logOutput.finishWriting(); } DatabaseLog(GraphWrapper graphWrapper);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory);   DatabaseLog(GraphWrapper graphWrapper, LogEntryFactory logEntryFactory, LogOutput logOutput); void generate(); static final Logger LOG; }