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/06/05 22:34:02 UTC

incubator-tinkerpop git commit: added LazyBarrierStrategyTest to ensure that NoOpBarrierSteps are added to the traversal as expected. Already two bugs found :). Added an Override toString() for AbstactStep. CollectingBarrierStep now includes the maxBarri

Repository: incubator-tinkerpop
Updated Branches:
  refs/heads/master 821a0ed1e -> dd3f996c1


added LazyBarrierStrategyTest to ensure that NoOpBarrierSteps are added to the traversal as expected. Already two bugs found :). Added an Override toString() for AbstactStep. CollectingBarrierStep now includes the maxBarrierSize in its toString().


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

Branch: refs/heads/master
Commit: dd3f996c1f55307adf32efd26d6df417c5e1aea9
Parents: 821a0ed
Author: Marko A. Rodriguez <ok...@gmail.com>
Authored: Fri Jun 5 14:33:14 2015 -0600
Committer: Marko A. Rodriguez <ok...@gmail.com>
Committed: Fri Jun 5 14:33:40 2015 -0600

----------------------------------------------------------------------
 .../traversal/step/util/AbstractStep.java       |   1 +
 .../step/util/CollectingBarrierStep.java        |   6 ++
 .../finalization/LazyBarrierStrategy.java       |  12 ++-
 .../finalization/LazyBarrierStrategyTest.java   | 103 +++++++++++++++++++
 4 files changed, 120 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dd3f996c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
index ec14512..066133a 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/AbstractStep.java
@@ -152,6 +152,7 @@ public abstract class AbstractStep<S, E> implements Step<S, E> {
 
     protected abstract Traverser<E> processNextStart() throws NoSuchElementException;
 
+    @Override
     public String toString() {
         return StringFactory.stepString(this);
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dd3f996c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
index e8227d6..6a45fa5 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/util/CollectingBarrierStep.java
@@ -22,6 +22,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
 import org.apache.tinkerpop.gremlin.process.traversal.traverser.util.TraverserSet;
+import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
 
 import java.util.Collections;
 import java.util.Set;
@@ -76,6 +77,11 @@ public abstract class CollectingBarrierStep<S> extends AbstractStep<S, S> {
     }
 
     @Override
+    public String toString() {
+        return StringFactory.stepString(this, this.maxBarrierSize);
+    }
+
+    @Override
     public void reset() {
         super.reset();
         this.traverserSet.clear();

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dd3f996c/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategy.java
index 62f4274..ecd172e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategy.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategy.java
@@ -26,6 +26,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
 import org.apache.tinkerpop.gremlin.process.traversal.TraversalStrategy;
 import org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder;
 import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.EdgeVertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.GraphStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.CollectingBarrierStep;
@@ -50,7 +51,7 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
 
     private static final int REQUIRED_DEPTH = 2;
     private static final int BIG_START_SIZE = 5;
-    private static final int MAX_BARRIER_SIZE = 10000;
+    protected static final int MAX_BARRIER_SIZE = 10000;
 
     static {
         PRIORS.add(ScopingStrategy.class);
@@ -78,11 +79,13 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
 
         if (depth > REQUIRED_DEPTH) {
             boolean bigStart = false;
+            char foundVertexStep = 'x';
             for (int i = 0; i < traversal.getSteps().size() - 1; i++) {
                 final Step<?, ?> step = traversal.getSteps().get(i);
                 if (i == 0)
                     bigStart = step instanceof GraphStep && (((GraphStep) step).getIds().length >= BIG_START_SIZE || (((GraphStep) step).getIds().length == 0 && step instanceof HasContainerHolder && ((HasContainerHolder) step).getHasContainers().isEmpty()));
-                else if (i > 1 || bigStart) {
+
+                if ('v' == foundVertexStep || bigStart) {
                     if (!(step instanceof FilterStep) &&
                             !(step instanceof CollectingBarrierStep) &&
                             !(step instanceof SupplyingBarrierStep) &&
@@ -91,6 +94,11 @@ public final class LazyBarrierStrategy extends AbstractTraversalStrategy<Travers
                         TraversalHelper.insertAfterStep(new NoOpBarrierStep<>(traversal, MAX_BARRIER_SIZE), step, traversal);
                     }
                 }
+
+                if ('x' == foundVertexStep && step instanceof VertexStep)
+                    foundVertexStep = ((VertexStep) step).returnsVertex() ? 'v' : 'e';
+                else if ('e' == foundVertexStep && step instanceof EdgeVertexStep)
+                    foundVertexStep = 'v';
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/dd3f996c/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategyTest.java b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategyTest.java
new file mode 100644
index 0000000..e8b0705
--- /dev/null
+++ b/gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/strategy/finalization/LazyBarrierStrategyTest.java
@@ -0,0 +1,103 @@
+/*
+ *
+ *  * 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.traversal.strategy.finalization;
+
+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.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 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)
+public class LazyBarrierStrategyTest {
+
+    @RunWith(Parameterized.class)
+    public static class StandardTest extends AbstractLazyBarrierStrategyTest {
+
+        @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.STANDARD);
+        }
+
+        @Test
+        public void shouldApplyStrategy() {
+            doTest(original, optimized);
+        }
+    }
+
+    private static abstract class AbstractLazyBarrierStrategyTest {
+
+        protected TraversalEngine traversalEngine;
+
+        void applyAdjacentToIncidentStrategy(final Traversal traversal) {
+            final TraversalStrategies strategies = new DefaultTraversalStrategies();
+            strategies.addStrategies(LazyBarrierStrategy.instance());
+
+            traversal.asAdmin().setStrategies(strategies);
+            traversal.asAdmin().setEngine(this.traversalEngine);
+            traversal.asAdmin().applyStrategies();
+        }
+
+        public void doTest(final Traversal traversal, final Traversal optimized) {
+            applyAdjacentToIncidentStrategy(traversal);
+            assertEquals(optimized.toString(), traversal.toString());
+        }
+
+        static Iterable<Object[]> generateTestParameters() {
+            final int size = LazyBarrierStrategy.MAX_BARRIER_SIZE;
+            return Arrays.asList(new Traversal[][]{
+                    {__.out().count(), __.out().count()},
+                    {__.out().out().count(), __.out().out().count()},
+                    {__.out().out().out().count(), __.out().out().barrier(size).out().barrier(size).count()},
+                    {__.outE().inV().outE().inV().outE().inV().groupCount(), __.outE().inV().outE().inV().barrier(size).outE().inV().barrier(size).groupCount()},
+                    {__.out().out().has("age", 32).out().count(), __.out().out().barrier(size).has("age", 32).out().barrier(size).count()},
+            });
+        }
+    }
+
+}