You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by ok...@apache.org on 2016/05/02 16:23:33 UTC

[1/4] incubator-tinkerpop git commit: fixed a self-loop bug in StarGraph. Added StarGraphTest.shouldHandleSelfLoops() to ensure correct behavior.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/tp31 704b023e8 -> 9a948720e


fixed a self-loop bug in StarGraph. Added StarGraphTest.shouldHandleSelfLoops() to ensure correct behavior.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/0563ec36
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/0563ec36
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/0563ec36

Branch: refs/heads/tp31
Commit: 0563ec36bb823d617acde6a15217c2b61471408d
Parents: 2451bb9
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 29 09:33:29 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 29 09:33:29 2016 -0600

----------------------------------------------------------------------
 .../gremlin/structure/util/star/StarGraph.java  | 17 +++--
 .../structure/util/star/StarGraphTest.java      | 70 ++++++++++++++++++++
 2 files changed, 82 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0563ec36/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index c613dbb..a8a72ff 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -206,10 +206,8 @@ public final class StarGraph implements Graph, Serializable {
         });
 
         vertex.edges(Direction.OUT).forEachRemaining(edge -> {
-            if (!ElementHelper.areEqual(starVertex, edge.inVertex())) { // only do a self loop once
-                final Edge starEdge = starVertex.addOutEdge(edge.label(), starGraph.addVertex(T.id, edge.inVertex().id()), T.id, edge.id());
-                edge.properties().forEachRemaining(p -> starEdge.property(p.key(), p.value()));
-            }
+            final Edge starEdge = starVertex.addOutEdge(edge.label(), starGraph.addVertex(T.id, edge.inVertex().id()), T.id, edge.id());
+            edge.properties().forEachRemaining(p -> starEdge.property(p.key(), p.value()));
         });
         return starGraph;
     }
@@ -290,7 +288,16 @@ public final class StarGraph implements Graph, Serializable {
 
         @Override
         public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
-            return this.addOutEdge(label, inVertex, keyValues);
+            final Edge edge = this.addOutEdge(label, inVertex, keyValues);
+            if (inVertex.equals(this)) {
+                List<Edge> inE = inEdges.get(label);
+                if (null == inE) {
+                    inE = new ArrayList<>();
+                    this.inEdges.put(label, inE);
+                }
+                inE.add(edge);
+            }
+            return edge;
         }
 
         @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/0563ec36/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index 2c5d6d2..fda6e37 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -40,6 +40,7 @@ import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Random;
 import java.util.Set;
@@ -47,6 +48,7 @@ import java.util.UUID;
 import java.util.stream.Collectors;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
