Repository: tinkerpop Updated Branches: refs/heads/TINKERPOP-1405 [created] 226d83e90
TINKERPOP-1405 Fixed a small bug in StandardVerificationStrategy that caused verification to fail when withPath was used in conjunction with ProfileStep. Project: http://git-wip-us.apache.org/repos/asf/tinkerpop/repo Commit: http://git-wip-us.apache.org/repos/asf/tinkerpop/commit/226d83e9 Tree: http://git-wip-us.apache.org/repos/asf/tinkerpop/tree/226d83e9 Diff: http://git-wip-us.apache.org/repos/asf/tinkerpop/diff/226d83e9 Branch: refs/heads/TINKERPOP-1405 Commit: 226d83e903dc16f5d6da644d7069bb1b54c3878b Parents: 9542419 Author: Ted Wilmes <[email protected]> Authored: Tue Aug 16 08:04:28 2016 -0500 Committer: Ted Wilmes <[email protected]> Committed: Tue Aug 16 08:04:28 2016 -0500 ---------------------------------------------------------------------- CHANGELOG.asciidoc | 1 + .../StandardVerificationStrategy.java | 12 ++++-- .../StandardVerificationStrategyTest.java | 41 +++++++++++++++----- 3 files changed, 41 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/226d83e9/CHANGELOG.asciidoc ---------------------------------------------------------------------- diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index bff6907..ac364b1 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -33,6 +33,7 @@ TinkerPop 3.2.2 (NOT OFFICIALLY RELEASED YET) * Added methods to retrieve `Cluster` settings in `gremlin-driver`. * Fixed a severe bug in `SubgraphStrategy`. * Deprecated `SubgraphStrategy.Builder.vertexCriterion()/edgeCriterion()` in favor of `vertices()/edges()`. +* Fixed a small bug in `StandardVerificationStrategy` that caused verification to fail when `withPath` was used in conjunction with `ProfileStep`. [[release-3-2-1]] TinkerPop 3.2.1 (Release Date: July 18, 2016) http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/226d83e9/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 4fc7da2..8582b5c 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 @@ -25,6 +25,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.ProfileSideEffectStep; import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.SideEffectCapStep; import org.apache.tinkerpop.gremlin.process.traversal.step.util.ReducingBarrierStep; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.RequirementsStep; import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy; import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper; @@ -53,11 +54,16 @@ public final class StandardVerificationStrategy extends AbstractTraversalStrateg throw new VerificationException("The parent of a reducing barrier can not be repeat()-step: " + step, traversal); }); - // The ProfileSideEffectStep must be the last step or the 2nd last step when accompanied by the cap step. + // The ProfileSideEffectStep must be the last step, 2nd last step when accompanied by the cap step, + // or 3rd to last when the traversal ends with a RequirementsStep. if (TraversalHelper.hasStepOfClass(ProfileSideEffectStep.class, traversal) && !(traversal.asAdmin().getEndStep() instanceof ProfileSideEffectStep) && - !(traversal.asAdmin().getEndStep() instanceof SideEffectCapStep && traversal.asAdmin().getEndStep().getPreviousStep() instanceof ProfileSideEffectStep)) { - throw new VerificationException("When specified, the profile()-Step must be the last step or followed only by the cap()-step.", traversal); + (!(traversal.asAdmin().getEndStep() instanceof SideEffectCapStep + && traversal.asAdmin().getEndStep().getPreviousStep() instanceof ProfileSideEffectStep) && + (!(traversal.asAdmin().getEndStep() instanceof RequirementsStep + && (traversal.asAdmin().getEndStep().getPreviousStep() instanceof SideEffectCapStep || + traversal.asAdmin().getEndStep().getPreviousStep() instanceof ProfileSideEffectStep))))) { + throw new VerificationException("When specified, the profile()-Step must be the last step or followed only by the cap()-step and/or requirements step.", traversal); } if (TraversalHelper.getStepsOfClass(ProfileSideEffectStep.class, traversal).size() > 1) { http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/226d83e9/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 2d80de4..aa64f68 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 @@ -20,13 +20,17 @@ package org.apache.tinkerpop.gremlin.process.traversal.strategy.verification; import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__; +import org.apache.tinkerpop.gremlin.process.traversal.step.util.RequirementsStep; import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import java.util.Arrays; +import java.util.Collections; +import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.__; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.repeat; import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.sum; @@ -39,11 +43,20 @@ import static org.junit.Assert.fail; @RunWith(Parameterized.class) public class StandardVerificationStrategyTest { + private static final RequirementsStep emptyRequirementStep = new RequirementsStep<>(null, Collections.EMPTY_SET); + @Parameterized.Parameters(name = "{0}") public static Iterable<Object[]> data() { return Arrays.asList(new Object[][]{ - {"__.repeat(out().fold().unfold()).times(2)", repeat(out().fold().unfold()).times(2)}, - {"__.repeat(sum()).times(2)", repeat(sum()).times(2)}, + // traversals that should fail verification + {"__.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}, + // traversals that should pass verification + {"__.V().profile().requirementsStep()", + __.V().profile().asAdmin().addStep(emptyRequirementStep), true}, + {"__.V().profile('metrics').cap('metrics').requirementsStep()", + __.V().profile("metrics").asAdmin().addStep(emptyRequirementStep), true} }); } @@ -53,16 +66,24 @@ public class StandardVerificationStrategyTest { @Parameterized.Parameter(value = 1) public Traversal traversal; + @Parameterized.Parameter(value = 2) + public Boolean legalTraversal; + @Test - public void shouldBeVerifiedIllegal() { - try { - final TraversalStrategies strategies = new DefaultTraversalStrategies(); - strategies.addStrategies(StandardVerificationStrategy.instance()); - traversal.asAdmin().setStrategies(strategies); + public void shouldBeVerified() { + final TraversalStrategies strategies = new DefaultTraversalStrategies(); + strategies.addStrategies(StandardVerificationStrategy.instance()); + traversal.asAdmin().setStrategies(strategies); + + if (legalTraversal) { traversal.asAdmin().applyStrategies(); - fail("The strategy should not allow traversal: " + this.traversal); - } catch (IllegalStateException ise) { - assertTrue(true); + } else { + try { + traversal.asAdmin().applyStrategies(); + fail("The strategy should not allow traversal: " + this.traversal); + } catch (IllegalStateException ise) { + assertTrue(true); + } } } }
