Repository: tinkerpop
Updated Branches:
  refs/heads/TINKERPOP-1539 e01aa721f -> c68b2154d


added two complex tests; one for OLTP only, one for OLTP and OLAP


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

Branch: refs/heads/TINKERPOP-1539
Commit: c68b2154ddc83b5e11686a11588585e238ec2985
Parents: e01aa72
Author: Daniel Kuppitz <daniel_kupp...@hotmail.com>
Authored: Thu Dec 1 22:13:59 2016 +0100
Committer: Daniel Kuppitz <daniel_kupp...@hotmail.com>
Committed: Thu Dec 1 22:13:59 2016 +0100

----------------------------------------------------------------------
 .../process/traversal/step/ComplexTest.java     | 103 ++++++++++++++++++-
 1 file changed, 102 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/c68b2154/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/ComplexTest.java
----------------------------------------------------------------------
diff --git 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/ComplexTest.java
 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/ComplexTest.java
index a33276f..bbb6781 100644
--- 
a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/ComplexTest.java
+++ 
b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/ComplexTest.java
@@ -22,9 +22,11 @@ package org.apache.tinkerpop.gremlin.process.traversal.step;
 import org.apache.tinkerpop.gremlin.LoadGraphWith;
 import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
 import org.apache.tinkerpop.gremlin.process.GremlinProcessRunner;
+import org.apache.tinkerpop.gremlin.process.IgnoreEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.Order;
 import org.apache.tinkerpop.gremlin.process.traversal.P;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.BulkSet;
 import org.apache.tinkerpop.gremlin.structure.Column;
 import org.apache.tinkerpop.gremlin.structure.Vertex;
@@ -33,21 +35,80 @@ import org.junit.runner.RunWith;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collection;
 import java.util.List;
 import java.util.Map;
 
+import static java.util.Collections.emptySet;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.eq;
+import static org.apache.tinkerpop.gremlin.process.traversal.P.neq;
+import static org.apache.tinkerpop.gremlin.process.traversal.Scope.local;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.constant;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.count;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.group;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.in;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.outE;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.project;
 import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.unfold;
