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/02/02 22:49:22 UTC

incubator-tinkerpop git commit: Added standard GraphComputer.Exceptions for GraphFilter and verfiy Exceptions are thrown correctly in GraphComputerTest. Tweaks to JavaDoc.

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-962 6cfb1f22f -> f7ad5c4f6


Added standard GraphComputer.Exceptions for GraphFilter and verfiy Exceptions are thrown correctly in GraphComputerTest. Tweaks to JavaDoc.


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

Branch: refs/heads/TINKERPOP-962
Commit: f7ad5c4f6a7b197cebb86fa22d4c263ce6b3365b
Parents: 6cfb1f2
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Feb 2 14:49:22 2016 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Feb 2 14:49:22 2016 -0700

----------------------------------------------------------------------
 .../gremlin/process/computer/GraphComputer.java   | 10 +++++++++-
 .../gremlin/process/computer/GraphFilter.java     |  4 ++--
 .../gremlin/process/computer/GraphFilterTest.java |  8 ++++----
 .../process/computer/GraphComputerTest.java       | 18 +++++++++++++++++-
 4 files changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f7ad5c4f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
index 7a0f593..ddb09a0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputer.java
@@ -126,7 +126,7 @@ public interface GraphComputer {
      *
      * @param edgeFilter the traversal that determines which edges are loaded for each vertex
      * @return the updated GraphComputer with newly set edge filter
-     * @throws IllegalArgumentException if the provided traversal goes attempts to access adjacent vertices
+     * @throws IllegalArgumentException if the provided traversal attempts to access adjacent vertices
      */
     public GraphComputer edges(final Traversal<Vertex, Edge> edgeFilter) throws IllegalArgumentException;
 
@@ -264,6 +264,14 @@ public interface GraphComputer {
         public static IllegalArgumentException computerRequiresMoreWorkersThanSupported(final int workers, final int maxWorkers) {
             return new IllegalArgumentException("The computer requires more workers than supported: " + workers + " [max:" + maxWorkers + "]");
         }
+
+        public static IllegalArgumentException vertexFilterAccessesIncidentEdges(final Traversal<Vertex, Vertex> vertexFilter) {
+            return new IllegalArgumentException("The provided vertex filter traversal accesses incident edges: " + vertexFilter);
+        }
+
+        public static IllegalArgumentException edgeFilterAccessesAdjacentVertices(final Traversal<Vertex, Edge> edgeFilter) {
+            return new IllegalArgumentException("The provided edge filter traversal accesses data on adjacent vertices: " + edgeFilter);
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f7ad5c4f/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
index f6c0726..082e1d4 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilter.java
@@ -53,13 +53,13 @@ public final class GraphFilter implements Cloneable, Serializable {
 
     public void setVertexFilter(final Traversal<Vertex, Vertex> vertexFilter) {
         if (!TraversalHelper.isLocalVertex(vertexFilter.asAdmin()))
-            throw new IllegalArgumentException("The provided vertex filter must not leave the local vertex: " + edgeFilter);
+            throw GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(vertexFilter);
         this.vertexFilter = vertexFilter.asAdmin().clone();
     }
 
     public void setEdgeFilter(final Traversal<Vertex, Edge> edgeFilter) {
         if (!TraversalHelper.isLocalStarGraph(edgeFilter.asAdmin()))
-            throw new IllegalArgumentException("The provided edge filter must not leave the local star graph: " + edgeFilter);
+            throw GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(edgeFilter);
         this.edgeFilter = edgeFilter.asAdmin().clone();
         if (this.edgeFilter.getStartStep() instanceof VertexStep) {
             this.allowedEdgeLabels.addAll(Arrays.asList(((VertexStep) this.edgeFilter.getStartStep()).getEdgeLabels()));

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f7ad5c4f/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
index 2fc3433..0a09155 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/computer/GraphFilterTest.java
@@ -77,18 +77,18 @@ public class GraphFilterTest {
         //
         graphFilter = new GraphFilter();
         try {
-            graphFilter.setEdgeFilter(__.<Vertex>inE("likes").inV().outE().has("weight", 1));    // cannot leave local star graph
+            graphFilter.setVertexFilter(__.out("likes"));    // cannot leave local vertex
             fail();
         } catch (final IllegalArgumentException e) {
-            assertTrue(e.getMessage().contains("local star graph"));
+            assertEquals(e.getMessage(), GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(__.out("likes")).getMessage());
         }
         //
         graphFilter = new GraphFilter();
         try {
-            graphFilter.setVertexFilter(__.out("likes"));    // cannot leave local vertex
+            graphFilter.setEdgeFilter(__.<Vertex>inE("likes").inV().outE().has("weight", 1));    // cannot leave local star graph
             fail();
         } catch (final IllegalArgumentException e) {
-            assertTrue(e.getMessage().contains("local vertex"));
+            assertEquals(e.getMessage(), GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(__.<Vertex>inE("likes").inV().outE().has("weight", 1)).getMessage());
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/f7ad5c4f/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
index 4e0a154..55d9dab 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
@@ -69,7 +69,9 @@ import static org.junit.Assert.fail;
         "adjacentVertexEdgesAndVerticesCanNotBeReadOrUpdated",
         "resultGraphPersistCombinationNotSupported",
         "vertexPropertiesCanNotBeUpdatedInMapReduce",
-        "computerRequiresMoreWorkersThanSupported"
+        "computerRequiresMoreWorkersThanSupported",
+        "vertexFilterAccessesIncidentEdges",
+        "edgeFilterAccessesAdjacentVertices"
 })
 @ExceptionCoverage(exceptionClass = Graph.Exceptions.class, methods = {
         "graphDoesNotSupportProvidedGraphComputer"
@@ -1505,6 +1507,20 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
         graph.compute(graphComputerClass.get()).edges(__.<Vertex>bothE().limit(0)).mapReduce(new MapReduceJ(VertexProgramM.VERTICES_ONLY)).submit().get();
         graph.compute(graphComputerClass.get()).edges(__.<Vertex>outE().limit(1)).mapReduce(new MapReduceJ(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get();
         graph.compute(graphComputerClass.get()).edges(__.outE()).mapReduce(new MapReduceJ(VertexProgramM.OUT_EDGES_ONLY)).submit().get();
+
+        // EXCEPTION HANDLING
+        try {
+            graph.compute(graphComputerClass.get()).vertices(__.out());
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals(e.getMessage(), GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(__.out()).getMessage());
+        }
+        try {
+            graph.compute(graphComputerClass.get()).edges(__.<Vertex>out().outE());
+            fail();
+        } catch (final IllegalArgumentException e) {
+            assertEquals(e.getMessage(), GraphComputer.Exceptions.edgeFilterAccessesAdjacentVertices(__.<Vertex>out().outE()).getMessage());
+        }
     }
 
     public static class VertexProgramM implements VertexProgram {