-
Notifications
You must be signed in to change notification settings - Fork 935
/
Copy pathQueuedThreadPoolTest.groovy
98 lines (87 loc) · 2.38 KB
/
QueuedThreadPoolTest.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
import io.opentelemetry.api.trace.SpanKind
import io.opentelemetry.instrumentation.test.AgentInstrumentationSpecification
import org.eclipse.jetty.util.thread.QueuedThreadPool
import static org.junit.jupiter.api.Assumptions.assumeTrue
class QueuedThreadPoolTest extends AgentInstrumentationSpecification {
def "QueueThreadPool 'dispatch' propagates"() {
setup:
def pool = new QueuedThreadPool()
// run test only if QueuedThreadPool has dispatch method
// dispatch method was removed in jetty 9.1
assumeTrue(pool.metaClass.getMetaMethod("dispatch", Runnable) != null)
pool.start()
new Runnable() {
@Override
void run() {
runWithSpan("parent") {
// this child will have a span
def child1 = new JavaAsyncChild()
// this child won't
def child2 = new JavaAsyncChild(false, false)
pool.dispatch(child1)
pool.dispatch(child2)
child1.waitForCompletion()
child2.waitForCompletion()
}
}
}.run()
expect:
assertTraces(1) {
trace(0, 2) {
span(0) {
name "parent"
kind SpanKind.INTERNAL
hasNoParent()
}
span(1) {
name "asyncChild"
kind SpanKind.INTERNAL
childOf span(0)
}
}
}
cleanup:
pool.stop()
}
def "QueueThreadPool 'dispatch' propagates lambda"() {
setup:
def pool = new QueuedThreadPool()
// run test only if QueuedThreadPool has dispatch method
// dispatch method was removed in jetty 9.1
assumeTrue(pool.metaClass.getMetaMethod("dispatch", Runnable) != null)
pool.start()
JavaAsyncChild child = new JavaAsyncChild(true, true)
new Runnable() {
@Override
void run() {
runWithSpan("parent") {
pool.dispatch(JavaLambdaMaker.lambda(child))
}
}
}.run()
// We block in child to make sure spans close in predictable order
child.unblock()
child.waitForCompletion()
expect:
assertTraces(1) {
trace(0, 2) {
span(0) {
name "parent"
kind SpanKind.INTERNAL
hasNoParent()
}
span(1) {
name "asyncChild"
kind SpanKind.INTERNAL
childOf span(0)
}
}
}
cleanup:
pool.stop()
}
}