|
5 | 5 |
|
6 | 6 | package io.opentelemetry.javaagent.instrumentation.guava.v10_0; |
7 | 7 |
|
8 | | -import static org.assertj.core.api.Assertions.assertThat; |
9 | | - |
10 | 8 | import com.google.common.eventbus.AsyncEventBus; |
11 | 9 | import com.google.common.eventbus.Subscribe; |
12 | | -import io.opentelemetry.api.trace.Span; |
13 | 10 | import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; |
14 | 11 | import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; |
15 | 12 | import java.util.concurrent.ExecutorService; |
16 | 13 | import java.util.concurrent.Executors; |
17 | 14 | import org.junit.jupiter.api.Test; |
18 | 15 | import org.junit.jupiter.api.extension.RegisterExtension; |
19 | 16 |
|
20 | | -public class AsyncEventBusTest { |
| 17 | +class AsyncEventBusTest { |
21 | 18 |
|
22 | 19 | @RegisterExtension |
23 | 20 | static final InstrumentationExtension testing = AgentInstrumentationExtension.create(); |
24 | 21 |
|
25 | 22 | static final ExecutorService executor = Executors.newSingleThreadExecutor(); |
26 | | - |
27 | 23 | static final AsyncEventBus asyncEventBus = new AsyncEventBus(executor); |
28 | 24 |
|
29 | 25 | @Test |
30 | | - void testAsyncEventBusTakeEffect() { |
| 26 | + void contextPropagation() { |
31 | 27 | class Listener { |
32 | | - String receivedTraceId; |
33 | 28 |
|
34 | 29 | @Subscribe |
35 | 30 | public void onEvent(String event) { |
36 | | - testing.runWithSpan( |
37 | | - "listener", |
38 | | - () -> { |
39 | | - receivedTraceId = Span.current().getSpanContext().getTraceId(); |
40 | | - }); |
| 31 | + testing.runWithSpan("listener", () -> {}); |
41 | 32 | } |
42 | 33 | } |
43 | 34 |
|
44 | | - Listener listener = new Listener(); |
45 | | - asyncEventBus.register(listener); |
| 35 | + asyncEventBus.register(new Listener()); |
46 | 36 |
|
47 | | - String[] parentTraceId = new String[1]; |
48 | | - testing.runWithSpan( |
49 | | - "parent", |
50 | | - () -> { |
51 | | - parentTraceId[0] = Span.current().getSpanContext().getTraceId(); |
52 | | - asyncEventBus.post("test"); |
53 | | - }); |
| 37 | + testing.runWithSpan("parent", () -> asyncEventBus.post("test")); |
54 | 38 |
|
55 | 39 | testing.waitAndAssertTraces( |
56 | 40 | trace -> |
57 | 41 | trace.hasSpansSatisfyingExactly( |
58 | 42 | span -> span.hasName("parent"), span -> span.hasName("listener"))); |
59 | | - |
60 | | - assertThat(listener.receivedTraceId) |
61 | | - .isNotNull() |
62 | | - .isNotEqualTo("00000000000000000000000000000000") |
63 | | - .isEqualTo(parentTraceId[0]); |
64 | 43 | } |
65 | 44 | } |
0 commit comments