Skip to content

Commit bd338db

Browse files
committed
TINKERPOP-3100 Add better tests/benchmarks around lock()
This was done because jdk8 could not compile the deep traversal tests that were used in testing. Adding the benchmarks and tests used to develop this work back since jdk8 is not an issue for 3.8.x.
1 parent ca5544d commit bd338db

File tree

3 files changed

+310
-1
lines changed

3 files changed

+310
-1
lines changed

gremlin-core/src/test/java/org/apache/tinkerpop/gremlin/process/traversal/util/DefaultTraversalTest.java

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,47 @@ private static Traversal getBigDeepTraversal() {
163163
).outV().filter(__.has("weight", P.lt(1))),
164164
__.as("a").outE("followedBy").choose(
165165
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
166-
).inV().where(__.identity())
166+
).inV().where(
167+
__.coalesce(
168+
__.where(
169+
__.union(
170+
__.as("a").outE("followedBy").choose(
171+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
172+
).inV().has("songType", P.neq("cover")).where(
173+
__.coalesce(
174+
__.where(
175+
__.union(
176+
__.as("a").outE("followedBy").choose(
177+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
178+
).inV().where(
179+
__.coalesce(
180+
__.where(
181+
__.union(
182+
__.as("a").outE("followedBy").choose(
183+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
184+
).inV().where(
185+
__.coalesce(
186+
__.where(
187+
__.union(
188+
__.as("a").outE("followedBy").choose(
189+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
190+
).inV().has("songType", P.within("original"))
191+
)
192+
)
193+
)
194+
)
195+
)
196+
)
197+
)
198+
)
199+
)
200+
)
201+
)
202+
)
203+
)
204+
)
205+
)
206+
)
167207
).dedup().select("a")
168208
)
169209
));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.tinkerpop.gremlin.process;
20+
21+
import org.apache.tinkerpop.benchmark.util.AbstractBenchmarkBase;
22+
import org.apache.tinkerpop.gremlin.process.traversal.P;
23+
import org.apache.tinkerpop.gremlin.process.traversal.Traversal;
24+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource;
25+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
26+
import org.apache.tinkerpop.gremlin.structure.Graph;
27+
import org.apache.tinkerpop.gremlin.structure.util.empty.EmptyGraph;
28+
import org.openjdk.jmh.annotations.Benchmark;
29+
import org.openjdk.jmh.annotations.Level;
30+
import org.openjdk.jmh.annotations.OutputTimeUnit;
31+
import org.openjdk.jmh.annotations.Scope;
32+
import org.openjdk.jmh.annotations.Setup;
33+
import org.openjdk.jmh.annotations.State;
34+
35+
import java.util.Arrays;
36+
import java.util.HashSet;
37+
import java.util.concurrent.TimeUnit;
38+
39+
import static org.apache.tinkerpop.gremlin.process.traversal.AnonymousTraversalSource.traversal;
40+
41+
/**
42+
* Benchmark for measuring the performance of applying strategies to a complex traversal.
43+
*/
44+
@OutputTimeUnit(TimeUnit.MILLISECONDS)
45+
@State(Scope.Thread)
46+
public class ApplyStrategiesBenchmark extends AbstractBenchmarkBase {
47+
48+
private Graph graph = EmptyGraph.instance();
49+
private GraphTraversalSource g = traversal().withEmbedded(graph);
50+
private Traversal<?, ?> traversal;
51+
52+
/**
53+
* Setup method that constructs the complex traversal before benchmarking on each invocation of the test.
54+
*/
55+
@Setup(Level.Invocation)
56+
public void setup() {
57+
traversal = g.V().or(
58+
__.has("name", P.within(new HashSet<>(Arrays.asList("DARK STAR", "ST. STEPHEN", "CHINA CAT SUNFLOWER")))),
59+
__.has("songType", P.eq("cover"))).where(
60+
__.coalesce(
61+
__.where(
62+
__.union(
63+
__.as("a").inE("sungBy").choose(
64+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
65+
).outV().filter(__.has("weight", P.lt(1))),
66+
__.as("a").outE("followedBy").choose(
67+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
68+
).inV().where(
69+
__.coalesce(
70+
__.where(
71+
__.union(
72+
__.as("a").outE("followedBy").choose(
73+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
74+
).inV().has("songType", P.neq("cover")).where(
75+
__.coalesce(
76+
__.where(
77+
__.union(
78+
__.as("a").outE("followedBy").choose(
79+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
80+
).inV().where(
81+
__.coalesce(
82+
__.where(
83+
__.union(
84+
__.as("a").outE("followedBy").choose(
85+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
86+
).inV().where(
87+
__.coalesce(
88+
__.where(
89+
__.union(
90+
__.as("a").outE("followedBy").choose(
91+
__.has("weight"), __.has("weight", P.gt(1)), __.identity()
92+
).inV().has("songType", P.within("original"))
93+
)
94+
)
95+
)
96+
)
97+
)
98+
)
99+
)
100+
)
101+
)
102+
)
103+
)
104+
)
105+
)
106+
)
107+
)
108+
)
109+
).dedup().select("a")
110+
)
111+
));
112+
}
113+
114+
@Override
115+
protected int getWarmupIterations() {
116+
return 1;
117+
}
118+
119+
@Override
120+
protected int getForks() {
121+
return 1;
122+
}
123+
124+
/**
125+
* Benchmark that measures only the time it takes to apply strategies to a complex traversal.
126+
*/
127+
@Benchmark
128+
public Traversal testLockTraversal() {
129+
if (traversal.asAdmin().isLocked())
130+
throw new RuntimeException("Traversal is locked - that shouldn't be possible if the traversal is new");
131+
traversal.asAdmin().applyStrategies();
132+
return traversal;
133+
}
134+
}

0 commit comments

Comments
 (0)