|
20 | 20 | package org.apache.tinkerpop.gremlin.process.traversal.util;
|
21 | 21 |
|
22 | 22 | import org.apache.tinkerpop.gremlin.process.traversal.Operator;
|
| 23 | +import org.apache.tinkerpop.gremlin.process.traversal.P; |
23 | 24 | import org.apache.tinkerpop.gremlin.process.traversal.Step;
|
24 | 25 | import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
|
25 | 26 | import org.apache.tinkerpop.gremlin.process.traversal.TraversalSideEffects;
|
26 | 27 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal;
|
| 28 | +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; |
27 | 29 | import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
|
28 | 30 | import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent;
|
| 31 | +import org.apache.tinkerpop.gremlin.structure.Graph; |
| 32 | +import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph; |
29 | 33 | import org.apache.tinkerpop.gremlin.util.function.ConstantSupplier;
|
30 | 34 | import org.apache.tinkerpop.gremlin.util.function.HashSetSupplier;
|
31 | 35 | import org.hamcrest.CoreMatchers;
|
|
42 | 46 | import java.util.stream.Collectors;
|
43 | 47 | import java.util.stream.IntStream;
|
44 | 48 |
|
| 49 | +import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal; |
45 | 50 | import static org.hamcrest.number.OrderingComparison.greaterThan;
|
46 | 51 | import static org.hamcrest.number.OrderingComparison.lessThan;
|
47 | 52 | import static org.junit.Assert.assertEquals;
|
48 | 53 | import static org.junit.Assert.assertFalse;
|
49 | 54 | import static org.junit.Assert.assertNotEquals;
|
50 | 55 | import static org.junit.Assert.assertNotSame;
|
51 | 56 | import static org.hamcrest.MatcherAssert.assertThat;
|
| 57 | +import static org.hamcrest.core.Is.is; |
52 | 58 | import static org.junit.Assert.assertTrue;
|
53 | 59 |
|
54 | 60 | /**
|
@@ -127,6 +133,53 @@ public void shouldBeTheSameSideEffectsThroughoutAllChildTraversals() {
|
127 | 133 | recursiveTestTraversals(traversal, sideEffects, new HashSet<>(Arrays.asList("marko", "bob", "x")), 13);
|
128 | 134 | }
|
129 | 135 |
|
| 136 | + @Test |
| 137 | + public void shouldLock() { |
| 138 | + final Traversal t = getBigDeepTraversal(); |
| 139 | + t.asAdmin().lock(); |
| 140 | + recursiveTestLock(t.asAdmin()); |
| 141 | + } |
| 142 | + |
| 143 | + |
| 144 | + @Test |
| 145 | + public void shouldLockAfterApplyingStrategies() { |
| 146 | + final Traversal t = getBigDeepTraversal(); |
| 147 | + t.asAdmin().applyStrategies(); |
| 148 | + recursiveTestLock(t.asAdmin()); |
| 149 | + } |
| 150 | + |
| 151 | + private static Traversal getBigDeepTraversal() { |
| 152 | + final Graph graph = EmptyGraph.instance(); |
| 153 | + final GraphTraversalSource g = traversal().withEmbedded(graph); |
| 154 | + |
| 155 | + final Traversal t = g.V().or( |
| 156 | + __.has("name", P.within(new HashSet<>(Arrays.asList("DARK STAR", "ST. STEPHEN", "CHINA CAT SUNFLOWER")))), |
| 157 | + __.has("songType", P.eq("cover"))).where( |
| 158 | + __.coalesce( |
| 159 | + __.where( |
| 160 | + __.union( |
| 161 | + __.as("a").inE("sungBy").choose( |
| 162 | + __.has("weight"), __.has("weight", P.gt(1)), __.identity() |
| 163 | + ).outV().filter(__.has("weight", P.lt(1))), |
| 164 | + __.as("a").outE("followedBy").choose( |
| 165 | + __.has("weight"), __.has("weight", P.gt(1)), __.identity() |
| 166 | + ).inV().where(__.identity()) |
| 167 | + ).dedup().select("a") |
| 168 | + ) |
| 169 | + )); |
| 170 | + return t; |
| 171 | + } |
| 172 | + |
| 173 | + private void recursiveTestLock(final Traversal.Admin<?, ?> traversal) { |
| 174 | + assertThat(traversal.isLocked(), is(true)); |
| 175 | + for (final Step<?, ?> step : traversal.getSteps()) { |
| 176 | + if (step instanceof TraversalParent) { |
| 177 | + ((TraversalParent) step).getGlobalChildren().forEach(this::recursiveTestLock); |
| 178 | + ((TraversalParent) step).getLocalChildren().forEach(this::recursiveTestLock); |
| 179 | + } |
| 180 | + } |
| 181 | + } |
| 182 | + |
130 | 183 | private void recursiveTestTraversals(final Traversal.Admin<?, ?> traversal, final TraversalSideEffects sideEffects, final Set aValue, final int bValue) {
|
131 | 184 | assertTrue(traversal.getSideEffects() == sideEffects);
|
132 | 185 | assertEquals(sideEffects.keys().size(), traversal.getSideEffects().keys().size());
|
|
0 commit comments