+import static 
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.values;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Daniel Kuppitz (http://gremlin.guru)
  */
 @RunWith(GremlinProcessRunner.class)
 public abstract class ComplexTest extends AbstractGremlinProcessTest {
 
+    /**
+     * Checks the result of both coworkerSummary tests, which is expected to 
look as follows:
+     * <p>
+     * marko={peter={numCoCreated=1, coCreated=[lop]}, josh={numCoCreated=1, 
coCreated=[lop]}}
+     * josh={peter={numCoCreated=1, coCreated=[lop]}, marko={numCoCreated=1, 
coCreated=[lop]}}
+     * peter={josh={numCoCreated=1, coCreated=[lop]}, marko={numCoCreated=1, 
coCreated=[lop]}}
+     */
+    private static void checkCoworkerSummary(final Map<String, Map<String, 
Map<String, Object>>> summary) {
+        assertNotNull(summary);
+        assertEquals(3, summary.size());
+        assertTrue(summary.containsKey("marko"));
+        assertTrue(summary.containsKey("josh"));
+        assertTrue(summary.containsKey("peter"));
+        for (final Map.Entry<String, Map<String, Map<String, Object>>> entry : 
summary.entrySet()) {
+            assertEquals(2, entry.getValue().size());
+            switch (entry.getKey()) {
+                case "marko":
+                    assertTrue(entry.getValue().containsKey("josh") && 
entry.getValue().containsKey("peter"));
+                    break;
+                case "josh":
+                    assertTrue(entry.getValue().containsKey("peter") && 
entry.getValue().containsKey("marko"));
+                    break;
+                case "peter":
+                    assertTrue(entry.getValue().containsKey("marko") && 
entry.getValue().containsKey("josh"));
+                    break;
+            }
+            for (final Map<String, Object> m : entry.getValue().values()) {
+                assertTrue(m.containsKey("numCoCreated"));
+                assertTrue(m.containsKey("coCreated"));
+                assertTrue(m.get("numCoCreated") instanceof Number);
+                assertTrue(m.get("coCreated") instanceof Collection);
+                assertEquals(1, ((Number) m.get("numCoCreated")).intValue());
+                assertEquals(1, ((Collection) m.get("coCreated")).size());
+                assertEquals("lop", ((Collection) 
m.get("coCreated")).iterator().next());
+            }
+        }
+    }
+
     public abstract Traversal<Vertex, String> getClassicRecommendation();
 
+    public abstract Traversal<Vertex, Map<String, Map<String, Map<String, 
Object>>>> getCoworkerSummary();
+
+    public abstract Traversal<Vertex, Map<String, Map<String, Map<String, 
Object>>>> getCoworkerSummaryOLTP();
+
     @Test
     @LoadGraphWith(LoadGraphWith.GraphData.GRATEFUL)
     public void classicRecommendation() {
@@ -81,12 +142,33 @@ public abstract class ComplexTest extends 
AbstractGremlinProcessTest {
 
     }
 
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    public void coworkerSummary() {
+        final Traversal<Vertex, Map<String, Map<String, Map<String, Object>>>> 
traversal = getCoworkerSummary();
+        printTraversalForm(traversal);
+        assertTrue(traversal.hasNext());
+        checkCoworkerSummary(traversal.next());
+        assertFalse(traversal.hasNext());
+    }
+
+    @Test
+    @LoadGraphWith(LoadGraphWith.GraphData.MODERN)
+    @IgnoreEngine(TraversalEngine.Type.COMPUTER) // no mid-traversal V() in 
computer mode + star-graph limitations
+    public void coworkerSummaryOLTP() {
+        final Traversal<Vertex, Map<String, Map<String, Map<String, Object>>>> 
traversal = getCoworkerSummaryOLTP();
+        printTraversalForm(traversal);
+        assertTrue(traversal.hasNext());
+        checkCoworkerSummary(traversal.next());
+        assertFalse(traversal.hasNext());
+    }
+
     public static class Traversals extends ComplexTest {
 
         @Override
         public Traversal<Vertex, String> getClassicRecommendation() {
             return g.V().has("name", "DARK 
STAR").as("a").out("followedBy").aggregate("stash").
-                    
in("followedBy").where(P.neq("a").and(P.not(P.within("stash")))).
+                    
in("followedBy").where(neq("a").and(P.not(P.within("stash")))).
                     groupCount().
                     unfold().
                     project("x", "y", "z").
@@ -99,6 +181,25 @@ public abstract class ComplexTest extends 
AbstractGremlinProcessTest {
                     limit(5).store("m").select("x");
         }
 
+        @Override
+        public Traversal<Vertex, Map<String, Map<String, Map<String, 
Object>>>> getCoworkerSummary() {
+            return 
g.V().hasLabel("person").filter(outE("created")).aggregate("p").as("p1").values("name").as("p1n")
+                    
.select("p").unfold().where(neq("p1")).as("p2").values("name").as("p2n").select("p2")
+                    .out("created").choose(in("created").where(eq("p1")), 
values("name"), constant(emptySet()))
+                    .<String, Map<String, Map<String, 
Object>>>group().by(select("p1n")).
+                            by(group().by(select("p2n")).
+                                    by(unfold().fold().project("numCoCreated", 
"coCreated").by(count(local)).by()));
+        }
+
+        @Override
+        public Traversal<Vertex, Map<String, Map<String, Map<String, 
Object>>>> getCoworkerSummaryOLTP() {
+            return g.V().hasLabel("person").filter(outE("created")).as("p1")
+                    
.V().hasLabel("person").where(neq("p1")).filter(outE("created")).as("p2")
+                    
.map(out("created").where(in("created").as("p1")).values("name").fold())
+                    .<String, Map<String, Map<String, 
Object>>>group().by(select("p1").by("name")).
+                            by(group().by(select("p2").by("name")).
+                                    by(project("numCoCreated", 
"coCreated").by(count(local)).by()));
+        }
     }
 }
 

Reply via email to