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 2015/04/24 18:47:37 UTC

incubator-tinkerpop git commit: added DetachedStarGraphTest which tests the topology of the DetachedXXX objects given Method.GET and Method.CREATE.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 49b21ff4d -> e790a89b0


added DetachedStarGraphTest which tests the topology of the DetachedXXX objects given Method.GET and Method.CREATE.


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

Branch: refs/heads/master
Commit: e790a89b0048d89d73249d21df237423c1d0f651
Parents: 49b21ff
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Apr 24 10:47:20 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Apr 24 10:47:30 2015 -0600

----------------------------------------------------------------------
 .../apache/tinkerpop/gremlin/TestHelper.java    | 31 +++----
 .../tinkerpop/gremlin/structure/IoTest.java     |  6 +-
 .../structure/StructureStandardSuite.java       |  2 +
 .../util/detached/DetachedGraphTest.java        | 96 ++++++++++++++++++++
 4 files changed, 116 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e790a89b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
index 533d5a7..d704e3e 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/TestHelper.java
@@ -20,9 +20,7 @@ package org.apache.tinkerpop.gremlin;
 
 import org.apache.tinkerpop.gremlin.structure.Direction;
 import org.apache.tinkerpop.gremlin.structure.Edge;
-import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Property;
-import org.apache.tinkerpop.gremlin.structure.T;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
@@ -107,7 +105,7 @@ public final class TestHelper {
 
     ///////////////
 
-    public static void validateVertexEquality(final Vertex originalVertex, final Vertex otherVertex) {
+    public static void validateVertexEquality(final Vertex originalVertex, final Vertex otherVertex, boolean testEdges) {
         assertEquals(originalVertex, otherVertex);
         assertEquals(otherVertex, originalVertex);
         assertEquals(originalVertex.id(), otherVertex.id());
@@ -122,20 +120,21 @@ public final class TestHelper {
                 validateVertexPropertyEquality(originalVertexProperty, otherVertexProperty);
             }
         }
+        if (testEdges) {
+            Iterator<Edge> originalEdges = IteratorUtils.set(originalVertex.edges(Direction.OUT)).iterator();
+            Iterator<Edge> otherEdges = IteratorUtils.set(otherVertex.edges(Direction.OUT)).iterator();
+            while (originalEdges.hasNext()) {
+                validateEdgeEquality(originalEdges.next(), otherEdges.next());
+            }
+            assertFalse(otherEdges.hasNext());
 
-        Iterator<Edge> originalEdges = IteratorUtils.set(originalVertex.edges(Direction.OUT)).iterator();
-        Iterator<Edge> otherEdges = IteratorUtils.set(otherVertex.edges(Direction.OUT)).iterator();
-        while (originalEdges.hasNext()) {
-            validateEdgeEquality(originalEdges.next(), otherEdges.next());
-        }
-        assertFalse(otherEdges.hasNext());
-
-        originalEdges = IteratorUtils.set(originalVertex.edges(Direction.IN)).iterator();
-        otherEdges = IteratorUtils.set(otherVertex.edges(Direction.IN)).iterator();
-        while (originalEdges.hasNext()) {
-            validateEdgeEquality(originalEdges.next(), otherEdges.next());
+            originalEdges = IteratorUtils.set(originalVertex.edges(Direction.IN)).iterator();
+            otherEdges = IteratorUtils.set(otherVertex.edges(Direction.IN)).iterator();
+            while (originalEdges.hasNext()) {
+                validateEdgeEquality(originalEdges.next(), otherEdges.next());
+            }
+            assertFalse(otherEdges.hasNext());
         }
-        assertFalse(otherEdges.hasNext());
 
     }
 
@@ -178,7 +177,7 @@ public final class TestHelper {
 
     public static void validateEquality(final Object original, final Object other) {
         if (original instanceof Vertex)
-            validateVertexEquality((Vertex) original, (Vertex) other);
+            validateVertexEquality((Vertex) original, (Vertex) other, true);
         else if (original instanceof VertexProperty)
             validateVertexPropertyEquality((VertexProperty) original, (VertexProperty) other);
         else if (original instanceof Edge)

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e790a89b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
index bc26053..5a28680 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/IoTest.java
@@ -1371,7 +1371,7 @@ public class IoTest extends AbstractGremlinTest {
             try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
                 reader.readVertex(bais, attachable -> {
                             final Vertex detachedVertex = attachable.get();
-                            TestHelper.validateVertexEquality(v1, detachedVertex);
+                            TestHelper.validateVertexEquality(v1, detachedVertex,true);
                             calledVertex.set(true);
                             return detachedVertex;
                         },
@@ -1466,7 +1466,7 @@ public class IoTest extends AbstractGremlinTest {
             try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
                 reader.readVertex(bais, attachable -> {
                     final Vertex detachedVertex = attachable.get();
-                    TestHelper.validateVertexEquality(v1, detachedVertex);
+                    TestHelper.validateVertexEquality(v1, detachedVertex,true);
                     calledVertex.set(true);
                     return detachedVertex;
                 }, attachable -> {
@@ -1563,7 +1563,7 @@ public class IoTest extends AbstractGremlinTest {
             try (final ByteArrayInputStream bais = new ByteArrayInputStream(os.toByteArray())) {
                 reader.readVertex(bais, attachable -> {
                             final Vertex detachedVertex = attachable.get();
-                            TestHelper.validateVertexEquality(v1, detachedVertex);
+                            TestHelper.validateVertexEquality(v1, detachedVertex,true);
                             calledVertex.set(true);
                             return detachedVertex;
                         },attachable -> {

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e790a89b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
index 0bd86d0..f65eb65 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/StructureStandardSuite.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.algorithm.generator.CommunityGeneratorTest;
 import org.apache.tinkerpop.gremlin.algorithm.generator.DistributionGeneratorTest;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedEdgeTest;
+import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedGraphTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedPropertyTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexPropertyTest;
 import org.apache.tinkerpop.gremlin.structure.util.detached.DetachedVertexTest;
@@ -76,6 +77,7 @@ public class StructureStandardSuite extends AbstractGremlinSuite {
     private static final Class<?>[] allTests = new Class<?>[]{
             BatchTest.class,
             CommunityGeneratorTest.class,
+            DetachedGraphTest.class,
             DetachedEdgeTest.class,
             DetachedVertexPropertyTest.class,
             DetachedPropertyTest.class,

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/e790a89b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedGraphTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedGraphTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedGraphTest.java
new file mode 100644
index 0000000..4990a74
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/structure/util/detached/DetachedGraphTest.java
@@ -0,0 +1,96 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one
+ *  * or more contributor license agreements.  See the NOTICE file
+ *  * distributed with this work for additional information
+ *  * regarding copyright ownership.  The ASF licenses this file
+ *  * to you under the Apache License, Version 2.0 (the
+ *  * "License"); you may not use this file except in compliance
+ *  * with the License.  You may obtain a copy of the License at
+ *  *
+ *  * http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing,
+ *  * software distributed under the License is distributed on an
+ *  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  * KIND, either express or implied.  See the License for the
+ *  * specific language governing permissions and limitations
+ *  * under the License.
+ *
+ */
+
+package org.apache.tinkerpop.gremlin.structure.util.detached;
+
+import org.apache.tinkerpop.gremlin.AbstractGremlinTest;
+import org.apache.tinkerpop.gremlin.FeatureRequirement;
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.TestHelper;
+import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+import org.apache.tinkerpop.gremlin.structure.Graph;
+import org.apache.tinkerpop.gremlin.structure.T;
+import org.apache.tinkerpop.gremlin.structure.Vertex;
+import org.apache.tinkerpop.gremlin.structure.util.Attachable;
+import org.apache.tinkerpop.gremlin.structure.util.star.StarGraph;
+import org.junit.Test;
+
+import java.util.Random;
+import java.util.UUID;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class DetachedGraphTest extends AbstractGremlinTest {
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.CREW)
+    public void testAttachableGetMethod() {
+        // vertex host
+        g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, DetachedFactory.detach(vertex, true).attach(Attachable.Method.get(vertex))));
+        g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, DetachedFactory.detach(vertexProperty, true).attach(Attachable.Method.get(vertex)))));
+        g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(vertex))))));
+        g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, DetachedFactory.detach(edge, true).attach(Attachable.Method.get(vertex)))));
+        g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(vertex))))));
+
+        // graph host
+        g.V().forEachRemaining(vertex -> TestHelper.validateEquality(vertex, DetachedFactory.detach(vertex, true).attach(Attachable.Method.get(graph))));
+        g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> TestHelper.validateEquality(vertexProperty, DetachedFactory.detach(vertexProperty, true).attach(Attachable.Method.get(graph)))));
+        g.V().forEachRemaining(vertex -> vertex.properties().forEachRemaining(vertexProperty -> vertexProperty.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(graph))))));
+        g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> TestHelper.validateEquality(edge, DetachedFactory.detach(edge, true).attach(Attachable.Method.get(graph)))));
+        g.V().forEachRemaining(vertex -> vertex.edges(Direction.OUT).forEachRemaining(edge -> edge.properties().forEachRemaining(property -> TestHelper.validateEquality(property, DetachedFactory.detach(property).attach(Attachable.Method.get(graph))))));
+
+    }
+
+    @Test
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_USER_SUPPLIED_IDS)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexPropertyFeatures.FEATURE_USER_SUPPLIED_IDS)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.EdgeFeatures.FEATURE_USER_SUPPLIED_IDS)
+    @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.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_META_PROPERTIES)
+    @FeatureRequirement(featureClass = Graph.Features.VertexFeatures.class, feature = Graph.Features.VertexFeatures.FEATURE_MULTI_PROPERTIES)
+    @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 testAttachableCreateMethod() {
+        final Random random = new Random(234335l);
+        StarGraph starGraph = StarGraph.open();
+        Vertex starVertex = starGraph.addVertex(T.label, "person", "name", "stephen", "name", "spmallete");
+        starVertex.property("acl", true, "timestamp", random.nextLong(), "creator", "marko");
+        for (int i = 0; i < 100; i++) {
+            starVertex.addEdge("knows", starGraph.addVertex("person", "name", new UUID(random.nextLong(), random.nextLong()), "since", random.nextLong()));
+            starGraph.addVertex(T.label, "project").addEdge("developedBy", starVertex, "public", random.nextBoolean());
+        }
+        final DetachedVertex detachedVertex = DetachedFactory.detach(starGraph.getStarVertex(), true);
+        final Vertex createdVertex = detachedVertex.attach(Attachable.Method.create(graph));
+        TestHelper.validateVertexEquality(detachedVertex, createdVertex, false);
+        TestHelper.validateVertexEquality(detachedVertex, starVertex, false);
+
+        starGraph.getStarVertex().edges(Direction.BOTH).forEachRemaining(starEdge -> {
+            final DetachedEdge detachedEdge = DetachedFactory.detach(starEdge, true);
+            final Edge createdEdge = detachedEdge.attach(Attachable.Method.create(random.nextBoolean() ? graph : createdVertex));
+            TestHelper.validateEdgeEquality(detachedEdge, starEdge);
+            TestHelper.validateEdgeEquality(detachedEdge, createdEdge);
+        });
+
+    }
+}