|
3 | 3 | * SPDX-License-Identifier: Apache-2.0
|
4 | 4 | */
|
5 | 5 |
|
6 |
| -package io.opentelemetry.instrumentation.tracer |
| 6 | +package io.opentelemetry.instrumentation.tracer; |
7 | 7 |
|
8 |
| -import io.opentelemetry.context.Context |
9 |
| -import io.opentelemetry.sdk.trace.ReadWriteSpan |
10 |
| -import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes |
11 |
| -import spock.lang.Specification |
| 8 | +import static org.assertj.core.api.Assertions.assertThat; |
| 9 | +import static org.mockito.Mockito.mock; |
| 10 | +import static org.mockito.Mockito.verify; |
| 11 | +import static org.mockito.Mockito.verifyNoMoreInteractions; |
12 | 12 |
|
13 |
| -class AddThreadDetailsSpanProcessorTest extends Specification { |
14 |
| - def span = Mock(ReadWriteSpan) |
| 13 | +import io.opentelemetry.context.Context; |
| 14 | +import io.opentelemetry.sdk.trace.ReadWriteSpan; |
| 15 | +import io.opentelemetry.sdk.trace.SpanProcessor; |
| 16 | +import io.opentelemetry.semconv.incubating.ThreadIncubatingAttributes; |
| 17 | +import org.junit.jupiter.api.Test; |
15 | 18 |
|
16 |
| - def processor = new AddThreadDetailsSpanProcessor() |
| 19 | +class AddThreadDetailsSpanProcessorTest { |
17 | 20 |
|
18 |
| - def "should require onStart call"() { |
19 |
| - expect: |
20 |
| - processor.isStartRequired() |
21 |
| - } |
| 21 | + private ReadWriteSpan span = mock(ReadWriteSpan.class); |
| 22 | + |
| 23 | + private SpanProcessor spanProcessor = new AddThreadDetailsSpanProcessor(); |
22 | 24 |
|
23 |
| - def "should set thread attributes on span start"() { |
24 |
| - given: |
25 |
| - def currentThreadName = Thread.currentThread().name |
26 |
| - def currentThreadId = Thread.currentThread().id |
| 25 | + @Test |
| 26 | + void onStart() { |
| 27 | + assertThat(spanProcessor.isStartRequired()).isTrue(); |
| 28 | + } |
27 | 29 |
|
28 |
| - when: |
29 |
| - processor.onStart(Context.root(), span) |
| 30 | + @Test |
| 31 | + void setThreadAttributes() { |
| 32 | + Thread thread = Thread.currentThread(); |
| 33 | + spanProcessor.onStart(Context.root(), span); |
30 | 34 |
|
31 |
| - then: |
32 |
| - 1 * span.setAttribute(ThreadIncubatingAttributes.THREAD_ID, currentThreadId) |
33 |
| - 1 * span.setAttribute(ThreadIncubatingAttributes.THREAD_NAME, currentThreadName) |
| 35 | + verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_ID, thread.getId()); |
| 36 | + verify(span).setAttribute(ThreadIncubatingAttributes.THREAD_NAME, thread.getName()); |
| 37 | + verifyNoMoreInteractions(span); |
34 | 38 | }
|
35 | 39 | }
|
0 commit comments