Skip to content

Commit ff89a97

Browse files
committed
simplify test
1 parent 62df5cc commit ff89a97

File tree

2 files changed

+1
-89
lines changed

2 files changed

+1
-89
lines changed

instrumentation/methods/javaagent/src/declarativeConfigTest/java/io/opentelemetry/javaagent/instrumentation/methods/MethodTest.java

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,11 @@
99
import static io.opentelemetry.sdk.testing.assertj.OpenTelemetryAssertions.equalTo;
1010
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_FUNCTION;
1111
import static io.opentelemetry.semconv.incubating.CodeIncubatingAttributes.CODE_NAMESPACE;
12-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
1312

14-
import io.opentelemetry.api.trace.Span;
1513
import io.opentelemetry.api.trace.SpanKind;
1614
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
1715
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
1816
import java.util.concurrent.Callable;
19-
import java.util.concurrent.CompletableFuture;
20-
import java.util.concurrent.CountDownLatch;
21-
import java.util.concurrent.TimeUnit;
22-
import java.util.concurrent.atomic.AtomicReference;
23-
import javax.naming.NoInitialContextException;
24-
import javax.naming.directory.InitialDirContext;
25-
import javax.naming.ldap.InitialLdapContext;
2617
import org.junit.jupiter.api.Test;
2718
import org.junit.jupiter.api.extension.RegisterExtension;
2819

@@ -41,88 +32,16 @@ void methodTraced() {
4132
trace.hasSpansSatisfyingExactly(
4233
span ->
4334
span.hasName("ConfigTracedCallable.call")
44-
.hasKind(SpanKind.INTERNAL)
35+
.hasKind(SpanKind.SERVER)
4536
.hasAttributesSatisfyingExactly(
4637
equalTo(CODE_NAMESPACE, ConfigTracedCallable.class.getName()),
4738
equalTo(CODE_FUNCTION, "call"))));
4839
}
49-
50-
@Test
51-
void bootLoaderMethodTraced() throws Exception {
52-
InitialLdapContext context = new InitialLdapContext();
53-
AtomicReference<Throwable> throwableReference = new AtomicReference<>();
54-
assertThatThrownBy(
55-
() -> {
56-
try {
57-
context.search("foo", null);
58-
} catch (Throwable throwable) {
59-
throwableReference.set(throwable);
60-
throw throwable;
61-
}
62-
})
63-
.isInstanceOf(NoInitialContextException.class);
64-
65-
testing.waitAndAssertTraces(
66-
trace ->
67-
trace.hasSpansSatisfyingExactly(
68-
span ->
69-
span.hasName("InitialDirContext.search")
70-
.hasKind(SpanKind.CLIENT)
71-
.hasException(throwableReference.get())
72-
.hasAttributesSatisfyingExactly(
73-
equalTo(CODE_NAMESPACE, InitialDirContext.class.getName()),
74-
equalTo(CODE_FUNCTION, "search"))));
75-
}
76-
7740
static class ConfigTracedCallable implements Callable<String> {
7841

7942
@Override
8043
public String call() {
8144
return "Hello!";
8245
}
8346
}
84-
85-
@Test
86-
void methodTracedWithAsyncStop() throws Exception {
87-
ConfigTracedCompletableFuture traced = new ConfigTracedCompletableFuture();
88-
CompletableFuture<String> future = traced.getResult();
89-
90-
// span is ended when CompletableFuture is completed
91-
// verify that span has not been ended yet
92-
assertThat(traced.span).isNotNull().satisfies(span -> assertThat(span.isRecording()).isTrue());
93-
94-
traced.countDownLatch.countDown();
95-
assertThat(future.get(10, TimeUnit.SECONDS)).isEqualTo("Hello!");
96-
97-
testing.waitAndAssertTraces(
98-
trace ->
99-
trace.hasSpansSatisfyingExactly(
100-
span ->
101-
span.hasName("ConfigTracedCompletableFuture.getResult")
102-
.hasKind(SpanKind.SERVER)
103-
.hasAttributesSatisfyingExactly(
104-
equalTo(CODE_NAMESPACE, ConfigTracedCompletableFuture.class.getName()),
105-
equalTo(CODE_FUNCTION, "getResult"))));
106-
}
107-
108-
static class ConfigTracedCompletableFuture {
109-
final CountDownLatch countDownLatch = new CountDownLatch(1);
110-
Span span;
111-
112-
CompletableFuture<String> getResult() {
113-
CompletableFuture<String> completableFuture = new CompletableFuture<>();
114-
span = Span.current();
115-
new Thread(
116-
() -> {
117-
try {
118-
countDownLatch.await();
119-
} catch (InterruptedException exception) {
120-
// ignore
121-
}
122-
completableFuture.complete("Hello!");
123-
})
124-
.start();
125-
return completableFuture;
126-
}
127-
}
12847
}

instrumentation/methods/javaagent/src/declarativeConfigTest/resources/declarative-config.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,4 @@ instrumentation/development:
3030
- class: io.opentelemetry.javaagent.instrumentation.methods.MethodTest$ConfigTracedCallable
3131
methods:
3232
- name: call
33-
- class: io.opentelemetry.javaagent.instrumentation.methods.MethodTest$ConfigTracedCompletableFuture
34-
methods:
35-
- name: getResult
3633
span_kind: SERVER
37-
- class: javax.naming.directory.InitialDirContext
38-
methods:
39-
- name: search
40-
span_kind: CLIENT

0 commit comments

Comments
 (0)