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/12/08 16:17:10 UTC

incubator-tinkerpop git commit: Fixed a NullPointerException in PeerPressureVertexProgram. PageRankVertexProgram had the null pointer check and PeerPressure did not. Added PeerPressureVertexProgramTest to ProcessComputeSuite. Ingeration tested Spark. CTR

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 6ae06da11 -> b1b405818


Fixed a NullPointerException in PeerPressureVertexProgram. PageRankVertexProgram had the null pointer check and PeerPressure did not. Added PeerPressureVertexProgramTest to ProcessComputeSuite. Ingeration tested Spark. CTR given the simplicity of the fix.


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

Branch: refs/heads/master
Commit: b1b4058180a995fc9f7f465c2ec5ce5948c910dd
Parents: 6ae06da
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Tue Dec 8 08:16:52 2015 -0700
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Tue Dec 8 08:16:52 2015 -0700

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |  1 +
 .../peerpressure/PeerPressureVertexProgram.java |  5 +-
 .../process/GroovyProcessComputerSuite.java     |  5 +-
 .../gremlin/process/ProcessComputerSuite.java   |  4 +-
 .../PeerPressureVertexProgramTest.java          | 63 +++++++++++++++
 .../ranking/PageRankVertexProgramTest.java      | 83 --------------------
 .../pagerank/PageRankVertexProgramTest.java     | 83 ++++++++++++++++++++
 7 files changed, 157 insertions(+), 87 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 72bb132..2bf0df7 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,6 +26,7 @@ image::https://raw.githubusercontent.com/apache/incubator-tinkerpop/master/docs/
 TinkerPop 3.1.1 (NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed a `NullPointerException` bug in `PeerPressureVertexProgram` that occurred when an adjacency traversal was not provided.
 * Fixed a long standing issue around having to use `reduceByKey()` on input data to Spark. It is no longer required.
 * Added `Spark` static object to allow "file system" control of persisted RDDs in Spark.
 * Improved logging control during builds with Maven.

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
index f0e4448..f2989e0 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgram.java
@@ -93,10 +93,11 @@ public class PeerPressureVertexProgram extends StaticVertexProgram<Pair<Serializ
     @Override
     public void storeState(final Configuration configuration) {
         super.storeState(configuration);
-        this.configurationTraversal.storeState(configuration);
         configuration.setProperty(MAX_ITERATIONS, this.maxIterations);
         configuration.setProperty(DISTRIBUTE_VOTE, this.distributeVote);
-
+        if (null != this.configurationTraversal) {
+            this.configurationTraversal.storeState(configuration);
+        }
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
index d07d52f..7187062 100644
--- a/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
+++ b/gremlin-groovy-test/src/main/java/org/apache/tinkerpop/gremlin/process/GroovyProcessComputerSuite.java
@@ -24,7 +24,9 @@ import org.apache.tinkerpop.gremlin.groovy.loaders.SugarLoader;
 import org.apache.tinkerpop.gremlin.groovy.util.SugarTestHelper;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import org.apache.tinkerpop.gremlin.process.computer.bulkloading.BulkLoaderVertexProgramTest;
-import org.apache.tinkerpop.gremlin.process.computer.ranking.PageRankVertexProgramTest;
+import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgram;
+import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgramTest;
+import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgramTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyBranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyChooseTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.GroovyLocalTest;
@@ -168,6 +170,7 @@ public class GroovyProcessComputerSuite extends ProcessComputerSuite {
 
             // algorithms
             PageRankVertexProgramTest.class,
+            PeerPressureVertexProgramTest.class,
             BulkLoaderVertexProgramTest.class,
     };
 

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
index 45ec0ef..76919be 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessComputerSuite.java
@@ -22,7 +22,8 @@ import org.apache.tinkerpop.gremlin.AbstractGremlinSuite;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
 import org.apache.tinkerpop.gremlin.process.computer.GraphComputerTest;
 import org.apache.tinkerpop.gremlin.process.computer.bulkloading.BulkLoaderVertexProgramTest;
-import org.apache.tinkerpop.gremlin.process.computer.ranking.PageRankVertexProgramTest;
+import org.apache.tinkerpop.gremlin.process.computer.clustering.peerpressure.PeerPressureVertexProgramTest;
+import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgramTest;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalEngine;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.BranchTest;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.ChooseTest;
@@ -172,6 +173,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
 
             // algorithms
             PageRankVertexProgramTest.class,
+            PeerPressureVertexProgramTest.class,
             BulkLoaderVertexProgramTest.class,
 
             // strategy

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgramTest.java
new file mode 100644
index 0000000..5d96eaf
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/clustering/peerpressure/PeerPressureVertexProgramTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.process.computer.clustering.peerpressure;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.Test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PeerPressureVertexProgramTest extends AbstractGremlinProcessTest {
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void shouldExecutePeerPressure() throws Exception {
+        if (g.getGraphComputer().get().features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
+            final ComputerResult result = graph.compute(g.getGraphComputer().get().getClass()).program(PeerPressureVertexProgram.build().create(graph)).submit().get();
+            final Set<Object> clusters = new HashSet<>();
+            result.graph().traversal().V().forEachRemaining(v -> {
+                assertEquals(4, v.keys().size()); // name, age/lang, voteStrength, cluster
+                assertTrue(v.keys().contains("name"));
+                assertTrue(v.keys().contains(PeerPressureVertexProgram.VOTE_STRENGTH));
+                assertTrue(v.keys().contains(PeerPressureVertexProgram.CLUSTER));
+                assertEquals(1, IteratorUtils.count(v.values("name")));
+                assertEquals(1, IteratorUtils.count(v.values(PeerPressureVertexProgram.CLUSTER)));
+                final Object cluster = v.value(PeerPressureVertexProgram.CLUSTER);
+                clusters.add(cluster);
+            });
+            assertEquals(2, clusters.size());
+            assertEquals(3, result.memory().getIteration());
+            assertEquals(1, result.memory().asMap().size());
+            assertTrue(result.memory().keys().contains("gremlin.peerPressureVertexProgram.voteToHalt"));  // this is private in PeerPressureVertexProgram (and that is okay)
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/PageRankVertexProgramTest.java
deleted file mode 100644
index c86f875..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/PageRankVertexProgramTest.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * 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.process.computer.ranking;
-
-import org.apache.tinkerpop.gremlin.LoadGraphWith;
-import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
-import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
-import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
-import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram;
-import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import org.junit.Test;
-
-import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author Marko A. Rodriguez (http://markorodriguez.com)
- */
-public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
-
-    @Test
-    @LoadGraphWith(MODERN)
-    public void shouldExecutePageRank() throws Exception {
-        if (g.getGraphComputer().get().features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
-            final ComputerResult result = graph.compute(g.getGraphComputer().get().getClass()).program(PageRankVertexProgram.build().create(graph)).submit().get();
-            result.graph().traversal().V().forEachRemaining(v -> {
-                assertEquals(4, v.keys().size()); // name, age/lang, edgeCount, pageRank
-                assertTrue(v.keys().contains("name"));
-                assertTrue(v.keys().contains(PageRankVertexProgram.EDGE_COUNT));
-                assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
-                assertEquals(1, IteratorUtils.count(v.values("name")));
-                assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
-                final String name = v.value("name");
-                final Double pageRank = v.value(PageRankVertexProgram.PAGE_RANK);
-                //System.out.println(name + "-----" + pageRank);
-                if (name.equals("marko"))
-                    assertTrue(pageRank > 0.14 && pageRank < 0.16);
-                else if (name.equals("vadas"))
-                    assertTrue(pageRank > 0.19 && pageRank < 0.20);
-                else if (name.equals("lop"))
-                    assertTrue(pageRank > 0.40 && pageRank < 0.41);
-                else if (name.equals("josh"))
-                    assertTrue(pageRank > 0.19 && pageRank < 0.20);
-                else if (name.equals("ripple"))
-                    assertTrue(pageRank > 0.23 && pageRank < 0.24);
-                else if (name.equals("peter"))
-                    assertTrue(pageRank > 0.14 && pageRank < 0.16);
-                else
-                    throw new IllegalStateException("The following vertex should not exist in the graph: " + name);
-            });
-            assertEquals(result.memory().getIteration(), 30);
-            assertEquals(result.memory().asMap().size(), 0);
-        }
-    }
-
-    /*@Test
-    @LoadGraphWith(MODERN)
-    public void shouldExecutePageRankWithNormalizedValues() throws Exception {
-        final ComputerResult result = graph.compute().program(PageRankVertexProgram.build().vertexCount(6).create()).submit().get();
-        final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next();
-        System.out.println(sum);
-        assertEquals(1.0d,sum,0.01);
-    }*/
-
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b1b40581/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
new file mode 100644
index 0000000..1e52fd0
--- /dev/null
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/computer/ranking/pagerank/PageRankVertexProgramTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.process.computer.ranking.pagerank;
+
+import org.apache.tinkerpop.gremlin.LoadGraphWith;
+import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
+import org.apache.tinkerpop.gremlin.process.computer.ComputerResult;
+import org.apache.tinkerpop.gremlin.process.computer.GraphComputer;
+import org.apache.tinkerpop.gremlin.process.computer.ranking.pagerank.PageRankVertexProgram;
+import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
+import org.junit.Test;
+
+import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * @author Marko A. Rodriguez (http://markorodriguez.com)
+ */
+public class PageRankVertexProgramTest extends AbstractGremlinProcessTest {
+
+    @Test
+    @LoadGraphWith(MODERN)
+    public void shouldExecutePageRank() throws Exception {
+        if (g.getGraphComputer().get().features().supportsResultGraphPersistCombination(GraphComputer.ResultGraph.NEW, GraphComputer.Persist.VERTEX_PROPERTIES)) {
+            final ComputerResult result = graph.compute(g.getGraphComputer().get().getClass()).program(PageRankVertexProgram.build().create(graph)).submit().get();
+            result.graph().traversal().V().forEachRemaining(v -> {
+                assertEquals(4, v.keys().size()); // name, age/lang, edgeCount, pageRank
+                assertTrue(v.keys().contains("name"));
+                assertTrue(v.keys().contains(PageRankVertexProgram.EDGE_COUNT));
+                assertTrue(v.keys().contains(PageRankVertexProgram.PAGE_RANK));
+                assertEquals(1, IteratorUtils.count(v.values("name")));
+                assertEquals(1, IteratorUtils.count(v.values(PageRankVertexProgram.PAGE_RANK)));
+                final String name = v.value("name");
+                final Double pageRank = v.value(PageRankVertexProgram.PAGE_RANK);
+                //System.out.println(name + "-----" + pageRank);
+                if (name.equals("marko"))
+                    assertTrue(pageRank > 0.14 && pageRank < 0.16);
+                else if (name.equals("vadas"))
+                    assertTrue(pageRank > 0.19 && pageRank < 0.20);
+                else if (name.equals("lop"))
+                    assertTrue(pageRank > 0.40 && pageRank < 0.41);
+                else if (name.equals("josh"))
+                    assertTrue(pageRank > 0.19 && pageRank < 0.20);
+                else if (name.equals("ripple"))
+                    assertTrue(pageRank > 0.23 && pageRank < 0.24);
+                else if (name.equals("peter"))
+                    assertTrue(pageRank > 0.14 && pageRank < 0.16);
+                else
+                    throw new IllegalStateException("The following vertex should not exist in the graph: " + name);
+            });
+            assertEquals(result.memory().getIteration(), 30);
+            assertEquals(result.memory().asMap().size(), 0);
+        }
+    }
+
+    /*@Test
+    @LoadGraphWith(MODERN)
+    public void shouldExecutePageRankWithNormalizedValues() throws Exception {
+        final ComputerResult result = graph.compute().program(PageRankVertexProgram.build().vertexCount(6).create()).submit().get();
+        final double sum = result.graph().traversal().V().values(PageRankVertexProgram.PAGE_RANK).sum().next();
+        System.out.println(sum);
+        assertEquals(1.0d,sum,0.01);
+    }*/
+
+
+}
\ No newline at end of file