tinkerpop-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From spmalle...@apache.org
Subject [05/50] tinkerpop git commit: Added lots more tests to various strategies. The inline aspect of MatchPredicateStrategy was moved to InlineFilterStrategy. In migrating that chunk, fixed a strategy application bug that was present in MatchPredicateStrategy
Date Thu, 29 Sep 2016 20:09:44 GMT
Added lots more tests to various strategies. The inline aspect of MatchPredicateStrategy was
moved to InlineFilterStrategy. In migrating that chunk, fixed a strategy application bug that
was present in MatchPredicateStrategy. Tweaked up various XXXStrategyTest in the new model
where extra strategies can be provded in the parameters.


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

Branch: refs/heads/TINKERPOP-1458
Commit: 36f3adda8c1e36b82a3ca36bb9dbfeea574340cf
Parents: 26035e6
Author: Marko A. Rodriguez <okrammarko@gmail.com>
Authored: Tue Sep 27 08:27:02 2016 -0600
Committer: Marko A. Rodriguez <okrammarko@gmail.com>
Committed: Tue Sep 27 12:45:49 2016 -0600

----------------------------------------------------------------------
 CHANGELOG.asciidoc                              |   4 +-
 .../optimization/InlineFilterStrategy.java      |  58 ++++++++-
 .../optimization/MatchPredicateStrategy.java    |  49 +-------
 .../process/traversal/util/TraversalHelper.java |  12 +-
 .../optimization/FilterRankingStrategyTest.java |  44 ++++---
 .../optimization/InlineFilterStrategyTest.java  |  32 +++--
 .../MatchPredicateStrategyTest.java             | 119 ++++++-------------
 7 files changed, 147 insertions(+), 171 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index 70b2a76..499046e 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -26,12 +26,14 @@ image::https://raw.githubusercontent.com/apache/tinkerpop/master/docs/static/ima
 TinkerPop 3.2.3 (Release Date: NOT OFFICIALLY RELEASED YET)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+* Fixed a end-step label bug in `MatchPredicateStrategy`.
+* Fixed a bug in `MatchPredicateStrategy` where inlined traversals did not have strategies
applied to it.
 * Fixed a bug in `RepeatUnrollStrategy` where inlined traversal did not have strategies applied
to it.
 * `TinkerGraphStepStrategy` is now smart about non-`HasContainer` filter steps.
 * Added `TraversalHelper.copyLabels()` for copying (or moving) labels form one step to another.
 * Added `TraversalHelper.applySingleLevelStrategies()` which will apply a subset of strategies
but not walk the child tree.
 * Added the concept that hidden labels using during traversal compilation are removed at
the end during `StandardVerificationStrategy`. (*breaking*)
-* Added `InlineFilterStrategy` which will determine if a `TraversalFilterStep` or `AndStep`
children are filters and if so, inline them.
+* Added `InlineFilterStrategy` which will determine if a `TraversalFilterStep`, `AndStep`,
`MatchStep` children are filters and if so, inline them.
 * Removed `IdentityRemovalStrategy` from the default listing as its not worth the clock cycles.
 * Removed the "!" symbol in `NotStep.toString()` as it is confusing and the `NotStep`-name
is sufficient.
 * Fixed a bug in `TraversalVertexProgram` (OLAP) around ordering and connectives (i.e. `and()`
and `or()`).

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
index ba2f832..cbc7748 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategy.java
@@ -25,10 +25,14 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.AndStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.TraversalFilterStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.List;
@@ -45,12 +49,14 @@ import java.util.Set;
  * __.filter(has("name","marko"))                                // is replaced by __.has("name","marko")
  * __.and(has("name"),has("age"))                                // is replaced by __.has("name").has("age")
  * __.and(filter(has("name","marko").has("age")),hasNot("blah")) // is replaced by __.has("name","marko").has("age").hasNot("blah")
+ * __.match(as('a').has(key,value),...)                          // is replaced by __.as('a').has(key,value).match(...)
  * </pre>
  */
 public final class InlineFilterStrategy extends AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy>
