Skip to content

Commit c0a08bf

Browse files
lauritotelbot[bot]
andauthored
Fix spring-core latest dep tests (#15299)
Co-authored-by: otelbot <[email protected]>
1 parent c443daf commit c0a08bf

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

instrumentation/spring/spring-core-2.0/javaagent/src/test/java/SimpleAsyncTaskExecutorInstrumentationTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import static org.junit.jupiter.api.Assumptions.assumeTrue;
7+
68
import io.opentelemetry.api.GlobalOpenTelemetry;
79
import io.opentelemetry.api.trace.SpanKind;
810
import io.opentelemetry.api.trace.Tracer;
911
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
1012
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
13+
import java.lang.reflect.Method;
1114
import java.util.concurrent.Callable;
1215
import java.util.concurrent.CountDownLatch;
1316
import org.junit.jupiter.api.Test;
@@ -22,6 +25,23 @@ class SimpleAsyncTaskExecutorInstrumentationTest {
2225

2326
private static final SimpleAsyncTaskExecutor EXECUTOR = new SimpleAsyncTaskExecutor();
2427

28+
private static final Method submitListenableRunnable;
29+
private static final Method submitListenableCallable;
30+
31+
static {
32+
// removed in spring 7
33+
submitListenableRunnable = findMethod("submitListenable", Runnable.class);
34+
submitListenableCallable = findMethod("submitListenable", Callable.class);
35+
}
36+
37+
private static Method findMethod(String name, Class<?>... parameterTypes) {
38+
try {
39+
return SimpleAsyncTaskExecutor.class.getMethod(name, parameterTypes);
40+
} catch (Exception e) {
41+
return null;
42+
}
43+
}
44+
2545
@Test
2646
void executeRunnable() {
2747
executeTwoTasks(EXECUTOR::execute);
@@ -39,12 +59,14 @@ void submitCallable() {
3959

4060
@Test
4161
void submitListenableRunnable() {
42-
executeTwoTasks(task -> EXECUTOR.submitListenable((Runnable) task));
62+
assumeTrue(submitListenableRunnable != null);
63+
executeTwoTasks(task -> submitListenableRunnable.invoke(EXECUTOR, task));
4364
}
4465

4566
@Test
4667
void submitListenableCallable() {
47-
executeTwoTasks(task -> EXECUTOR.submitListenable((Callable<?>) task));
68+
assumeTrue(submitListenableCallable != null);
69+
executeTwoTasks(task -> submitListenableCallable.invoke(EXECUTOR, task));
4870
}
4971

5072
private static void executeTwoTasks(ThrowingConsumer<AsyncTask> task) {

0 commit comments

Comments
 (0)