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 2017/06/27 15:50:19 UTC

[1/5] tinkerpop git commit: bugfix

Repository: tinkerpop
Updated Branches:
  refs/heads/tp32 5ac61b7af -> f1aed80b0


bugfix


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

Branch: refs/heads/tp32
Commit: 28c514da9065683ed90ea6aabc66ffdcbab99c11
Parents: b1c0723
Author: Sheldon <sh...@mindmaps.io>
Authored: Thu Jun 15 18:00:32 2017 +0100
Committer: Sheldon <sh...@mindmaps.io>
Committed: Mon Jun 19 11:20:20 2017 +0100

----------------------------------------------------------------------
 .../process/computer/TinkerMessageBoard.java    |  4 ++--
 .../process/computer/TinkerMessenger.java       | 22 +++++++++++++-------
 2 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/28c514da/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessageBoard.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessageBoard.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessageBoard.java
index b217801..422ab86 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessageBoard.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessageBoard.java
@@ -32,8 +32,8 @@ import java.util.concurrent.ConcurrentHashMap;
  */
 final class TinkerMessageBoard<M> {
 
-    public Map<Vertex, Queue<M>> sendMessages = new ConcurrentHashMap<>();
-    public Map<Vertex, Queue<M>> receiveMessages = new ConcurrentHashMap<>();
+    public Map<MessageScope, Map<Vertex,Queue<M>>> sendMessages = new ConcurrentHashMap<>();
+    public Map<MessageScope, Map<Vertex, Queue<M>>> receiveMessages = new ConcurrentHashMap<>();
     public Set<MessageScope> previousMessageScopes = new HashSet<>();
     public Set<MessageScope> currentMessageScopes = new HashSet<>();
 

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/28c514da/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java
----------------------------------------------------------------------
diff --git a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java
index 3298aff..d3f2de5 100644
--- a/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java
+++ b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java
@@ -37,6 +37,7 @@ import java.util.Optional;
 import java.util.Queue;
 import java.util.Spliterator;
 import java.util.Spliterators;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.stream.Stream;
 import java.util.stream.StreamSupport;
@@ -59,14 +60,15 @@ public final class TinkerMessenger<M> implements Messenger<M> {
     @Override
     public Iterator<M> receiveMessages() {
         final MultiIterator<M> multiIterator = new MultiIterator<>();
-        for (final MessageScope messageScope : this.messageBoard.previousMessageScopes) {
+        for (final MessageScope messageScope : this.messageBoard.receiveMessages.keySet()) {
+//        for (final MessageScope messageScope : this.messageBoard.previousMessageScopes) {
             if (messageScope instanceof MessageScope.Local) {
                 final MessageScope.Local<M> localMessageScope = (MessageScope.Local<M>) messageScope;
                 final Traversal.Admin<Vertex, Edge> incidentTraversal = TinkerMessenger.setVertexStart(localMessageScope.getIncidentTraversal().get().asAdmin(), this.vertex);
                 final Direction direction = TinkerMessenger.getDirection(incidentTraversal);
                 final Edge[] edge = new Edge[1]; // simulates storage side-effects available in Gremlin, but not Java8 streams
                 multiIterator.addIterator(StreamSupport.stream(Spliterators.spliteratorUnknownSize(VertexProgramHelper.reverse(incidentTraversal.asAdmin()), Spliterator.IMMUTABLE | Spliterator.SIZED), false)
-                        .map(e -> this.messageBoard.receiveMessages.get((edge[0] = e).vertices(direction).next()))
+                        .map(e -> this.messageBoard.receiveMessages.get(messageScope).get((edge[0] = e).vertices(direction).next()))
                         .filter(q -> null != q)
                         .flatMap(Queue::stream)
                         .map(message -> localMessageScope.getEdgeFunction().apply(message, edge[0]))
@@ -74,7 +76,7 @@ public final class TinkerMessenger<M> implements Messenger<M> {
 
             } else {
                 multiIterator.addIterator(Stream.of(this.vertex)
-                        .map(this.messageBoard.receiveMessages::get)
+                        .map(this.messageBoard.receiveMessages.get(messageScope)::get)
                         .filter(q -> null != q)
                         .flatMap(Queue::stream)
                         .iterator());
@@ -85,16 +87,20 @@ public final class TinkerMessenger<M> implements Messenger<M> {
 
     @Override
     public void sendMessage(final MessageScope messageScope, final M message) {
-        this.messageBoard.currentMessageScopes.add(messageScope);
+//        this.messageBoard.currentMessageScopes.add(messageScope);
         if (messageScope instanceof MessageScope.Local) {
-            addMessage(this.vertex, message);
+            addMessage(this.vertex, message, messageScope);
         } else {
-            ((MessageScope.Global) messageScope).vertices().forEach(v -> addMessage(v, message));
+            ((MessageScope.Global) messageScope).vertices().forEach(v -> addMessage(v, message, messageScope));
         }
     }
 
-    private void addMessage(final Vertex vertex, final M message) {
-        this.messageBoard.sendMessages.compute(vertex, (v, queue) -> {
+    private void addMessage(final Vertex vertex, final M message, MessageScope messageScope) {
+        this.messageBoard.sendMessages.compute(messageScope, (ms, messages) -> {
+            if(null==messages) messages = new ConcurrentHashMap<>();
+            return messages;
+        });
+        this.messageBoard.sendMessages.get(messageScope).compute(vertex, (v, queue) -> {
             if (null == queue) queue = new ConcurrentLinkedQueue<>();
             queue.add(null != this.combiner && !queue.isEmpty() ? this.combiner.combine(queue.remove(), message) : message);
             return queue;


[5/5] tinkerpop git commit: fixed up the MultiScope test to use MODERN so that it works with Giraph and Spark. Will back tweak to tp31/.

Posted by ok...@apache.org.
fixed up the MultiScope test to use MODERN so that it works with Giraph and Spark. Will back tweak to tp31/.


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

Branch: refs/heads/tp32
Commit: f1aed80b056c2244ce8b23ab077e8b10ee6939d9
Parents: 5ac61b7 3b8c628
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 27 09:50:15 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 27 09:50:15 2017 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  2 +
 .../process/computer/GraphComputerTest.java     | 75 ++++++++++++++++++--
 .../process/computer/TinkerMessageBoard.java    |  4 +-
 .../process/computer/TinkerMessenger.java       | 22 +++---
 4 files changed, 88 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1aed80b/CHANGELOG.asciidoc
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1aed80b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
----------------------------------------------------------------------
diff --cc gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/GraphComputerTest.java
index 5c66673,02ac5d4..e4b40e8
--- 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
@@@ -24,35 -22,18 +24,32 @@@ import org.apache.commons.configuration
  import org.apache.tinkerpop.gremlin.ExceptionCoverage;
  import org.apache.tinkerpop.gremlin.LoadGraphWith;
  import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 +import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram;
 +import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram;
 +import org.apache.tinkerpop.gremlin.process.computer.traversal.TraversalVertexProgram;
 +import org.apache.tinkerpop.gremlin.process.computer.util.AbstractVertexProgramBuilder;
  import org.apache.tinkerpop.gremlin.process.computer.util.StaticMapReduce;
  import org.apache.tinkerpop.gremlin.process.computer.util.StaticVertexProgram;
 +import org.apache.tinkerpop.gremlin.process.traversal.Operator;
 +import org.apache.tinkerpop.gremlin.process.traversal.P;
- import org.apache.tinkerpop.gremlin.process.traversal.Path;
 +import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 +import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
  import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 +import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyPath;
 +import org.apache.tinkerpop.gremlin.process.traversal.strategy.verification.VerificationException;
 +import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 +import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
  import org.apache.tinkerpop.gremlin.structure.Direction;
 -import org.apache.tinkerpop.gremlin.structure.Element;
 +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.Vertex;
  import org.apache.tinkerpop.gremlin.structure.VertexProperty;
  import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
  import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 +import org.javatuples.Pair;
- import org.junit.Ignore;
  import org.junit.Test;
  
- import java.util.AbstractMap;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collections;
@@@ -70,15 -50,11 +68,14 @@@ import java.util.concurrent.Future
  
  import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.GRATEFUL;
  import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
 +import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
- import static org.apache.tinkerpop.gremlin.structure.T.id;
  import static org.junit.Assert.assertEquals;
  import static org.junit.Assert.assertFalse;
  import static org.junit.Assert.assertTrue;
  import static org.junit.Assert.fail;
 +import static org.junit.Assume.assumeNoException;
 +
+ 
  /**
   * @author Marko A. Rodriguez (http://markorodriguez.com)
   */
@@@ -1588,567 -1468,92 +1585,635 @@@ public class GraphComputerTest extends 
          public void storeState(final Configuration configuration) {
              VertexProgram.super.storeState(configuration);
          }
+     }
+ 
+     /////////////////////////////////////////////
+     @Test
++    @LoadGraphWith(MODERN)
+     public void shouldSupportMultipleScopes() throws ExecutionException, InterruptedException {
 -        Vertex a = graph.addVertex("a");
 -        Vertex b = graph.addVertex("b");
 -        Vertex c = graph.addVertex("c");
 -        a.addEdge("edge", b);
 -        b.addEdge("edge", c);
 -
 -        // Simple graph:
 -        // a -> b -> c
 -
 -        // Execute a traversal program that sends an incoming message of "2" and an outgoing message of "1" from "b"
 -        // then each vertex sums any received messages
 -        ComputerResult result = graph.compute().program(new MultiScopeVertexProgram()).submit().get();
 -
 -        // We expect the results to be {a=2, b=0, c=1}. Instead it is {a=3, b=0, c=3}
 -        assertEquals((Long) result.graph().traversal().V().hasLabel("a").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(2L));
 -        assertEquals((Long) result.graph().traversal().V().hasLabel("b").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(0L));
 -        assertEquals((Long) result.graph().traversal().V().hasLabel("c").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(1L));
++        final ComputerResult result = graph.compute().program(new MultiScopeVertexProgram()).submit().get();
++        assertEquals(result.graph().traversal().V().has("name", "josh").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 0L);
++        assertEquals(result.graph().traversal().V().has("name", "lop").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L);
++        assertEquals(result.graph().traversal().V().has("name", "ripple").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 1L);
++        assertEquals(result.graph().traversal().V().has("name", "marko").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(), 2L);
+     }
+ 
 -    public static class MultiScopeVertexProgram implements VertexProgram<Long> {
++    public static class MultiScopeVertexProgram extends StaticVertexProgram<Long> {
+ 
+         private final MessageScope.Local<Long> countMessageScopeIn = MessageScope.Local.of(__::inE);
+         private final MessageScope.Local<Long> countMessageScopeOut = MessageScope.Local.of(__::outE);
+ 
+         private static final String MEMORY_KEY = "count";
+ 
 -        private static final Set<String> COMPUTE_KEYS = Collections.singleton(MEMORY_KEY);
+ 
+         @Override
 -        public void setup(final Memory memory) {}
++        public void setup(final Memory memory) {
++        }
+ 
+         @Override
+         public GraphComputer.Persist getPreferredPersist() {
+             return GraphComputer.Persist.VERTEX_PROPERTIES;
+         }
+ 
+         @Override
 -        public Set<String> getElementComputeKeys() {
 -            return COMPUTE_KEYS;
++        public Set<VertexComputeKey> getVertexComputeKeys() {
++            return Collections.singleton(VertexComputeKey.of(MEMORY_KEY, false));
+         }
+ 
+         @Override
+         public Set<MessageScope> getMessageScopes(final Memory memory) {
+             HashSet<MessageScope> scopes = new HashSet<>();
+             scopes.add(countMessageScopeIn);
+             scopes.add(countMessageScopeOut);
+             return scopes;
+         }
+ 
+         @Override
+         public void execute(Vertex vertex, Messenger<Long> messenger, Memory memory) {
+             switch (memory.getIteration()) {
+                 case 0:
 -                    if (vertex.label().equals("b")) {
++                    if (vertex.value("name").equals("josh")) {
+                         messenger.sendMessage(this.countMessageScopeIn, 2L);
+                         messenger.sendMessage(this.countMessageScopeOut, 1L);
+                     }
+                     break;
+                 case 1:
+                     long edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0L, (a, b) -> a + b);
+                     vertex.property(MEMORY_KEY, edgeCount);
+                     break;
+             }
+         }
+ 
+         @Override
+         public boolean terminate(final Memory memory) {
+             return memory.getIteration() == 1;
+         }
+ 
+         @Override
+         public GraphComputer.ResultGraph getPreferredResultGraph() {
+             return GraphComputer.ResultGraph.NEW;
+         }
  
 -        @Override
 -        public MultiScopeVertexProgram clone() {
 +    }
 +
 +    /////////////////////////////////////////////
 +
 +    @Test
 +    @LoadGraphWith(MODERN)
 +    public void shouldSupportGraphFilter() throws Exception {
 +        // if the graph computer does not support graph filter, then make sure its exception handling is correct
 +        if (!graphProvider.getGraphComputer(graph).features().supportsGraphFilter()) {
              try {
 -                return (MultiScopeVertexProgram) super.clone();
 -            } catch (final CloneNotSupportedException e) {
 -                throw new RuntimeException(e);
 +                graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software"));
 +                fail("Should throw an unsupported operation exception");
 +            } catch (final UnsupportedOperationException e) {
 +                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
 +            }
 +            try {
 +                graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(10));
 +                fail("Should throw an unsupported operation exception");
 +            } catch (final UnsupportedOperationException e) {
 +                assertEquals(GraphComputer.Exceptions.graphFilterNotSupported().getMessage(), e.getMessage());
 +            }
 +            return;
 +        }
 +        /// VERTEX PROGRAM
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).program(new VertexProgramM(VertexProgramM.SOFTWARE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).program(new VertexProgramM(VertexProgramM.PEOPLE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).program(new VertexProgramM(VertexProgramM.VERTICES_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).program(new VertexProgramM(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(outE()).program(new VertexProgramM(VertexProgramM.OUT_EDGES_ONLY)).submit().get();
 +
 +        /// VERTEX PROGRAM + MAP REDUCE
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).program(new VertexProgramM(VertexProgramM.SOFTWARE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.SOFTWARE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).program(new VertexProgramM(VertexProgramM.PEOPLE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.KNOWS_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).program(new VertexProgramM(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).program(new VertexProgramM(VertexProgramM.VERTICES_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.VERTICES_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).program(new VertexProgramM(VertexProgramM.ONE_OUT_EDGE_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(outE()).program(new VertexProgramM(VertexProgramM.OUT_EDGES_ONLY)).mapReduce(new MapReduceJ(VertexProgramM.OUT_EDGES_ONLY)).submit().get();
 +
 +        /// MAP REDUCE ONLY
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("software")).mapReduce(new MapReduceJ(VertexProgramM.SOFTWARE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.bothE("knows")).mapReduce(new MapReduceJ(VertexProgramM.KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.bothE("knows")).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).vertices(__.hasLabel("person")).edges(__.<Vertex>bothE("knows").has("weight", P.gt(0.5f))).mapReduce(new MapReduceJ(VertexProgramM.PEOPLE_KNOWS_WELL_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>bothE().limit(0)).mapReduce(new MapReduceJ(VertexProgramM.VERTICES_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(__.<Vertex>outE().limit(1)).mapReduce(new MapReduceJ(VertexProgramM.ONE_OUT_EDGE_ONLY)).submit().get();
 +        graphProvider.getGraphComputer(graph).edges(outE()).mapReduce(new MapReduceJ(VertexProgramM.OUT_EDGES_ONLY)).submit().get();
 +
 +        // EXCEPTION HANDLING
 +        try {
 +            graphProvider.getGraphComputer(graph).vertices(__.out());
 +            fail();
 +        } catch (final IllegalArgumentException e) {
 +            assertEquals(e.getMessage(), GraphComputer.Exceptions.vertexFilterAccessesIncidentEdges(__.out()).getMessage());
 +        }
 +        try {
 +            graphProvider.getGraphComputer(graph).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 {
 +
 +        public static final String SOFTWARE_ONLY = "softwareOnly";
 +        public static final String PEOPLE_ONLY = "peopleOnly";
 +        public static final String KNOWS_ONLY = "knowsOnly";
 +        public static final String PEOPLE_KNOWS_ONLY = "peopleKnowsOnly";
 +        public static final String PEOPLE_KNOWS_WELL_ONLY = "peopleKnowsWellOnly";
 +        public static final String VERTICES_ONLY = "verticesOnly";
 +        public static final String ONE_OUT_EDGE_ONLY = "oneOutEdgeOnly";
 +        public static final String OUT_EDGES_ONLY = "outEdgesOnly";
 +
 +        private String state;
 +
 +        public VertexProgramM() {
 +
 +        }
 +
 +        public VertexProgramM(final String state) {
 +            this.state = state;
 +        }
 +
 +        @Override
 +        public void setup(final Memory memory) {
 +
 +        }
 +
 +        @Override
 +        public void execute(final Vertex vertex, final Messenger messenger, final Memory memory) {
 +            switch (this.state) {
 +                case SOFTWARE_ONLY: {
 +                    assertEquals("software", vertex.label());
 +                    assertFalse(vertex.edges(Direction.OUT).hasNext());
 +                    assertTrue(vertex.edges(Direction.IN).hasNext());
 +                    assertTrue(vertex.edges(Direction.IN, "created").hasNext());
 +                    assertFalse(vertex.edges(Direction.IN, "knows").hasNext());
 +                    break;
 +                }
 +                case PEOPLE_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    assertFalse(vertex.edges(Direction.IN, "created").hasNext());
 +                    assertTrue(IteratorUtils.count(vertex.edges(Direction.BOTH)) > 0);
 +                    break;
 +                }
 +                case KNOWS_ONLY: {
 +                    assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "created")));
 +                    if (vertex.value("name").equals("marko"))
 +                        assertEquals(2, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                    else if (vertex.value("name").equals("vadas"))
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                    else if (vertex.value("name").equals("josh"))
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                    else {
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    }
 +                    break;
 +                }
 +                case PEOPLE_KNOWS_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "created")));
 +                    if (vertex.value("name").equals("marko"))
 +                        assertEquals(2, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                    else if (vertex.value("name").equals("vadas"))
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                    else if (vertex.value("name").equals("josh"))
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                    else {
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    }
 +                    break;
 +                }
 +                case PEOPLE_KNOWS_WELL_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "created")));
 +                    if (vertex.value("name").equals("marko")) {
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                        assertEquals(1.0, vertex.edges(Direction.OUT, "knows").next().value("weight"), 0.001);
 +                    } else if (vertex.value("name").equals("vadas"))
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                    else if (vertex.value("name").equals("josh")) {
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.IN, "knows")));
 +                        assertEquals(1.0, vertex.edges(Direction.IN, "knows").next().value("weight"), 0.001);
 +                    } else {
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH, "knows")));
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    }
 +                    break;
 +                }
 +                case VERTICES_ONLY: {
 +                    assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    break;
 +                }
 +                case ONE_OUT_EDGE_ONLY: {
 +                    if (vertex.label().equals("software") || vertex.value("name").equals("vadas"))
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    else {
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.OUT)));
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.IN)));
 +                        assertEquals(1, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    }
 +                    break;
 +                }
 +                case OUT_EDGES_ONLY: {
 +                    if (vertex.label().equals("software") || vertex.value("name").equals("vadas"))
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    else {
 +                        assertTrue(IteratorUtils.count(vertex.edges(Direction.OUT)) > 0);
 +                        assertEquals(0, IteratorUtils.count(vertex.edges(Direction.IN)));
 +                        assertEquals(IteratorUtils.count(vertex.edges(Direction.OUT)), IteratorUtils.count(vertex.edges(Direction.BOTH)));
 +                    }
 +                    break;
 +                }
 +                default:
 +                    throw new IllegalStateException("This is an illegal state for this test case: " + this.state);
 +            }
 +        }
 +
 +        @Override
 +        public boolean terminate(final Memory memory) {
 +            return true;
 +        }
 +
 +        @Override
 +        public Set<MessageScope> getMessageScopes(Memory memory) {
 +            return Collections.emptySet();
 +        }
 +
 +        @Override
 +        public GraphComputer.ResultGraph getPreferredResultGraph() {
 +            return GraphComputer.ResultGraph.NEW;
 +        }
 +
 +        @Override
 +        public GraphComputer.Persist getPreferredPersist() {
 +            return GraphComputer.Persist.NOTHING;
 +        }
 +
 +        @Override
 +        @SuppressWarnings("CloneDoesntCallSuperClone,CloneDoesntDeclareCloneNotSupportedException")
 +        public VertexProgramM clone() {
 +            return new VertexProgramM(this.state);
 +        }
 +
 +        @Override
 +        public void loadState(final Graph graph, final Configuration configuration) {
 +            this.state = configuration.getString("state");
 +        }
 +
 +        @Override
 +        public void storeState(final Configuration configuration) {
 +            configuration.setProperty("state", this.state);
 +            VertexProgram.super.storeState(configuration);
 +        }
 +
 +    }
 +
 +    private static class MapReduceJ implements MapReduce<MapReduce.NullObject, Integer, MapReduce.NullObject, Integer, Integer> {
 +
 +        private String state;
 +
 +        public MapReduceJ() {
 +        }
 +
 +        public MapReduceJ(final String state) {
 +            this.state = state;
 +        }
 +
 +        @Override
 +        public void loadState(final Graph graph, final Configuration configuration) {
 +            this.state = configuration.getString("state");
 +        }
 +
 +        @Override
 +        public void storeState(final Configuration configuration) {
 +            configuration.setProperty("state", this.state);
 +            MapReduce.super.storeState(configuration);
 +        }
 +
 +        @Override
 +        @SuppressWarnings("CloneDoesntCallSuperClone,CloneDoesntDeclareCloneNotSupportedException")
 +        public MapReduceJ clone() {
 +            return new MapReduceJ(this.state);
 +        }
 +
 +        @Override
 +        public boolean doStage(final Stage stage) {
 +            return true;
 +        }
 +
 +        @Override
 +        public void map(final Vertex vertex, final MapEmitter<NullObject, Integer> emitter) {
 +            emitter.emit(1);
 +            switch (this.state) {
 +                case VertexProgramM.SOFTWARE_ONLY: {
 +                    assertEquals("software", vertex.label());
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    break;
 +                }
 +                case VertexProgramM.KNOWS_ONLY: {
 +                    assertTrue(vertex.label().equals("person") || vertex.label().equals("software"));
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_KNOWS_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_KNOWS_WELL_ONLY: {
 +                    assertEquals("person", vertex.label());
 +                    break;
 +                }
 +                case VertexProgramM.VERTICES_ONLY: {
 +                    assertTrue(vertex.label().equals("person") || vertex.label().equals("software"));
 +                    break;
 +                }
 +                case VertexProgramM.ONE_OUT_EDGE_ONLY: {
 +                    assertTrue(vertex.label().equals("person") || vertex.label().equals("software"));
 +                    break;
 +                }
 +                case VertexProgramM.OUT_EDGES_ONLY: {
 +                    assertTrue(vertex.label().equals("person") || vertex.label().equals("software"));
 +                    break;
 +                }
 +                default:
 +                    throw new IllegalStateException("This is an illegal state for this test case: " + this.state);
 +            }
 +        }
 +
 +        @Override
 +        public void combine(final NullObject key, final Iterator<Integer> values, final ReduceEmitter<NullObject, Integer> emitter) {
 +            this.reduce(key, values, emitter);
 +        }
 +
 +        @Override
 +        public void reduce(final NullObject key, final Iterator<Integer> values, final ReduceEmitter<NullObject, Integer> emitter) {
 +            int count = 0;
 +            while (values.hasNext()) {
 +                count = count + values.next();
 +            }
 +            emitter.emit(count);
 +        }
 +
 +        @Override
 +        public Integer generateFinalResult(final Iterator<KeyValue<NullObject, Integer>> keyValues) {
 +            int counter = keyValues.next().getValue();
 +            assertFalse(keyValues.hasNext());
 +
 +            switch (this.state) {
 +                case VertexProgramM.SOFTWARE_ONLY: {
 +                    assertEquals(2, counter);
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_ONLY: {
 +                    assertEquals(4, counter);
 +                    break;
 +                }
 +                case VertexProgramM.KNOWS_ONLY: {
 +                    assertEquals(6, counter);
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_KNOWS_ONLY: {
 +                    assertEquals(4, counter);
 +                    break;
 +                }
 +                case VertexProgramM.PEOPLE_KNOWS_WELL_ONLY: {
 +                    assertEquals(4, counter);
 +                    break;
 +                }
 +                case VertexProgramM.VERTICES_ONLY: {
 +                    assertEquals(6, counter);
 +                    break;
 +                }
 +                case VertexProgramM.ONE_OUT_EDGE_ONLY: {
 +                    assertEquals(6, counter);
 +                    break;
 +                }
 +                case VertexProgramM.OUT_EDGES_ONLY: {
 +                    assertEquals(6, counter);
 +                    break;
 +                }
 +                default:
 +                    throw new IllegalStateException("This is an illegal state for this test case: " + this.state);
 +            }
 +            return counter;
 +        }
 +
 +        @Override
 +        public String getMemoryKey() {
 +            return "a";
 +        }
 +    }
 +
 +    @Test
 +    @LoadGraphWith(MODERN)
 +    public void shouldSupportJobChaining() throws Exception {
 +        final ComputerResult result1 = graphProvider.getGraphComputer(graph)
 +                .program(PageRankVertexProgram.build().iterations(5).create(graph)).persist(GraphComputer.Persist.EDGES).result(GraphComputer.ResultGraph.NEW).submit().get();
 +        final Graph graph1 = result1.graph();
 +        final Memory memory1 = result1.memory();
 +        assertEquals(5, memory1.getIteration());
 +        assertEquals(6, graph1.traversal().V().count().next().intValue());
 +        assertEquals(6, graph1.traversal().E().count().next().intValue());
 +        assertEquals(6, graph1.traversal().V().values(PageRankVertexProgram.PAGE_RANK).count().next().intValue());
 +        assertEquals(18, graph1.traversal().V().values().count().next().intValue());
 +        //
 +        final ComputerResult result2 = graph1.compute(graphProvider.getGraphComputer(graph1).getClass())
 +                .program(PeerPressureVertexProgram.build().maxIterations(4).create(graph1)).persist(GraphComputer.Persist.EDGES).result(GraphComputer.ResultGraph.NEW).submit().get();
 +        final Graph graph2 = result2.graph();
 +        final Memory memory2 = result2.memory();
 +        assertTrue(memory2.getIteration() <= 4);
 +        assertEquals(6, graph2.traversal().V().count().next().intValue());
 +        assertEquals(6, graph2.traversal().E().count().next().intValue());
 +        assertEquals(6, graph2.traversal().V().values(PeerPressureVertexProgram.CLUSTER).count().next().intValue());
 +        assertEquals(6, graph2.traversal().V().values(PageRankVertexProgram.PAGE_RANK).count().next().intValue());
 +        assertEquals(24, graph2.traversal().V().values().count().next().intValue());
 +        //
 +        final ComputerResult result3 = graph2.compute(graphProvider.getGraphComputer(graph2).getClass())
 +                .program(TraversalVertexProgram.build().traversal(g.V().groupCount("m").by(__.values(PageRankVertexProgram.PAGE_RANK).count()).label().asAdmin()).create(graph2)).persist(GraphComputer.Persist.EDGES).result(GraphComputer.ResultGraph.NEW).submit().get();
 +        final Graph graph3 = result3.graph();
 +        final Memory memory3 = result3.memory();
 +        assertTrue(memory3.keys().contains("m"));
 +        assertTrue(memory3.keys().contains(TraversalVertexProgram.HALTED_TRAVERSERS));
 +        assertEquals(1, memory3.<Map<Long, Long>>get("m").size());
 +        assertEquals(6, memory3.<Map<Long, Long>>get("m").get(1l).intValue());
 +        List<Traverser<String>> traversers = IteratorUtils.list(memory3.<TraverserSet>get(TraversalVertexProgram.HALTED_TRAVERSERS).iterator());
 +        assertEquals(6l, traversers.stream().map(Traverser::bulk).reduce((a, b) -> a + b).get().longValue());
 +        assertEquals(4l, traversers.stream().filter(s -> s.get().equals("person")).map(Traverser::bulk).reduce((a, b) -> a + b).get().longValue());
 +        assertEquals(2l, traversers.stream().filter(s -> s.get().equals("software")).map(Traverser::bulk).reduce((a, b) -> a + b).get().longValue());
 +        assertEquals(6, graph3.traversal().V().count().next().intValue());
 +        assertEquals(6, graph3.traversal().E().count().next().intValue());
 +        assertEquals(0, graph3.traversal().V().values(TraversalVertexProgram.HALTED_TRAVERSERS).count().next().intValue());
 +        assertEquals(6, graph3.traversal().V().values(PeerPressureVertexProgram.CLUSTER).count().next().intValue());
 +        assertEquals(6, graph3.traversal().V().values(PageRankVertexProgram.PAGE_RANK).count().next().intValue());
 +        assertEquals(24, graph3.traversal().V().values().count().next().intValue()); // no halted traversers
 +
 +        // TODO: add a test the shows DAG behavior -- splitting another TraversalVertexProgram off of the PeerPressureVertexProgram job.
 +    }
 +
 +    ///////////////////////////////////
 +
 +    @Test
 +    @LoadGraphWith(MODERN)
 +    public void shouldSupportPreExistingComputeKeys() throws Exception {
 +        final ComputerResult result = graphProvider.getGraphComputer(graph).program(new VertexProgramN()).submit().get();
 +        result.graph().vertices().forEachRemaining(vertex -> {
 +            if (vertex.label().equals("person")) {
 +                if (vertex.value("name").equals("marko"))
 +                    assertEquals(32, vertex.<Integer>value("age").intValue());
 +                else if (vertex.value("name").equals("peter"))
 +                    assertEquals(38, vertex.<Integer>value("age").intValue());
 +                else if (vertex.value("name").equals("vadas"))
 +                    assertEquals(30, vertex.<Integer>value("age").intValue());
 +                else if (vertex.value("name").equals("josh"))
 +                    assertEquals(35, vertex.<Integer>value("age").intValue());
 +                else
 +                    throw new IllegalStateException("This vertex should not have been accessed: " + vertex);
 +            }
 +        });
 +    }
 +
 +    private static class VertexProgramN extends StaticVertexProgram {
 +
 +        @Override
 +        public void setup(final Memory memory) {
 +
 +        }
 +
 +        @Override
 +        public void execute(final Vertex vertex, final Messenger messenger, final Memory memory) {
 +            if (vertex.label().equals("person"))
 +                vertex.property(VertexProperty.Cardinality.single, "age", vertex.<Integer>value("age") + 1);
 +        }
 +
 +        @Override
 +        public boolean terminate(final Memory memory) {
 +            return memory.getIteration() > 1;
 +        }
 +
 +        @Override
 +        public Set<MessageScope> getMessageScopes(final Memory memory) {
 +            return Collections.emptySet();
 +        }
 +
 +        @Override
 +        public Set<VertexComputeKey> getVertexComputeKeys() {
 +            return Collections.singleton(VertexComputeKey.of("age", false));
 +        }
 +
 +        @Override
 +        public GraphComputer.ResultGraph getPreferredResultGraph() {
 +            return GraphComputer.ResultGraph.NEW;
 +        }
 +
 +        @Override
 +        public GraphComputer.Persist getPreferredPersist() {
 +            return GraphComputer.Persist.VERTEX_PROPERTIES;
 +        }
 +    }
 +
 +    ///////////////////////////////////
 +
 +    @Test
 +    @LoadGraphWith(MODERN)
 +    public void shouldSupportTransientKeys() throws Exception {
 +        final ComputerResult result = graphProvider.getGraphComputer(graph).program(new VertexProgramO()).mapReduce(new MapReduceK()).submit().get();
 +        result.graph().vertices().forEachRemaining(vertex -> {
 +            assertFalse(vertex.property("v1").isPresent());
 +            assertFalse(vertex.property("v2").isPresent());
 +            assertTrue(vertex.property("v3").isPresent());
 +            assertEquals("shouldExist", vertex.value("v3"));
 +            assertTrue(vertex.property("name").isPresent());
 +            if (vertex.label().equals("software"))
 +                assertTrue(vertex.property("lang").isPresent());
 +            else
 +                assertTrue(vertex.property("age").isPresent());
 +            assertEquals(3, IteratorUtils.count(vertex.properties()));
 +            assertEquals(0, IteratorUtils.count(vertex.properties("v1")));
 +            assertEquals(0, IteratorUtils.count(vertex.properties("v2")));
 +            assertEquals(1, IteratorUtils.count(vertex.properties("v3")));
 +            assertEquals(1, IteratorUtils.count(vertex.properties("name")));
 +        });
 +        assertEquals(6l, result.graph().traversal().V().properties("name").count().next().longValue());
 +        assertEquals(0l, result.graph().traversal().V().properties("v1").count().next().longValue());
 +        assertEquals(0l, result.graph().traversal().V().properties("v2").count().next().longValue());
 +        assertEquals(6l, result.graph().traversal().V().properties("v3").count().next().longValue());
 +        assertEquals(6l, result.graph().traversal().V().<String>values("name").dedup().count().next().longValue());
 +        assertEquals(1l, result.graph().traversal().V().<String>values("v3").dedup().count().next().longValue());
 +        assertEquals("shouldExist", result.graph().traversal().V().<String>values("v3").dedup().next());
 +        ///
 +        assertFalse(result.memory().exists("m1"));
 +        assertFalse(result.memory().exists("m2"));
 +        assertTrue(result.memory().exists("m3"));
 +        assertEquals(24l, result.memory().<Long>get("m3").longValue());
 +        assertEquals(2, result.memory().keys().size());  // mapReduceK
 +    }
 +
 +    private static class VertexProgramO extends StaticVertexProgram {
 +
 +        @Override
 +        public void setup(final Memory memory) {
 +            assertFalse(memory.exists("m1"));
 +            assertFalse(memory.exists("m2"));
 +            assertFalse(memory.exists("m3"));
 +        }
 +
 +        @Override
 +        public void execute(final Vertex vertex, final Messenger messenger, final Memory memory) {
 +            if (memory.isInitialIteration()) {
 +                assertFalse(vertex.property("v1").isPresent());
 +                assertFalse(vertex.property("v2").isPresent());
 +                assertFalse(vertex.property("v3").isPresent());
 +                vertex.property("v1", "shouldNotExist");
 +                vertex.property("v2", "shouldNotExist");
 +                vertex.property("v3", "shouldExist");
 +                assertTrue(vertex.property("v1").isPresent());
 +                assertTrue(vertex.property("v2").isPresent());
 +                assertTrue(vertex.property("v3").isPresent());
 +                assertEquals("shouldNotExist", vertex.value("v1"));
 +                assertEquals("shouldNotExist", vertex.value("v2"));
 +                assertEquals("shouldExist", vertex.value("v3"));
 +                //
 +                assertFalse(memory.exists("m1"));
 +                assertFalse(memory.exists("m2"));
 +                assertFalse(memory.exists("m3"));
 +                memory.add("m1", false);
 +                memory.add("m2", true);
 +                memory.add("m3", 2l);
 +                // should still not exist as this pulls from the master memory
 +                assertFalse(memory.exists("m1"));
 +                assertFalse(memory.exists("m2"));
 +                assertFalse(memory.exists("m3"));
 +
 +            } else {
 +                assertTrue(vertex.property("v1").isPresent());
 +                assertTrue(vertex.property("v2").isPresent());
 +                assertTrue(vertex.property("v3").isPresent());
 +                assertEquals("shouldNotExist", vertex.value("v1"));
 +                assertEquals("shouldNotExist", vertex.value("v2"));
 +                assertEquals("shouldExist", vertex.value("v3"));
 +                //
 +                assertTrue(memory.exists("m1"));
 +                assertTrue(memory.exists("m2"));
 +                assertTrue(memory.exists("m3"));
 +                assertFalse(memory.get("m1"));
 +                assertTrue(memory.get("m2"));
 +                assertEquals(12l, memory.<Long>get("m3").longValue());
 +                memory.add("m1", true);
 +                memory.add("m2", true);
 +                memory.add("m3", 2l);
              }
          }
  

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/f1aed80b/tinkergraph-gremlin/src/main/java/org/apache/tinkerpop/gremlin/tinkergraph/process/computer/TinkerMessenger.java
----------------------------------------------------------------------


[3/5] tinkerpop git commit: Merge branch 'tp31' of https://github.com/sheldonkhall/tinkerpop into tp31

Posted by ok...@apache.org.
Merge branch 'tp31' of https://github.com/sheldonkhall/tinkerpop into tp31


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

Branch: refs/heads/tp32
Commit: d67b88b2bee75c68d3c5756a8dbf963f9de2df39
Parents: 3d50f5c 99679a0
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 27 07:53:22 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 27 07:53:22 2017 -0600

----------------------------------------------------------------------
 .../process/computer/GraphComputerTest.java     | 93 ++++++++++++++++++++
 .../process/computer/TinkerMessageBoard.java    |  4 +-
 .../process/computer/TinkerMessenger.java       | 22 +++--
 3 files changed, 109 insertions(+), 10 deletions(-)
----------------------------------------------------------------------



[2/5] tinkerpop git commit: add the regression test

Posted by ok...@apache.org.
add the regression test


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

Branch: refs/heads/tp32
Commit: 99679a037db3e86112471a40cd454114231852b6
Parents: 28c514d
Author: Sheldon <sh...@mindmaps.io>
Authored: Mon Jun 19 10:35:16 2017 +0100
Committer: Sheldon <sh...@mindmaps.io>
Committed: Mon Jun 19 11:20:37 2017 +0100

----------------------------------------------------------------------
 .../process/computer/GraphComputerTest.java     | 93 ++++++++++++++++++++
 1 file changed, 93 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/99679a03/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 1af0830..02ac5d4 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
@@ -24,11 +24,14 @@ import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.computer.util.StaticMapReduce;
 import org.apache.tinkerpop.gremlin.process.computer.util.StaticVertexProgram;
+import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.structure.Direction;
+import org.apache.tinkerpop.gremlin.structure.Element;
 import org.apache.tinkerpop.gremlin.structure.Graph;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
 import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
 import org.junit.Test;
 
 import java.util.ArrayList;
@@ -38,9 +41,11 @@ import java.util.Comparator;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.Set;
 import java.util.concurrent.ConcurrentSkipListSet;
+import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 
 import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.GRATEFUL;
@@ -1463,6 +1468,94 @@ public class GraphComputerTest extends AbstractGremlinProcessTest {
         public void storeState(final Configuration configuration) {
             VertexProgram.super.storeState(configuration);
         }
+    }
+
+    /////////////////////////////////////////////
+    @Test
+    public void shouldSupportMultipleScopes() throws ExecutionException, InterruptedException {
+        Vertex a = graph.addVertex("a");
+        Vertex b = graph.addVertex("b");
+        Vertex c = graph.addVertex("c");
+        a.addEdge("edge", b);
+        b.addEdge("edge", c);
+
+        // Simple graph:
+        // a -> b -> c
+
+        // Execute a traversal program that sends an incoming message of "2" and an outgoing message of "1" from "b"
+        // then each vertex sums any received messages
+        ComputerResult result = graph.compute().program(new MultiScopeVertexProgram()).submit().get();
+
+        // We expect the results to be {a=2, b=0, c=1}. Instead it is {a=3, b=0, c=3}
+        assertEquals((Long) result.graph().traversal().V().hasLabel("a").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(2L));
+        assertEquals((Long) result.graph().traversal().V().hasLabel("b").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(0L));
+        assertEquals((Long) result.graph().traversal().V().hasLabel("c").next().property(MultiScopeVertexProgram.MEMORY_KEY).value(),Long.valueOf(1L));
+    }
+
+    public static class MultiScopeVertexProgram implements VertexProgram<Long> {
+
+        private final MessageScope.Local<Long> countMessageScopeIn = MessageScope.Local.of(__::inE);
+        private final MessageScope.Local<Long> countMessageScopeOut = MessageScope.Local.of(__::outE);
+
+        private static final String MEMORY_KEY = "count";
+
+        private static final Set<String> COMPUTE_KEYS = Collections.singleton(MEMORY_KEY);
+
+        @Override
+        public void setup(final Memory memory) {}
+
+        @Override
+        public GraphComputer.Persist getPreferredPersist() {
+            return GraphComputer.Persist.VERTEX_PROPERTIES;
+        }
+
+        @Override
+        public Set<String> getElementComputeKeys() {
+            return COMPUTE_KEYS;
+        }
+
+        @Override
+        public Set<MessageScope> getMessageScopes(final Memory memory) {
+            HashSet<MessageScope> scopes = new HashSet<>();
+            scopes.add(countMessageScopeIn);
+            scopes.add(countMessageScopeOut);
+            return scopes;
+        }
+
+        @Override
+        public void execute(Vertex vertex, Messenger<Long> messenger, Memory memory) {
+            switch (memory.getIteration()) {
+                case 0:
+                    if (vertex.label().equals("b")) {
+                        messenger.sendMessage(this.countMessageScopeIn, 2L);
+                        messenger.sendMessage(this.countMessageScopeOut, 1L);
+                    }
+                    break;
+                case 1:
+                    long edgeCount = IteratorUtils.reduce(messenger.receiveMessages(), 0L, (a, b) -> a + b);
+                    vertex.property(MEMORY_KEY, edgeCount);
+                    break;
+            }
+        }
+
+        @Override
+        public boolean terminate(final Memory memory) {
+            return memory.getIteration() == 1;
+        }
+
+        @Override
+        public GraphComputer.ResultGraph getPreferredResultGraph() {
+            return GraphComputer.ResultGraph.NEW;
+        }
+
+        @Override
+        public MultiScopeVertexProgram clone() {
+            try {
+                return (MultiScopeVertexProgram) super.clone();
+            } catch (final CloneNotSupportedException e) {
+                throw new RuntimeException(e);
+            }
+        }
 
     }
 


[4/5] tinkerpop git commit: updated CHANGELOG.

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


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

Branch: refs/heads/tp32
Commit: 3b8c62892b3369a2ada0314f33f0b5122a4d6e82
Parents: d67b88b
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Jun 27 07:54:00 2017 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Jun 27 07:54:00 2017 -0600

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


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/3b8c6289/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index d421cb5..5436fd9 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,8 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.1.8 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed a `MessageScope` bug in `TinkerGraphComputer`.
+
 [[release-3-1-7]]
 TinkerPop 3.1.7 (Release Date: June 12, 2017)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~