You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tinkerpop.apache.org by co...@apache.org on 2025/09/05 22:22:19 UTC
(tinkerpop) 10/19: Added more tests.
This is an automated email from the ASF dual-hosted git repository.
colegreer pushed a commit to branch repeatLimit
in repository https://gitbox.apache.org/repos/asf/tinkerpop.git
commit 25ce55657de2746878ce74b7aa37acc04f5ce3d7
Author: Andrea Child <an...@improving.com>
AuthorDate: Fri Aug 29 23:10:26 2025 -0700
Added more tests.
---
.../process/traversal/step/branch/RepeatStep.java | 48 +++++-----------------
.../traversal/step/filter/RangeGlobalStep.java | 8 +---
.../tinkergraph/structure/TinkerGraphPlayTest.java | 32 +++++++++++++--
3 files changed, 39 insertions(+), 49 deletions(-)
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
index 644aa9f7e6..ed26d2634e 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/branch/RepeatStep.java
@@ -18,25 +18,23 @@
*/
package org.apache.tinkerpop.gremlin.process.traversal.step.branch;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.Set;
import org.apache.tinkerpop.gremlin.process.traversal.Step;
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
import org.apache.tinkerpop.gremlin.process.traversal.Traverser;
import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
-import org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep;
import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.util.ComputerAwareStep;
import org.apache.tinkerpop.gremlin.process.traversal.traverser.TraverserRequirement;
import org.apache.tinkerpop.gremlin.process.traversal.util.TraversalUtil;
-import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.util.StringFactory;
import org.apache.tinkerpop.gremlin.util.iterator.IteratorUtils;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
/**
* @author Marko A. Rodriguez (http://markorodriguez.com)
*/
@@ -236,34 +234,21 @@ public final class RepeatStep<S> extends ComputerAwareStep<S, S> implements Trav
while (true) {
if (this.repeatTraversal.getEndStep().hasNext()) {
- Traverser.Admin<S> result = this.repeatTraversal.getEndStep().next();
- System.out.printf("RepeatStep returning result: %s Path: %s%n",
- ((Vertex) result.get()).property("id").value(), result.path());
- return IteratorUtils.of(result);
+ return this.repeatTraversal.getEndStep();
} else {
final Traverser.Admin<S> start = this.starts.next();
-
String ln;
if (this.loopName != null) {
ln = this.getId();
} else {
ln = this.loopName;
}
-
start.initialiseLoops(this.getId(), ln);
- System.out.printf("RepeatStep processing start: %s Path: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.path(), start.loops());
if (doUntil(start, true)) {
- System.out.printf("RepeatStep until condition met, exiting: %s%n",
- ((Vertex) start.get()).property("id").value());
start.resetLoops();
return IteratorUtils.of(start);
}
-
- System.out.printf("RepeatStep adding to repeat traversal: %s%n",
- ((Vertex) start.get()).property("id").value());
this.repeatTraversal.addStart(start);
-
if (doEmit(start, true)) {
final Traverser.Admin<S> emitSplit = start.split();
emitSplit.resetLoops();
@@ -355,28 +340,15 @@ public final class RepeatStep<S> extends ComputerAwareStep<S, S> implements Trav
final RepeatStep<S> repeatStep = (RepeatStep<S>) this.getTraversal().getParent();
while (true) {
final Traverser.Admin<S> start = this.starts.next();
- System.out.printf("RepeatEndStep processing: %s Path: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.path(), start.loops());
start.incrLoops();
- System.out.printf("RepeatEndStep after incrLoops: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.loops());
if (repeatStep.doUntil(start, false)) {
- System.out.printf("RepeatEndStep until condition met, resetting loops: %s%n",
- ((Vertex) start.get()).property("id").value());
start.resetLoops();
return IteratorUtils.of(start);
} else {
- System.out.printf("RepeatEndStep continuing repeat: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.loops());
- if (!repeatStep.untilFirst && !repeatStep.emitFirst) {
+ if (!repeatStep.untilFirst && !repeatStep.emitFirst)
repeatStep.repeatTraversal.addStart(start);
- System.out.printf("RepeatEndStep added start to repeatTraversal: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.loops());
- } else {
+ else
repeatStep.addStart(start);
- System.out.printf("RepeatEndStep adding start to repeatStep: %s Loops: %d%n",
- ((Vertex) start.get()).property("id").value(), start.loops());
- }
if (repeatStep.doEmit(start, false)) {
final Traverser.Admin<S> emitSplit = start.split();
emitSplit.resetLoops();
diff --git a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
index c9d5d1ed7d..b5ed20db43 100644
--- a/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
+++ b/gremlin-core/src/main/java/org/apache/tinkerpop/gremlin/process/traversal/step/filter/RangeGlobalStep.java
@@ -73,8 +73,6 @@ public final class RangeGlobalStep<S> extends FilterStep<S> implements Ranging,
// Determine which counter to use
AtomicLong currentCounter = this.counter;
if (usePerIterationCounters) {
-
-
StringBuilder sb = new StringBuilder();
Traversal.Admin t = this.traversal;
while (!t.isRoot()) {
@@ -82,15 +80,11 @@ public final class RangeGlobalStep<S> extends FilterStep<S> implements Ranging,
// TODO: account scenario where parent is not repeat step?
Step<?, ?> ps = pt.asStep();
String pid = ps.getId();
- int loops = traverser.loops(pid);
- System.out.printf("Parent: %s PID: %s Loops: %d TraverserLoops: %d%n", ps, pid, loops, traverser.loops());
sb.append(pid).append(":");
- sb.append(loops).append(":");
+ sb.append(traverser.loops(pid)).append(":");
t = ps.getTraversal();
}
sb.append(this.getId()).append(":").append(traverser.loops());
-// Object pathHead = traverser.path().get(0);
-// sb.append(":").append(pathHead.toString());
// Create counter key that isolates between different repeat step contexts
String iterationKey = sb.toString();
diff --git a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
index c9317ba083..5b8b37a5c1 100644
--- a/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
+++ b/tinkergraph-gremlin/src/test/java/org/apache/tinkerpop/gremlin/tinkergraph/structure/TinkerGraphPlayTest.java
@@ -59,7 +59,7 @@ import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.select
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.union;
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.valueMap;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
/**
* @author Stephen Mallette (http://stephen.genoprime.com);
@@ -101,15 +101,38 @@ public class TinkerGraphPlayTest {
@Test
public void testRepeatOutLimit() {
- GraphTraversal<Vertex, Path> basic = g.V().has("id", "l2-0")
+ GraphTraversal<Vertex, Path> outLimit = g.V().has("id", "l2-0")
.repeat(__.out("knows").limit(2))
.times(2).path().by("id");
- GraphTraversal<Vertex, Path> basicUnfolded = g.V().has("id", "l2-0")
+ GraphTraversal<Vertex, Path> outLimitUnfolded = g.V().has("id", "l2-0")
.out("knows").limit(2)
.out("knows").limit(2)
.path().by("id");
- assertEquals(toListAndPrint("basic", basic), toListAndPrint("basicUnfolded", basicUnfolded));
+ assertEquals(toListAndPrint("outLimit", outLimit), toListAndPrint("outLimitUnfolded", outLimitUnfolded));
+ }
+
+ @Test
+ public void testRepeatWithBothAndLimit() {
+ GraphTraversal<Vertex, Path> bothLimit = g.V().has("id", "l3-0")
+ .repeat(__.both("knows").limit(3))
+ .times(2).path().by("id");
+ GraphTraversal<Vertex, Path> bothLimitUnfolded = g.V().has("id", "l3-0")
+ .both("knows").limit(3)
+ .both("knows").limit(3)
+ .path().by("id");
+ assertEquals(toListAndPrint("bothLimit", bothLimit), toListAndPrint("bothLimitUnfolded", bothLimitUnfolded));
+ }
+ @Test
+ public void testRepeatWithFilterAndLimit() {
+ GraphTraversal<Vertex, Path> filterLimit = g.V().has("id", "l2-0")
+ .repeat(__.out("knows").has("id", P.neq("l4-3")).limit(2))
+ .times(2).path().by("id");
+ GraphTraversal<Vertex, Path> filterLimitUnfolded = g.V().has("id", "l2-0")
+ .out("knows").has("id", P.neq("l4-3")).limit(2)
+ .out("knows").has("id", P.neq("l4-3")).limit(2)
+ .path().by("id");
+ assertEquals(toListAndPrint("filterLimit", filterLimit), toListAndPrint("basicUnfolded", filterLimitUnfolded));
}
@Test
@@ -329,6 +352,7 @@ public class TinkerGraphPlayTest {
for (Object o : list) {
System.out.println(o);
}
+ assertFalse(list.isEmpty());
return list;
}