tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From florianhockm...@apache.org
Subject [30/45] tinkerpop git commit: TINKERPOP-1996 Verification strategy to prevent io() from misuse
Date Tue, 31 Jul 2018 20:19:59 GMT
TINKERPOP-1996 Verification strategy to prevent io() from misuse


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

Branch: refs/heads/TINKERPOP-1774
Commit: e6e4413e46594ae8f6d408de4e3d3bd85c228f53
Parents: ded7c18
Author: Stephen Mallette <spmva@genoprime.com>
Authored: Fri Jul 20 11:47:24 2018 -0400
Committer: Stephen Mallette <spmva@genoprime.com>
Committed: Fri Jul 20 11:47:24 2018 -0400

----------------------------------------------------------------------
 .../strategy/verification/StandardVerificationStrategy.java   | 7 +++++++
 .../verification/StandardVerificationStrategyTest.java        | 5 +++++
 2 files changed, 12 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e4413e/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
index 50faa25..258d345 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategy.java
@@ -23,6 +23,7 @@ import org.apache.tinkerpop.gremlin.process.computer.traversal.strategy.finaliza
 import org.apache.tinkerpop.gremlin.process.traversal.Step;
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
+import org.apache.tinkerpop.gremlin.process.traversal.step.ReadWriting;
 import org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.NoneStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep;
@@ -39,6 +40,7 @@ import java.util.Set;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
  */
 public final class StandardVerificationStrategy extends AbstractTraversalStrategy<TraversalStrategy.VerificationStrategy>
implements TraversalStrategy.VerificationStrategy {
 
@@ -81,6 +83,11 @@ public final class StandardVerificationStrategy extends AbstractTraversalStrateg
         if (TraversalHelper.getStepsOfClass(ProfileSideEffectStep.class, traversal).size()
> 1) {
             throw new VerificationException("The profile()-Step cannot be specified multiple
times.", traversal);
         }
+
+        if (traversal.getStartStep() instanceof ReadWriting && traversal.getSteps().size()
!= 1) {
+            if (TraversalHelper.getStepsOfClass(NoneStep.class, traversal).size() != traversal.getSteps().size()
- 1)
+                throw new VerificationException("The io() step must be the first and only
step in the traversal - it cannot be used with other steps", traversal);
+        }
     }
 
     public static StandardVerificationStrategy instance() {

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/e6e4413e/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategyTest.java
index ee96266..deec002 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/verification/StandardVerificationStrategyTest.java
@@ -24,6 +24,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.decoration.RequirementsStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
+import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -50,7 +51,11 @@ public class StandardVerificationStrategyTest {
                 {"__.repeat(out().fold().unfold()).times(2)", repeat(out().fold().unfold()).times(2),
false},
                 {"__.repeat(sum()).times(2)", repeat(sum()).times(2), false},
                 {"__.repeat(out().count())", repeat(out().count()), false},
+                {"__.io().read().V()", EmptyGraph.instance().traversal().io("junk.kryo").read().V(),
false},
+                {"__.io().write().V()", EmptyGraph.instance().traversal().io("junk.kryo").write().V(),
false},
                 // traversals that should pass verification
+                {"__.io().read().V().none()", EmptyGraph.instance().traversal().io("junk.kryo").read().none(),
true},
+                {"__.io().write().V().none()", EmptyGraph.instance().traversal().io("junk.kryo").write().none(),
true},
                 {"__.V().profile()",
                         __.V().profile(), true},
                 {"__.V().profile('metrics').cap('metrics')",


Mime
View raw message