public GraphNode getNode(ObjectId id) { synchronized (delegate) { return delegate.getNode(id); } } }
public GraphNode getNode(ObjectId id) { synchronized (delegate) { return delegate.getNode(id); } } }
/** * Determines if there are any sparse commits between the start commit and the end commit, not * including the end commit. * * @return true if there are any sparse commits between start and end */ @Override protected Boolean _call() { Preconditions.checkState(start != null, "start commit has not been set."); Preconditions.checkState(end != null, "end commit has not been set."); GraphNode node = graphDatabase().getNode(start); return isSparsePath(node, end, false); }
/** * Determines if there are any sparse commits between the start commit and the end commit, not * including the end commit. * * @return true if there are any sparse commits between start and end */ @Override protected Boolean _call() { Preconditions.checkState(start != null, "start commit has not been set."); Preconditions.checkState(end != null, "end commit has not been set."); GraphNode node = graphDatabase().getNode(start); return isSparsePath(node, end, false); }
@Test public void testSparseNode() { ObjectId nodeId = RevObjectTestSupport.hashString("node"); database.put(nodeId, ImmutableList.of()); GraphNode node = database.getNode(nodeId); assertFalse(node.isSparse()); database.setProperty(nodeId, GraphDatabase.SPARSE_FLAG, "true"); node = database.getNode(nodeId); assertTrue(node.isSparse()); database.setProperty(nodeId, GraphDatabase.SPARSE_FLAG, "false"); node = database.getNode(nodeId); assertFalse(node.isSparse()); }
@Test public void testSparseNode() { ObjectId nodeId = RevObjectTestSupport.hashString("node"); database.put(nodeId, ImmutableList.of()); GraphNode node = database.getNode(nodeId); assertFalse(node.isSparse()); database.setProperty(nodeId, GraphDatabase.SPARSE_FLAG, "true"); node = database.getNode(nodeId); assertTrue(node.isSparse()); database.setProperty(nodeId, GraphDatabase.SPARSE_FLAG, "false"); node = database.getNode(nodeId); assertFalse(node.isSparse()); }
@Override public void run() { GraphNode commit2Node = database.getNode(commit2); GraphNode commit1Node = database.getNode(commit1); GraphNode rootNode = database.getNode(rootId); List<GraphEdge> edges; assertNotNull(commit2Node); assertNotNull(commit1Node); assertNotNull(rootNode); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.IN)); assertEquals(2, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.OUT)); assertTrue(edges.isEmpty()); } });
@Override public void run() { GraphNode commit2Node = database.getNode(commit2); GraphNode commit1Node = database.getNode(commit1); GraphNode rootNode = database.getNode(rootId); List<GraphEdge> edges; assertNotNull(commit2Node); assertNotNull(commit1Node); assertNotNull(rootNode); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(commit2Node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(commit1Node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.IN)); assertEquals(2, edges.size()); edges = ImmutableList.copyOf(rootNode.getEdges(Direction.OUT)); assertTrue(edges.isEmpty()); } });
@Test public void testProperties() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); ImmutableList<ObjectId> parents = ImmutableList.of(); database.put(rootId, parents); database.setProperty(rootId, GraphDatabase.SPARSE_FLAG, "true"); assertTrue(database.getNode(rootId).isSparse()); }
@Test public void testProperties() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); ImmutableList<ObjectId> parents = ImmutableList.of(); database.put(rootId, parents); database.setProperty(rootId, GraphDatabase.SPARSE_FLAG, "true"); assertTrue(database.getNode(rootId).isSparse()); }
@Test public void testEdges() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); GraphNode node; List<GraphEdge> edges; node = database.getNode(commit2); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); node = database.getNode(commit1); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); }
@Test public void testEdges() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); GraphNode node; List<GraphEdge> edges; node = database.getNode(commit2); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertTrue(edges.isEmpty()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(2, edges.size()); assertEquals(commit1, edges.get(0).getToNode().getIdentifier()); assertEquals(rootId, edges.get(1).getToNode().getIdentifier()); node = database.getNode(commit1); assertNotNull(node); edges = ImmutableList.copyOf(node.getEdges(Direction.IN)); assertEquals(1, edges.size()); edges = ImmutableList.copyOf(node.getEdges(Direction.OUT)); assertEquals(1, edges.size()); }
@Test public void testUpdateNode() { ObjectId nodeId = RevObjectTestSupport.hashString("node"); ObjectId nodeParent = RevObjectTestSupport.hashString("nodeParent"); boolean updated = database.put(nodeId, ImmutableList.of()); assertTrue(updated); GraphNode node = database.getNode(nodeId); assertFalse(node.getEdges(Direction.BOTH).hasNext()); updated = database.put(nodeId, ImmutableList.of(nodeParent)); assertTrue(updated); node = database.getNode(nodeId); Iterator<GraphEdge> edges = node.getEdges(Direction.BOTH); assertTrue(edges.hasNext()); GraphEdge edge = edges.next(); assertEquals(nodeId, edge.getFromNode().getIdentifier()); assertEquals(nodeParent, edge.getToNode().getIdentifier()); updated = database.put(nodeId, ImmutableList.of(nodeParent)); assertFalse(updated); }
@Test public void testUpdateNode() { ObjectId nodeId = RevObjectTestSupport.hashString("node"); ObjectId nodeParent = RevObjectTestSupport.hashString("nodeParent"); boolean updated = database.put(nodeId, ImmutableList.of()); assertTrue(updated); GraphNode node = database.getNode(nodeId); assertFalse(node.getEdges(Direction.BOTH).hasNext()); updated = database.put(nodeId, ImmutableList.of(nodeParent)); assertTrue(updated); node = database.getNode(nodeId); Iterator<GraphEdge> edges = node.getEdges(Direction.BOTH); assertTrue(edges.hasNext()); GraphEdge edge = edges.next(); assertEquals(nodeId, edge.getFromNode().getIdentifier()); assertEquals(nodeParent, edge.getToNode().getIdentifier()); updated = database.put(nodeId, ImmutableList.of(nodeParent)); assertFalse(updated); }
@Test public void testTruncate() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); assertTrue(database.exists(rootId)); assertTrue(database.exists(commit1)); assertTrue(database.exists(commit2)); assertNotNull(database.getNode(rootId)); assertNotNull(database.getNode(commit1)); assertNotNull(database.getNode(commit2)); assertEquals(1, database.getDepth(commit2)); database.truncate(); // not using getNode for assertions cause it's contract is not well defined for an invalid // argument and implementations behave differently. Created an issue to fix it. // assertNull(database.getNode(rootId)); // assertNull(database.getNode(commit1)); // assertNull(database.getNode(commit2)); // assertEquals(0, database.getDepth(commit2)); assertFalse(database.exists(rootId)); assertFalse(database.exists(commit1)); assertFalse(database.exists(commit2)); }
@Test public void testTruncate() throws IOException { ObjectId rootId = RevObjectTestSupport.hashString("root"); database.put(rootId, ImmutableList.of()); ObjectId commit1 = RevObjectTestSupport.hashString("c1"); database.put(commit1, ImmutableList.of(rootId)); ObjectId commit2 = RevObjectTestSupport.hashString("c2"); database.put(commit2, ImmutableList.of(commit1, rootId)); assertTrue(database.exists(rootId)); assertTrue(database.exists(commit1)); assertTrue(database.exists(commit2)); assertNotNull(database.getNode(rootId)); assertNotNull(database.getNode(commit1)); assertNotNull(database.getNode(commit2)); assertEquals(1, database.getDepth(commit2)); database.truncate(); // not using getNode for assertions cause it's contract is not well defined for an invalid // argument and implementations behave differently. Created an issue to fix it. // assertNull(database.getNode(rootId)); // assertNull(database.getNode(commit1)); // assertNull(database.getNode(commit2)); // assertEquals(0, database.getDepth(commit2)); assertFalse(database.exists(rootId)); assertFalse(database.exists(commit1)); assertFalse(database.exists(commit2)); }