@@ -161,6 +163,74 @@ public class StarGraphTest extends AbstractGremlinTest {
         TestHelper.validateEquality(starVertex, createdVertex);
     }
 
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_VERTICES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_ADD_PROPERTY)
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_EDGES)
+    @FeatureRequirement(featureClass = Graph.Features.EdgeFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_ADD_PROPERTY)
+    public void shouldHandleSelfLoops() {
+        assertEquals(0l, IteratorUtils.count(graph.vertices()));
+        assertEquals(0l, IteratorUtils.count(graph.edges()));
+        final Vertex vertex = graph.addVertex("person");
+        final VertexProperty<String> vertexProperty = vertex.property("name", "furnace");
+        final Edge edge = vertex.addEdge("self", vertex);
+        final Property<String> edgeProperty = edge.property("acl", "private");
+        assertEquals(1l, IteratorUtils.count(graph.vertices()));
+        assertEquals(1l, IteratorUtils.count(graph.edges()));
+        assertEquals(1l, IteratorUtils.count(vertex.properties()));
+        assertEquals(1l, IteratorUtils.count(edge.properties()));
+        assertEquals(vertexProperty, vertex.properties().next());
+        assertEquals(edgeProperty, edge.properties().next());
+        ///
+        final StarGraph starGraph = StarGraph.of(vertex);
+        final StarGraph.StarVertex starVertex = starGraph.getStarVertex();
+        final Edge starEdge = starVertex.edges(Direction.OUT).next();
+        assertEquals(vertex, starVertex);
+        assertEquals(edge, starEdge);
+        assertEquals(1l, IteratorUtils.count(starVertex.properties()));
+        assertEquals("furnace", starVertex.value("name"));
+        assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH, "self")));
+        assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT, "self")));
+        assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN, "self")));
+        Iterator<Vertex> vertexIterator = starVertex.vertices(Direction.BOTH, "self");
+        assertEquals(starVertex, vertexIterator.next());
+        assertEquals(starVertex, vertexIterator.next());
+        assertFalse(vertexIterator.hasNext());
+        assertEquals(starVertex, starVertex.vertices(Direction.OUT, "self").next());
+        assertEquals(starVertex, starVertex.vertices(Direction.IN, "self").next());
+        ///
+        assertEquals(2l, IteratorUtils.count(starVertex.vertices(Direction.BOTH)));
+        assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.OUT)));
+        assertEquals(1l, IteratorUtils.count(starVertex.vertices(Direction.IN)));
+        vertexIterator = starVertex.vertices(Direction.BOTH);
+        assertEquals(starVertex, vertexIterator.next());
+        assertEquals(starVertex, vertexIterator.next());
+        assertFalse(vertexIterator.hasNext());
+        assertEquals(starVertex, starVertex.vertices(Direction.OUT).next());
+        assertEquals(starVertex, starVertex.vertices(Direction.IN).next());
+        ///
+        assertEquals(2l, IteratorUtils.count(starVertex.edges(Direction.BOTH, "self", "nothing")));
+        assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.OUT, "self", "nothing")));
+        assertEquals(1l, IteratorUtils.count(starVertex.edges(Direction.IN, "self", "nothing")));
+        Iterator<Edge> edgeIterator = starVertex.edges(Direction.BOTH, "self", "nothing");
+        Edge tempEdge = edgeIterator.next();
+        assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
+        assertEquals("private", tempEdge.value("acl"));
+        assertEquals(starEdge, tempEdge);
+        tempEdge = edgeIterator.next();
+        assertEquals(1l, IteratorUtils.count(tempEdge.properties()));
+        assertEquals("private", tempEdge.value("acl"));
+        assertEquals(starEdge, tempEdge);
+        assertFalse(edgeIterator.hasNext());
+        assertEquals(starEdge, starVertex.edges(Direction.OUT, "self", "nothing").next());
+        assertEquals(starEdge, starVertex.edges(Direction.IN, "self", "nothing").next());
+        //
+        final StarGraph starGraphCopy = serializeDeserialize(starGraph).getValue0();
+        TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);
+        TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true);
+        TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true);
+    }
+
     private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         try {


[2/4] incubator-tinkerpop git commit: an untested addEdge method is now tested and the NPE thrown is now not there. Thank you @dalaro.

Posted by ok...@apache.org.
an untested addEdge method is now tested and the NPE thrown is now not there. Thank you @dalaro.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/82295fe1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/82295fe1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/82295fe1

Branch: refs/heads/tp31
Commit: 82295fe1eaaeab86517c191c1d44dfe3f0b34d2a
Parents: 0563ec3
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 29 10:37:51 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 29 10:37:51 2016 -0600

----------------------------------------------------------------------
 .../gremlin/structure/util/star/StarGraph.java      |  4 +++-
 .../gremlin/structure/util/star/StarGraphTest.java  | 16 ++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/82295fe1/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
index a8a72ff..f516630 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraph.java
@@ -290,7 +290,9 @@ public final class StarGraph implements Graph, Serializable {
         public Edge addEdge(final String label, final Vertex inVertex, final Object... keyValues) {
             final Edge edge = this.addOutEdge(label, inVertex, keyValues);
             if (inVertex.equals(this)) {
-                List<Edge> inE = inEdges.get(label);
+                if(null == this.inEdges)
+                    this.inEdges = new HashMap<>();
+                List<Edge> inE = this.inEdges.get(label);
                 if (null == inE) {
                     inE = new ArrayList<>();
                     this.inEdges.put(label, inE);

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/82295fe1/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
index fda6e37..034afad 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/star/StarGraphTest.java
@@ -229,8 +229,24 @@ public class StarGraphTest extends AbstractGremlinTest {
         TestHelper.validateVertexEquality(vertex, starGraph.getStarVertex(), true);
         TestHelper.validateVertexEquality(vertex, starGraphCopy.getStarVertex(), true);
         TestHelper.validateVertexEquality(starGraph.getStarVertex(), starGraphCopy.getStarVertex(), true);
+        // test native non-clone-based methods
+        final StarGraph starGraphNative = StarGraph.open();
+        Vertex v1 = starGraphNative.addVertex(T.label, "thing", T.id, "v1");
+        assertEquals("v1", v1.id());
+        assertEquals("thing", v1.label());
+        Edge e1 = v1.addEdge("self", v1, "name", "pipes");
+        assertEquals(2l, IteratorUtils.count(v1.vertices(Direction.BOTH, "self", "nothing")));
+        assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.OUT)));
+        assertEquals(1l, IteratorUtils.count(v1.vertices(Direction.IN, "self")));
+        edgeIterator = v1.edges(Direction.BOTH);
+        TestHelper.validateEdgeEquality(e1, edgeIterator.next());
+        TestHelper.validateEdgeEquality(e1, edgeIterator.next());
+        assertFalse(edgeIterator.hasNext());
+        TestHelper.validateEdgeEquality(e1, v1.edges(Direction.OUT, "self", "nothing").next());
+        TestHelper.validateEdgeEquality(e1, v1.edges(Direction.IN).next());
     }
 
+
     private Pair<StarGraph, Integer> serializeDeserialize(final StarGraph starGraph) {
         final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
         try {


[3/4] incubator-tinkerpop git commit: Merge branch 'TINKERPOP-1284' into tp31

Posted by ok...@apache.org.
Merge branch 'TINKERPOP-1284' into tp31


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/7427ae1e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/7427ae1e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/7427ae1e

Branch: refs/heads/tp31
Commit: 7427ae1eb3e4580dfbe838e6c48ed11f162a6e74
Parents: 704b023 82295fe
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon May 2 08:22:24 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon May 2 08:22:24 2016 -0600

----------------------------------------------------------------------
 .../gremlin/structure/util/star/StarGraph.java  | 19 +++--
 .../structure/util/star/StarGraphTest.java      | 86 ++++++++++++++++++++
 2 files changed, 100 insertions(+), 5 deletions(-)
----------------------------------------------------------------------



[4/4] incubator-tinkerpop git commit: Updated CHANGELOG.

Posted by ok...@apache.org.
Updated CHANGELOG.


Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/9a948720
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/9a948720
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/9a948720

Branch: refs/heads/tp31
Commit: 9a948720e70bee953c50ad6e9c613943a5a7051b
Parents: 7427ae1
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Mon May 2 08:23:17 2016 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Mon May 2 08:23:17 2016 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/9a948720/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 1848fdf..4b282de 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.3 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed a self-loop bug in `StarGraph`.
 * Added configuration option for disabling `:remote` timeout with `:remote config timeout none`.
 * Added `init-tp-spark.sh` to Gremlin Console binary distribution.
 * Fixed bug where use of `:x` in a Gremlin Console initialization script would generate a stack trace.