You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by sp...@apache.org on 2015/02/17 15:40:27 UTC
[1/5] incubator-tinkerpop git commit: Change pom parent from sonatype
to apache.
Repository: incubator-tinkerpop
Updated Branches:
refs/heads/master deb8921e4 -> b7c5a5e2f
Change pom parent from sonatype to apache.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/b2dceb19
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/b2dceb19
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/b2dceb19
Branch: refs/heads/master
Commit: b2dceb190fcde59e8c003d4caa7b476c0064a007
Parents: 2b918f7
Author: Stephen Mallette <sp...@apache.org>
Authored: Mon Feb 16 09:23:12 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Mon Feb 16 09:23:12 2015 -0500
----------------------------------------------------------------------
pom.xml | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b2dceb19/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 2d1f39d..6fb8acd 100644
--- a/pom.xml
+++ b/pom.xml
@@ -19,9 +19,9 @@ limitations under the License.
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
- <groupId>org.sonatype.oss</groupId>
- <artifactId>oss-parent</artifactId>
- <version>7</version>
+ <groupId>org.apache</groupId>
+ <artifactId>apache</artifactId>
+ <version>16</version>
</parent>
<groupId>org.apache.tinkerpop</groupId>
<artifactId>tinkerpop</artifactId>
[3/5] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/master'
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/460338c6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/460338c6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/460338c6
Branch: refs/heads/master
Commit: 460338c66235537cb86d64c58ca87c2bb453ff97
Parents: a2ad8fb deb8921
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Feb 17 08:08:38 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Feb 17 08:08:38 2015 -0500
----------------------------------------------------------------------
docs/src/the-graphcomputer.asciidoc | 16 +-
docs/src/the-traversal.asciidoc | 4 +
docs/static/images/grateful-dead-schema.png | Bin 0 -> 65600 bytes
docs/static/images/tinkerpop3.graffle | 699 +++++++++++++++++--
.../gremlin/process/computer/GraphComputer.java | 4 +
.../computer/traversal/TraversalSupplier.java | 10 +-
.../traversal/TraversalVertexProgram.java | 9 +-
.../traversal/step/map/ComputerResultStep.java | 3 +-
.../mapreduce/TraverserMapReduce.java | 4 +-
.../process/computer/util/LambdaHolder.java | 6 +
.../traversal/step/map/RangeLocalStep.java | 46 +-
.../traversal/step/map/SampleLocalStep.java | 76 +-
.../sideEffect/mapreduce/GroupMapReduce.java | 6 +
.../traversal/lambda/IdentityTraversal.java | 4 +-
.../gremlin/groovy/loaders/SugarLoader.groovy | 22 +
.../structure/ExceptionCoverageTest.java | 1 +
hadoop-gremlin/conf/hadoop-kryo.properties | 2 +-
.../computer/giraph/GiraphGraphComputer.java | 42 +-
.../process/computer/TinkerGraphComputer.java | 1 -
.../tinkergraph/structure/TinkerGraphTest.java | 20 +-
20 files changed, 850 insertions(+), 125 deletions(-)
----------------------------------------------------------------------
[5/5] incubator-tinkerpop git commit: Update changelog.
Posted by sp...@apache.org.
Update changelog.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/b7c5a5e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/b7c5a5e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/b7c5a5e2
Branch: refs/heads/master
Commit: b7c5a5e2f42ceb5f5db4df83378ce73edbc77993
Parents: 89c6f21
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Feb 17 09:40:08 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Feb 17 09:40:08 2015 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/b7c5a5e2/CHANGELOG.asciidoc
----------------------------------------------------------------------
diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc
index eab30ce..e39cf6a 100644
--- a/CHANGELOG.asciidoc
+++ b/CHANGELOG.asciidoc
@@ -27,6 +27,7 @@ TinkerPop 3.0.0.M8 (Release Date: NOT OFFICIALLY RELEASED YET)
* Added `hasNot(traversal)` which is a faster way of doing `has(traversal.count().is(0L))`.
* `TraversalStrategy.apply(traversal)` is the new method signature as the `TraversalEngine` can be retrieved from the `Traversal`.
+* Added `TimeLimitedStrategy` which injects a `TimeLimit` step at the end of every `Traversal`.
* `TraversalEngine` is now an interface and provided to the traversal by the graph. `Graph` methods added to set the desired traversal engine to use.
* Added `count(local)`, `sum(local)`, `max(local)`, `min(local)`, `mean(local)`, `dedup(local)`, `sample(local)` and `range(local)` for operating on the local object (e.g. collection, map, etc.).
* `TraversalComparator` exists which allows for `order().by(outE().count(),decr)`.
[2/5] incubator-tinkerpop git commit: Merge remote-tracking branch
'origin/master'
Posted by sp...@apache.org.
Merge remote-tracking branch 'origin/master'
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/a2ad8fb1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/a2ad8fb1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/a2ad8fb1
Branch: refs/heads/master
Commit: a2ad8fb1acf9bd0044b84736867b4b8f9a5fc2b1
Parents: b2dceb1 6640db0
Author: Stephen Mallette <sp...@apache.org>
Authored: Mon Feb 16 12:41:31 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Mon Feb 16 12:41:31 2015 -0500
----------------------------------------------------------------------
CHANGELOG.asciidoc | 1 +
.../graph/traversal/ElementTraversal.java | 4 +
.../process/graph/traversal/GraphTraversal.java | 123 +++----------------
.../gremlin/process/graph/traversal/__.java | 4 +
.../traversal/step/filter/HasTraversalStep.java | 11 +-
.../step/filter/GroovyHasNotTest.groovy | 14 ++-
.../graph/traversal/step/filter/HasNotTest.java | 30 +++--
7 files changed, 60 insertions(+), 127 deletions(-)
----------------------------------------------------------------------
[4/5] incubator-tinkerpop git commit: Add TimeLimitedStrategy and
refactored pattern for testing TraversalStrategy.
Posted by sp...@apache.org.
Add TimeLimitedStrategy and refactored pattern for testing TraversalStrategy.
Project: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/commit/89c6f212
Tree: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/tree/89c6f212
Diff: http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/diff/89c6f212
Branch: refs/heads/master
Commit: 89c6f21209a075bf7e69a01618b709c6bcc27ce0
Parents: 460338c
Author: Stephen Mallette <sp...@apache.org>
Authored: Tue Feb 17 09:38:45 2015 -0500
Committer: Stephen Mallette <sp...@apache.org>
Committed: Tue Feb 17 09:38:45 2015 -0500
----------------------------------------------------------------------
.../traversal/strategy/TimeLimitedStrategy.java | 30 ++++
.../gremlin/process/ProcessComputerSuite.java | 7 +-
.../gremlin/process/ProcessStandardSuite.java | 7 +-
.../strategy/RangeByIsCountStrategyTest.java | 136 ---------------
.../strategy/RangeByIsCountStrategyTest.java | 168 +++++++++++++++++++
.../strategy/TimeLimitedStrategyTest.java | 60 +++++++
6 files changed, 262 insertions(+), 146 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategy.java
----------------------------------------------------------------------
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategy.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategy.java
new file mode 100644
index 0000000..7dbc1ba
--- /dev/null
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategy.java
@@ -0,0 +1,30 @@
+package org.apache.tinkerpop.gremlin.process.graph.traversal.strategy;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.TimeLimitStep;
+
+/**
+ * A {@link org.apache.tinkerpop.gremlin.process.TraversalStrategy} that prevents a traversal from running beyond
+ * a pre-configured time.
+ *
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class TimeLimitedStrategy extends AbstractTraversalStrategy {
+ private final long timeLimit;
+
+ public TimeLimitedStrategy(final long timeLimit) {
+ this.timeLimit = timeLimit;
+ }
+
+ public long getTimeLimit() {
+ return timeLimit;
+ }
+
+ @Override
+ public void apply(final Traversal.Admin<?, ?> traversal) {
+ if (traversal.getEndStep().getClass().equals(TimeLimitStep.class))
+ return;
+
+ traversal.addStep(new TimeLimitStep<>(traversal, timeLimit));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/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 42f07f9..a67f64b 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
@@ -26,7 +26,6 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.step.branch.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.*;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.RangeByIsCountStrategyTest;
import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.TraversalVerificationStrategyTest;
import org.junit.runners.model.InitializationError;
import org.junit.runners.model.RunnerBuilder;
@@ -136,8 +135,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
ComputerDataStrategyTest.class,
// strategy
- TraversalVerificationStrategyTest.ComputerTest.class,
- RangeByIsCountStrategyTest.ComputerTest.class
+ TraversalVerificationStrategyTest.ComputerTest.class
};
/**
@@ -212,8 +210,7 @@ public class ProcessComputerSuite extends AbstractGremlinSuite {
// strategy
ComputerDataStrategyTest.class,
- TraversalVerificationStrategyTest.class,
- RangeByIsCountStrategyTest.class
+ TraversalVerificationStrategyTest.class
};
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
index 197fc89..7445196 100644
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
+++ b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/ProcessStandardSuite.java
@@ -24,7 +24,6 @@ import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.map.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.sideEffect.*;
import org.apache.tinkerpop.gremlin.process.graph.traversal.step.util.TraversalSideEffectsTest;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.RangeByIsCountStrategyTest;
import org.apache.tinkerpop.gremlin.process.graph.traversal.strategy.TraversalVerificationStrategyTest;
import org.apache.tinkerpop.gremlin.process.traversal.CoreTraversalTest;
import org.apache.tinkerpop.gremlin.process.util.PathTest;
@@ -133,8 +132,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
PathTest.class,
// strategy
- TraversalVerificationStrategyTest.StandardTest.class,
- RangeByIsCountStrategyTest.StandardTest.class
+ TraversalVerificationStrategyTest.StandardTest.class
// algorithms
// PageRankVertexProgramTest.class
@@ -211,8 +209,7 @@ public class ProcessStandardSuite extends AbstractGremlinSuite {
// PageRankVertexProgramTest.class
// strategy
- TraversalVerificationStrategyTest.class,
- RangeByIsCountStrategyTest.class
+ TraversalVerificationStrategyTest.class
};
/**
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java b/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
deleted file mode 100644
index 61cc09d..0000000
--- a/gremlin-test/src/main/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
+++ /dev/null
@@ -1,136 +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.graph.traversal.strategy;
-
-import org.apache.tinkerpop.gremlin.LoadGraphWith;
-import org.apache.tinkerpop.gremlin.process.AbstractGremlinProcessTest;
-import org.apache.tinkerpop.gremlin.process.Traversal;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.HasTraversalStep;
-import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.RangeGlobalStep;
-import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
-import org.apache.tinkerpop.gremlin.structure.Compare;
-import org.apache.tinkerpop.gremlin.structure.Contains;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.concurrent.atomic.AtomicInteger;
-import java.util.function.BiPredicate;
-
-import static org.apache.tinkerpop.gremlin.LoadGraphWith.GraphData.MODERN;
-import static org.junit.Assert.assertEquals;
-
-/**
- * @author Daniel Kuppitz (http://gremlin.guru)
- */
-public abstract class RangeByIsCountStrategyTest extends AbstractGremlinProcessTest {
-
- public static class StandardTest extends RangeByIsCountStrategyTest {
-
- private void runTest(final BiPredicate predicate, final Object value, final long expectedHighRange) {
- final AtomicInteger counter = new AtomicInteger(0);
- Traversal traversal = g.V().count().is(predicate, value);
- traversal.iterate();
- TraversalHelper.getStepsOfClass(RangeGlobalStep.class, traversal.asAdmin()).stream().forEach(step -> {
- assertEquals(0, step.getLowRange());
- assertEquals(expectedHighRange, step.getHighRange());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.get());
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countEqualsNullShouldLimitToOne() {
- runTest(Compare.eq, 0l, 1l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countNotEqualsFourShouldLimitToFive() {
- runTest(Compare.neq, 4l, 5l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countLessThanOrEqualThreeShouldLimitToFour() {
- runTest(Compare.lte, 3l, 4l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countLessThanThreeShouldLimitToThree() {
- runTest(Compare.lt, 3l, 3l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countGreaterThanTwoShouldLimitToThree() {
- runTest(Compare.gt, 2l, 3l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countGreaterThanOrEqualTwoShouldLimitToTwo() {
- runTest(Compare.gte, 2l, 2l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countInsideTwoAndFourShouldLimitToFour() {
- runTest(Compare.inside, Arrays.asList(2l, 4l), 4l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countOutsideTwoAndFourShouldLimitToFive() {
- runTest(Compare.outside, Arrays.asList(2l, 4l), 5l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countWithinTwoSixFourShouldLimitToSeven() {
- runTest(Contains.within, Arrays.asList(2l, 6l, 4l), 7l);
- }
-
- @Test
- @LoadGraphWith(MODERN)
- public void countWithoutTwoSixFourShouldLimitToSix() {
- runTest(Contains.without, Arrays.asList(2l, 6l, 4l), 6l);
- }
- }
-
- public static class ComputerTest extends RangeByIsCountStrategyTest {
- @Test
- @LoadGraphWith(MODERN)
- public void nestedCountEqualsNullShouldLimitToOne() {
- final AtomicInteger counter = new AtomicInteger(0);
- final Traversal traversal = g.V().has(__.outE("created").count().is(0)).iterate();
- final HasTraversalStep hasStep = TraversalHelper.getStepsOfClass(HasTraversalStep.class, traversal.asAdmin()).stream().findFirst().get();
- final Traversal nestedTraversal = (Traversal) hasStep.getLocalChildren().get(0);
- TraversalHelper.getStepsOfClass(RangeGlobalStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
- assertEquals(0, step.getLowRange());
- assertEquals(1, step.getHighRange());
- counter.incrementAndGet();
- });
- assertEquals(1, counter.get());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
new file mode 100644
index 0000000..1ec2c6f
--- /dev/null
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/RangeByIsCountStrategyTest.java
@@ -0,0 +1,168 @@
+package org.apache.tinkerpop.gremlin.process.graph.traversal.strategy;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.TraversalEngine;
+import org.apache.tinkerpop.gremlin.process.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.HasTraversalStep;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.RangeGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.apache.tinkerpop.gremlin.structure.Compare;
+import org.apache.tinkerpop.gremlin.structure.Contains;
+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.List;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.BiPredicate;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.*;
+
+/**
+ * @author Daniel Kuppitz (http://gremlin.guru)
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+@RunWith(Enclosed.class)
+public class RangeByIsCountStrategyTest {
+
+ @RunWith(Parameterized.class)
+ public static class StandardTest extends AbstractRangeByIsCountStrategyTest {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> data() {
+ return generateTestParameters();
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public String name;
+
+ @Parameterized.Parameter(value = 1)
+ public BiPredicate predicate;
+
+ @Parameterized.Parameter(value = 2)
+ public Object value;
+
+ @Parameterized.Parameter(value = 3)
+ public long expectedHighRange;
+
+ @Before
+ public void setup() {
+ this.traversalEngine = mock(TraversalEngine.class);
+ when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.STANDARD);
+ }
+
+ @Test
+ public void shouldApplyStrategy() {
+ doTest(predicate, value, expectedHighRange);
+ }
+ }
+
+ @RunWith(Parameterized.class)
+ public static class ComputerTest extends AbstractRangeByIsCountStrategyTest {
+
+ @Parameterized.Parameters(name = "{0}")
+ public static Iterable<Object[]> data() {
+ return generateTestParameters();
+ }
+
+ @Parameterized.Parameter(value = 0)
+ public String name;
+
+ @Parameterized.Parameter(value = 1)
+ public BiPredicate predicate;
+
+ @Parameterized.Parameter(value = 2)
+ public Object value;
+
+ @Parameterized.Parameter(value = 3)
+ public long expectedHighRange;
+
+ @Before
+ public void setup() {
+ this.traversalEngine = mock(TraversalEngine.class);
+ when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
+ }
+
+ @Test
+ public void shouldApplyStrategy() {
+ doTest(predicate, value, expectedHighRange);
+ }
+ }
+
+ public static class SpecificComputerTest extends AbstractRangeByIsCountStrategyTest {
+
+ @Before
+ public void setup() {
+ this.traversalEngine = mock(TraversalEngine.class);
+ when(this.traversalEngine.getType()).thenReturn(TraversalEngine.Type.COMPUTER);
+ }
+
+ @Test
+ public void nestedCountEqualsNullShouldLimitToOne() {
+ final AtomicInteger counter = new AtomicInteger(0);
+ final Traversal traversal = __.out().has(__.outE("created").count().is(0));
+ applyRangeByIsCountStrategy(traversal);
+
+ final HasTraversalStep hasStep = TraversalHelper.getStepsOfClass(HasTraversalStep.class, traversal.asAdmin()).stream().findFirst().get();
+ final Traversal nestedTraversal = (Traversal) hasStep.getLocalChildren().get(0);
+ TraversalHelper.getStepsOfClass(RangeGlobalStep.class, nestedTraversal.asAdmin()).stream().forEach(step -> {
+ assertEquals(0, step.getLowRange());
+ assertEquals(1, step.getHighRange());
+ counter.incrementAndGet();
+ });
+ assertEquals(1, counter.get());
+ }
+ }
+
+ private static abstract class AbstractRangeByIsCountStrategyTest {
+
+ protected TraversalEngine traversalEngine;
+
+ void applyRangeByIsCountStrategy(final Traversal traversal) {
+ final TraversalStrategies strategies = new DefaultTraversalStrategies();
+ strategies.addStrategies(RangeByIsCountStrategy.instance());
+
+ traversal.asAdmin().setStrategies(strategies);
+ traversal.asAdmin().applyStrategies();
+ traversal.asAdmin().setEngine(traversalEngine);
+ }
+
+ public void doTest(final BiPredicate predicate, final Object value, final long expectedHighRange) {
+ final AtomicInteger counter = new AtomicInteger(0);
+ final Traversal traversal = __.out().count().is(predicate, value);
+ applyRangeByIsCountStrategy(traversal);
+
+ final List<RangeGlobalStep> steps = TraversalHelper.getStepsOfClass(RangeGlobalStep.class, traversal.asAdmin());
+ assertEquals(1, steps.size());
+
+ steps.forEach(step -> {
+ assertEquals(0, step.getLowRange());
+ assertEquals(expectedHighRange, step.getHighRange());
+ counter.incrementAndGet();
+ });
+
+ assertEquals(1, counter.intValue());
+ }
+
+ static Iterable<Object[]> generateTestParameters() {
+
+ return Arrays.asList(new Object[][]{
+ {"countEqualsNullShouldLimitToOne", Compare.eq, 0l, 1l},
+ {"countNotEqualsFourShouldLimitToFive", Compare.neq, 4l, 5l},
+ {"countLessThanOrEqualThreeShouldLimitToFour", Compare.lte, 3l, 4l},
+ {"countLessThanThreeShouldLimitToThree", Compare.lt, 3l, 3l},
+ {"countGreaterThanTwoShouldLimitToThree", Compare.gt, 2l, 3l},
+ {"countGreaterThanOrEqualTwoShouldLimitToTwo", Compare.gte, 2l, 2l},
+ {"countInsideTwoAndFourShouldLimitToFour", Compare.inside, Arrays.asList(2l, 4l), 4l},
+ {"countOutsideTwoAndFourShouldLimitToFive", Compare.outside, Arrays.asList(2l, 4l), 5l},
+ {"countWithinTwoSixFourShouldLimitToSeven", Contains.within, Arrays.asList(2l, 6l, 4l), 7l},
+ {"countWithoutTwoSixFourShouldLimitToSix", Contains.without, Arrays.asList(2l, 6l, 4l), 6l}});
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-tinkerpop/blob/89c6f212/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
----------------------------------------------------------------------
diff --git a/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
new file mode 100644
index 0000000..f9d16c0
--- /dev/null
+++ b/gremlin-test/src/test/java/org/apache/tinkerpop/gremlin/process/graph/traversal/strategy/TimeLimitedStrategyTest.java
@@ -0,0 +1,60 @@
+package org.apache.tinkerpop.gremlin.process.graph.traversal.strategy;
+
+import org.apache.tinkerpop.gremlin.process.Traversal;
+import org.apache.tinkerpop.gremlin.process.TraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.__;
+import org.apache.tinkerpop.gremlin.process.graph.traversal.step.filter.TimeLimitStep;
+import org.apache.tinkerpop.gremlin.process.traversal.DefaultTraversalStrategies;
+import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class TimeLimitedStrategyTest {
+
+ @Test
+ public void shouldAddTimeLimitStepIfNotPresent() {
+ final Traversal t = __.out();
+
+ final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
+ final TraversalStrategies strategies = new DefaultTraversalStrategies();
+ strategies.addStrategies(s);
+ t.asAdmin().setStrategies(strategies);
+
+ t.asAdmin().applyStrategies();
+
+ assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
+ }
+
+ @Test
+ public void shouldNotAddTimeLimitStepIfAlreadyPresentAtEnd() {
+ final Traversal t = __.out().timeLimit(100);
+
+ final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
+ final TraversalStrategies strategies = new DefaultTraversalStrategies();
+ strategies.addStrategies(s);
+ t.asAdmin().setStrategies(strategies);
+
+ t.asAdmin().applyStrategies();
+
+ assertEquals(1, TraversalHelper.getStepsOfAssignableClass(TimeLimitStep.class, t.asAdmin()).stream().count());
+ assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
+ }
+
+ @Test
+ public void shouldAddTimeLimitStepIfAlreadyPresentInMiddle() {
+ final Traversal t = __.out().timeLimit(100).out();
+
+ final TimeLimitedStrategy s = new TimeLimitedStrategy(100);
+ final TraversalStrategies strategies = new DefaultTraversalStrategies();
+ strategies.addStrategies(s);
+ t.asAdmin().setStrategies(strategies);
+
+ t.asAdmin().applyStrategies();
+
+ assertEquals(TimeLimitStep.class, t.asAdmin().getEndStep().getClass());
+ }
+}