implements TraversalStrategy.OptimizationStrategy {
 
     private static final InlineFilterStrategy INSTANCE = new InlineFilterStrategy();
     private static final Set<Class<? extends OptimizationStrategy>> POSTS = new
HashSet<>(Arrays.asList(
+            MatchPredicateStrategy.class,
             FilterRankingStrategy.class,
             GraphFilterStrategy.class));
 
@@ -62,9 +68,10 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
         boolean changed = true; // recursively walk child traversals trying to inline them
into the current traversal line.
         while (changed) {
             changed = false;
-            for (final TraversalFilterStep<?> step : TraversalHelper.getStepsOfAssignableClass(TraversalFilterStep.class,
traversal)) {
+            // filter(x.y) --> x.y
+            for (final TraversalFilterStep<?> step : TraversalHelper.getStepsOfClass(TraversalFilterStep.class,
traversal)) {
                 final Traversal.Admin<?, ?> childTraversal = step.getLocalChildren().get(0);
-                if (TraversalHelper.allStepsInstanceOf(childTraversal, FilterStep.class,
true)) {
+                if (TraversalHelper.allStepsInstanceOf(childTraversal, FilterStep.class))
{
                     changed = true;
                     TraversalHelper.applySingleLevelStrategies(traversal, childTraversal,
InlineFilterStrategy.class);
                     final Step<?, ?> finalStep = childTraversal.getEndStep();
@@ -73,8 +80,9 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
                     traversal.removeStep(step);
                 }
             }
-            for (final AndStep<?> step : TraversalHelper.getStepsOfAssignableClass(AndStep.class,
traversal)) {
-                if (!step.getLocalChildren().stream().filter(t -> !TraversalHelper.allStepsInstanceOf(t,
FilterStep.class, true)).findAny().isPresent()) {
+            // and(x,y) --> x.y
+            for (final AndStep<?> step : TraversalHelper.getStepsOfClass(AndStep.class,
traversal)) {
+                if (!step.getLocalChildren().stream().filter(t -> !TraversalHelper.allStepsInstanceOf(t,
FilterStep.class)).findAny().isPresent()) {
                     changed = true;
                     final List<Traversal.Admin<?, ?>> childTraversals = (List)
step.getLocalChildren();
                     Step<?, ?> finalStep = null;
@@ -90,7 +98,49 @@ public final class InlineFilterStrategy extends AbstractTraversalStrategy<Traver
                     traversal.removeStep(step);
                 }
             }
+            // match(as('a').has(key,value),...) --> as('a').has(key,value).match(...)
+            if (traversal.getParent() instanceof EmptyStep) {
+                for (final MatchStep<?, ?> step : TraversalHelper.getStepsOfClass(MatchStep.class,
traversal)) {
+                    final String startLabel = determineStartLabelForHasPullOut(step);
+                    if (null != startLabel) {
+                        for (final Traversal.Admin<?, ?> matchTraversal : new ArrayList<>(step.getGlobalChildren()))
{
+                            if (!(step.getPreviousStep() instanceof EmptyStep) &&
+                                    TraversalHelper.allStepsInstanceOf(matchTraversal,
+                                            HasStep.class,
+                                            MatchStep.MatchStartStep.class,
+                                            MatchStep.MatchEndStep.class) &&
+                                    matchTraversal.getStartStep() instanceof MatchStep.MatchStartStep
&&
+                                    startLabel.equals(((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().orElse(null)))
{
+                                changed = true;
+                                final String endLabel = ((MatchStep.MatchEndStep) matchTraversal.getEndStep()).getMatchKey().orElse(null);
// why would this exist? but just in case
+                                matchTraversal.removeStep(0);                           
           // remove MatchStartStep
+                                matchTraversal.removeStep(matchTraversal.getSteps().size()
- 1);    // remove MatchEndStep
+                                TraversalHelper.applySingleLevelStrategies(traversal, matchTraversal,
InlineFilterStrategy.class);
+                                step.removeGlobalChild(matchTraversal);
+                                step.getPreviousStep().addLabel(startLabel);
+                                if (null != endLabel) matchTraversal.getEndStep().addLabel(endLabel);
+                                TraversalHelper.insertTraversal((Step) step.getPreviousStep(),
matchTraversal, traversal);
+                            }
+                        }
+                        if (step.getGlobalChildren().isEmpty())
+                            traversal.removeStep(step);
+                    }
+                }
+            }
+        }
+    }
+
+    private static final String determineStartLabelForHasPullOut(final MatchStep<?, ?>
matchStep) {
+        final String startLabel = MatchStep.Helper.computeStartLabel(matchStep.getGlobalChildren());
+        Step<?, ?> previousStep = matchStep.getPreviousStep();
+        if (previousStep.getLabels().contains(startLabel))
+            return startLabel;
+        while (!(previousStep instanceof EmptyStep)) {
+            if (!previousStep.getLabels().isEmpty())
+                return null;
+            previousStep = previousStep.getPreviousStep();
         }
+        return startLabel;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategy.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategy.java
index f025749..a93dcd9 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategy.java
@@ -22,20 +22,18 @@ 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.filter.DedupGlobalStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WherePredicateStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.WhereTraversalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.MatchStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectOneStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.SelectStep;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.EmptyStep;
 import org.apache.tinkerpop.gremlin.process.traversal.strategy.AbstractTraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversal;
 import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
 
+import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
-import java.util.stream.Collectors;
 
 /**
  * MatchWhereStrategy will fold any post-{@code where()} step that maintains a traversal
constraint into
@@ -53,11 +51,7 @@ import java.util.stream.Collectors;
 public final class MatchPredicateStrategy extends AbstractTraversalStrategy<TraversalStrategy.OptimizationStrategy>
implements TraversalStrategy.OptimizationStrategy {
 
     private static final MatchPredicateStrategy INSTANCE = new MatchPredicateStrategy();
-    private static final Set<Class<? extends OptimizationStrategy>> PRIORS =
new HashSet<>();
-
-    static {
-        PRIORS.add(IdentityRemovalStrategy.class);
-    }
+    private static final Set<Class<? extends OptimizationStrategy>> PRIORS =
new HashSet<>(Arrays.asList(IdentityRemovalStrategy.class, InlineFilterStrategy.class));
 
     private MatchPredicateStrategy() {
     }
@@ -89,48 +83,9 @@ public final class MatchPredicateStrategy extends AbstractTraversalStrategy<Trav
                 } else
                     break;
             }
-            // match(as('a').has(key,value),...) --> as('a').has(key,value).match(...)
-            final String startLabel = this.determineStartLabelForHasPullOut(matchStep);
-            if (null != startLabel) {
-                ((MatchStep<?, ?>) matchStep).getGlobalChildren().stream().collect(Collectors.toList()).forEach(matchTraversal
-> {
-                    if (matchTraversal.getStartStep() instanceof MatchStep.MatchStartStep
&&
-                            ((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().isPresent()
&&
-                            ((MatchStep.MatchStartStep) matchTraversal.getStartStep()).getSelectKey().get().equals(startLabel)
&&
-                            !(matchStep.getPreviousStep() instanceof EmptyStep) &&
-                            !matchTraversal.getSteps().stream()
-                                    .filter(step -> !(step instanceof MatchStep.MatchStartStep)
&&
-                                            !(step instanceof MatchStep.MatchEndStep) &&
-                                            !(step instanceof HasStep))
-                                    .findAny()
-                                    .isPresent()) {
-                        matchStep.removeGlobalChild(matchTraversal);
-                        matchTraversal.removeStep(0);                                   
   // remove MatchStartStep
-                        matchTraversal.removeStep(matchTraversal.getSteps().size() - 1);
   // remove MatchEndStep
-                        matchStep.getPreviousStep().addLabel(startLabel);
-                        TraversalHelper.insertTraversal(matchStep.getPreviousStep(), matchTraversal,
traversal);
-                    }
-                });
-            }
         });
     }
 
-    private String determineStartLabelForHasPullOut(final MatchStep<?, ?> matchStep)
{
-        if (!(matchStep.getTraversal().getParent() instanceof EmptyStep))
-            return null;
-        else {
-            final String startLabel = MatchStep.Helper.computeStartLabel(matchStep.getGlobalChildren());
-            Step<?, ?> previousStep = matchStep.getPreviousStep();
-            if (previousStep.getLabels().contains(startLabel))
-                return startLabel;
-            while (!(previousStep instanceof EmptyStep)) {
-                if (!previousStep.getLabels().isEmpty())
-                    return null;
-                previousStep = previousStep.getPreviousStep();
-            }
-            return startLabel;
-        }
-    }
-
     public static MatchPredicateStrategy instance() {
         return INSTANCE;
     }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
index 7564741..d38ac6e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/util/TraversalHelper.java
@@ -579,10 +579,16 @@ public final class TraversalHelper {
         }
     }
 
-    public static boolean allStepsInstanceOf(final Traversal.Admin<?, ?> traversal,
final Class<?> classToCheck, boolean checkIsInstanceOf) {
+    public static boolean allStepsInstanceOf(final Traversal.Admin<?, ?> traversal,
final Class<?>... classesToCheck) {
         for (final Step step : traversal.getSteps()) {
-            boolean isInstance = classToCheck.isInstance(step);
-            if ((isInstance && !checkIsInstanceOf) || (!isInstance && checkIsInstanceOf))
+            boolean foundInstance = false;
+            for (final Class<?> classToCheck : classesToCheck) {
+                if (classToCheck.isInstance(step)) {
+                    foundInstance = true;
+                    break;
+                }
+            }
+            if (!foundInstance)
                 return false;
         }
         return true;

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyTest.java
index 2a57185..71f5b4b 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/FilterRankingStrategyTest.java
@@ -20,6 +20,7 @@ package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
 
 import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
 import org.junit.Test;
@@ -27,6 +28,8 @@ import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 
 import static org.junit.Assert.assertEquals;
 
@@ -47,33 +50,36 @@ public class FilterRankingStrategyTest {
     @Parameterized.Parameter(value = 1)
     public Traversal optimized;
 
-
-    void applyFilterRankingStrategy(final Traversal traversal) {
-        final TraversalStrategies strategies = new DefaultTraversalStrategies();
-        strategies.addStrategies(FilterRankingStrategy.instance(), IdentityRemovalStrategy.instance());
-        traversal.asAdmin().setStrategies(strategies);
-        traversal.asAdmin().applyStrategies();
-    }
+    @Parameterized.Parameter(value = 2)
+    public Collection<TraversalStrategy> otherStrategies;
 
     @Test
     public void doTest() {
-        applyFilterRankingStrategy(original);
-        assertEquals(optimized, original);
+        final TraversalStrategies strategies = new DefaultTraversalStrategies();
+        strategies.addStrategies(FilterRankingStrategy.instance());
+        for (final TraversalStrategy strategy : this.otherStrategies) {
+            strategies.addStrategies(strategy);
+        }
+        this.original.asAdmin().setStrategies(strategies);
+        this.original.asAdmin().applyStrategies();
+        assertEquals(this.optimized, this.original);
     }
 
     @Parameterized.Parameters(name = "{0}")
     public static Iterable<Object[]> generateTestParameters() {
 
-        return Arrays.asList(new Traversal[][]{
-                {__.dedup().order(), __.dedup().order()},
-                {__.order().dedup(), __.dedup().order()},
-                {__.identity().order().dedup(), __.dedup().order()},
-                {__.order().identity().dedup(), __.dedup().order()},
-                {__.order().out().dedup(), __.order().out().dedup()},
-                {__.has("value", 0).filter(__.out()).dedup(), __.has("value", 0).filter(__.out()).dedup()},
-                {__.dedup().filter(__.out()).has("value", 0), __.has("value", 0).filter(__.out()).dedup()},
-                {__.filter(__.out()).dedup().has("value", 0), __.has("value", 0).filter(__.out()).dedup()},
-                {__.has("value", 0).filter(__.out()).dedup(), __.has("value", 0).filter(__.out()).dedup()},
+        return Arrays.asList(new Object[][]{
+                {__.dedup().order(), __.dedup().order(), Collections.emptyList()},
+                {__.order().dedup(), __.dedup().order(), Collections.emptyList()},
+                {__.order().as("a").dedup(), __.order().as("a").dedup(), Collections.emptyList()},
+                {__.identity().order().dedup(), __.dedup().order(), Collections.singletonList(IdentityRemovalStrategy.instance())},
+                {__.order().identity().dedup(), __.dedup().order(), Collections.singletonList(IdentityRemovalStrategy.instance())},
+                {__.order().out().dedup(), __.order().out().dedup(), Collections.emptyList()},
+                {__.has("value", 0).filter(__.out()).dedup(), __.has("value", 0).filter(__.out()).dedup(),
Collections.emptyList()},
+                {__.dedup().filter(__.out()).has("value", 0), __.has("value", 0).filter(__.out()).dedup(),
Collections.emptyList()},
+                {__.filter(__.out()).dedup().has("value", 0), __.has("value", 0).filter(__.out()).dedup(),
Collections.emptyList()},
+                {__.has("value", 0).filter(__.out()).dedup(), __.has("value", 0).filter(__.out()).dedup(),
Collections.emptyList()},
+                {__.has("value", 0).and(__.has("age"), __.has("name", "marko")).is(10), __.is(10).has("value",
0).has("name", "marko").has("age"), Collections.singletonList(InlineFilterStrategy.instance())},
         });
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
index b77ecc2..e9e605a 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/InlineFilterStrategyTest.java
@@ -29,9 +29,13 @@ import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
 
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.V;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.and;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.filter;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.has;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.map;
+import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.match;
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.out;
 import static org.junit.Assert.assertEquals;
 
@@ -47,18 +51,13 @@ public class InlineFilterStrategyTest {
     @Parameterized.Parameter(value = 1)
     public Traversal optimized;
 
-
-    void applyInlineFilterStrategy(final Traversal traversal) {
-        final TraversalStrategies strategies = new DefaultTraversalStrategies();
-        strategies.addStrategies(InlineFilterStrategy.instance());
-        traversal.asAdmin().setStrategies(strategies);
-        traversal.asAdmin().applyStrategies();
-    }
-
     @Test
     public void doTest() {
-        applyInlineFilterStrategy(original);
-        assertEquals(optimized, original);
+        final TraversalStrategies strategies = new DefaultTraversalStrategies();
+        strategies.addStrategies(InlineFilterStrategy.instance());
+        this.original.asAdmin().setStrategies(strategies);
+        this.original.asAdmin().applyStrategies();
+        assertEquals(this.optimized, this.original);
     }
 
     @Parameterized.Parameters(name = "{0}")
@@ -67,12 +66,19 @@ public class InlineFilterStrategyTest {
         return Arrays.asList(new Traversal[][]{
                 {filter(out("knows")), filter(out("knows"))},
                 {filter(has("age", P.gt(10))).as("a"), has("age", P.gt(10)).as("a")},
-                {filter(has("age", P.gt(10)).as("b")).as("a"), has("age", P.gt(10)).as("b","a")},
+                {filter(has("age", P.gt(10)).as("b")).as("a"), has("age", P.gt(10)).as("b",
"a")},
                 {filter(has("age", P.gt(10))), has("age", P.gt(10))},
                 {filter(and(has("age", P.gt(10)), has("name", "marko"))), has("age", P.gt(10)).has("name",
"marko")},
+                //
                 {and(has("age", P.gt(10)), filter(has("age", 22))), has("age", P.gt(10)).has("age",
22)},
-                {and(has("age", P.gt(10)).as("a"), and(filter(has("age", 22).as("b")).as("c"),
has("name", "marko").as("d"))), has("age", P.gt(10)).as("a").has("age", 22).as("b","c").has("name",
"marko").as("d")},
-                {and(has("age", P.gt(10)), and(out("knows"), has("name", "marko"))), has("age",
P.gt(10)).and(out("knows"), has("name", "marko"))}
+                {and(has("age", P.gt(10)).as("a"), and(filter(has("age", 22).as("b")).as("c"),
has("name", "marko").as("d"))), has("age", P.gt(10)).as("a").has("age", 22).as("b", "c").has("name",
"marko").as("d")},
+                {and(has("age", P.gt(10)), and(out("knows"), has("name", "marko"))), has("age",
P.gt(10)).and(out("knows"), has("name", "marko"))},
+                //
+                {V().match(as("a").has("age", 10), as("a").filter(has("name")).as("b")),
V().as("a").has("age", 10).match(as("a").has("name").as("b"))},
+                {match(as("a").has("age", 10), as("a").filter(has("name")).as("b")), match(as("a").has("age",
10), as("a").has("name").as("b"))},
+                {map(match(as("a").has("age", 10), as("a").filter(has("name")).as("b"))),
map(match(as("a").has("age", 10), as("a").has("name").as("b")))},
+                {V().match(as("a").has("age", 10)), V().as("a").has("age", 10)},
+                {V().match(as("a").has("age", 10).as("b"), as("a").filter(has("name")).as("b")),
V().as("a").has("age", 10).as("b").match(as("a").has("name").as("b"))},
         });
     }
 }

http://git-wip-us.apache.org/repos/asf/tinkerpop/blob/36f3adda/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategyTest.java
b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategyTest.java
index 41d3525..509004c 100644
--- a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategyTest.java
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/optimization/MatchPredicateStrategyTest.java
@@ -20,113 +20,64 @@ package org.apache.tinkerpop.gremlin.process.traversal.strategy.optimization;
 
 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.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
 import org.apache.tinkerpop.gremlin.process.traversal.util.DefaultTraversalStrategies;
-import org.junit.Before;
 import org.junit.Test;
-import org.junit.experimental.runners.Enclosed;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
 
 import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
 
 import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.as;
 import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 /**
  * @author Marko A. Rodriguez (http://markorodriguez.com)
  */
-@RunWith(Enclosed.class)
+@RunWith(Parameterized.class)
 public class MatchPredicateStrategyTest {
 
-    @RunWith(Parameterized.class)
-    public static class StandardTest extends AbstractMatchPredicateStrategyTest {
+    @Parameterized.Parameter(value = 0)
+    public Traversal original;
 
-        @Parameterized.Parameters(name = "{0}")
-        public static Iterable<Object[]> data() {
-            return generateTestParameters();
-        }
-
-        @Parameterized.Parameter(value = 0)
-        public Traversal original;
-
-        @Parameterized.Parameter(value = 1)
-        public Traversal optimized;
+    @Parameterized.Parameter(value = 1)
+    public Traversal optimized;
 
-        @Before
-        public void setup() {
-            this.traversalEngine = mock(TraversalEngine.class);
-            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
-        }
+    @Parameterized.Parameter(value = 2)
+    public Collection<TraversalStrategy> otherStrategies;
 
-        @Test
-        public void shouldApplyStrategy() {
-            doTest(original, optimized);
+    @Test
+    public void doTest() {
+        final TraversalStrategies strategies = new DefaultTraversalStrategies();
+        strategies.addStrategies(MatchPredicateStrategy.instance());
+        for (final TraversalStrategy strategy : this.otherStrategies) {
+            strategies.addStrategies(strategy);
         }
+        this.original.asAdmin().setStrategies(strategies);
+        this.original.asAdmin().applyStrategies();
+        assertEquals(this.optimized, this.original);
     }
 
-    @RunWith(Parameterized.class)
-    public static class ComputerTest extends AbstractMatchPredicateStrategyTest {
-
-        @Parameterized.Parameters(name = "{0}")
-        public static Iterable<Object[]> data() {
-            return generateTestParameters();
-        }
-
-        @Parameterized.Parameter(value = 0)
-        public Traversal original;
-
-        @Parameterized.Parameter(value = 1)
-        public Traversal optimized;
-
-        @Before
-        public void setup() {
-            this.traversalEngine = mock(TraversalEngine.class);
-            when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
-        }
-
-        @Test
-        public void shouldApplyStrategy() {
-            doTest(original, optimized);
-        }
+    @Parameterized.Parameters(name = "{0}")
+    public static Iterable<Object[]> generateTestParameters() {
+
+        return Arrays.asList(new Object[][]{
+                {__.out().match(as("a").has("name", "marko"), as("a").out().as("b")), __.out().as("a").has("name",
"marko").match(as("a").out().as("b")), Collections.singletonList(InlineFilterStrategy.instance())},
// has() pull out
+                {__.out().as("a").match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("a").has("name", "marko").match(as("a").out().as("b")), Collections.singletonList(InlineFilterStrategy.instance())},
// has() pull out
+                {__.out().as("a").out().match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("a").out().match(as("a").has("name", "marko"), as("a").out().as("b")), Collections.emptyList()},
// no has() pull out
+                {__.map(__.match(as("a").has("name", "marko"), as("a").out().as("b"))), __.map(__.match(as("a").has("name",
"marko"), as("a").out().as("b"))), Collections.emptyList()}, // no has() pull out
+                {__.out().as("c").match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("c").match(as("a").has("name", "marko"), as("a").out().as("b")), Collections.emptyList()},
// no has() pull out
+                /////////
+                {__.match(as("a").out().as("b"), __.where(as("b").out("knows").as("c"))),
__.match(as("a").out().as("b"), as("b").where(__.out("knows").as("c"))), Collections.emptyList()},
// make as().where()
+                {__.match(as("a").out().as("b"), __.where("a", P.gt("b"))), __.match(as("a").out().as("b"),
__.as("a").where(P.gt("b"))), Collections.emptyList()},  // make as().where()
+                /////////
+                // {__.match(as("a").out().as("b")).where(as("b").out("knows").as("c")),
__.match(as("a").out().as("b"), as("b").where(__.out("knows").as("c"))), Collections.emptyList()},
// make as().where()
+                // {__.match(as("a").out().as("b")).where("a", P.gt("b")), __.match(as("a").out().as("b"),
__.as("a").where(P.gt("b"))), Collections.emptyList()},  // make as().where()
+        });
     }
 
-    private static abstract class AbstractMatchPredicateStrategyTest {
-
-        protected TraversalEngine traversalEngine;
-
-        void applyMatchWhereStrategy(final Traversal traversal) {
-            final TraversalStrategies strategies = new DefaultTraversalStrategies();
-            strategies.addStrategies(MatchPredicateStrategy.instance(), IdentityRemovalStrategy.instance());
-            traversal.asAdmin().setStrategies(strategies);
-            //traversal.asAdmin().setEngine(this.traversalEngine);
-            traversal.asAdmin().applyStrategies();
-        }
-
-        public void doTest(final Traversal traversal, final Traversal optimized) {
-            applyMatchWhereStrategy(traversal);
-            assertEquals(optimized, traversal);
-        }
-
-        static Iterable<Object[]> generateTestParameters() {
-
-            return Arrays.asList(new Traversal[][]{
-                    {__.out().match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("a").has("name", "marko").match(as("a").out().as("b"))}, // has() pull out
-                    {__.out().as("a").match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("a").has("name", "marko").match(as("a").out().as("b"))}, // has() pull out
-                    {__.out().as("a").out().match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("a").out().match(as("a").has("name", "marko"), as("a").out().as("b"))}, // no
has() pull out
-                    {__.map(__.match(as("a").has("name", "marko"), as("a").out().as("b"))),
__.map(__.match(as("a").has("name", "marko"), as("a").out().as("b")))}, // no has() pull out
-                    {__.out().as("c").match(as("a").has("name", "marko"), as("a").out().as("b")),
__.out().as("c").match(as("a").has("name", "marko"), as("a").out().as("b"))}, // no has()
pull out
-                    /////////
-                    {__.match(as("a").out().as("b"), __.where(as("b").out("knows").as("c"))),
__.match(as("a").out().as("b"), as("b").where(__.out("knows").as("c")))}, // make as().where()
-                    {__.match(as("a").out().as("b"), __.where("a", P.gt("b"))), __.match(as("a").out().as("b"),
__.as("a").where(P.gt("b")))},  // make as().where()
-                    /////////
-                    //{__.match(as("a").out().as("b")).where(as("b").out("knows").as("c")),
__.match(as("a").out().as("b"), as("b").where(__.out("knows").as("c")))}, // make as().where()
-                    //{__.match(as("a").out().as("b")).where("a", P.gt("b")), __.match(as("a").out().as("b"),
__.as("a").where(P.gt("b")))},  // make as().where()
-            });
-        }
-    }
 }


Mime
View raw message