33 * SPDX-License-Identifier: Apache-2.0
44 */
55
6+ import static org .junit .jupiter .api .Assumptions .assumeTrue ;
7+
68import io .opentelemetry .api .GlobalOpenTelemetry ;
79import io .opentelemetry .api .trace .SpanKind ;
810import io .opentelemetry .api .trace .Tracer ;
911import io .opentelemetry .instrumentation .testing .junit .AgentInstrumentationExtension ;
1012import io .opentelemetry .instrumentation .testing .junit .InstrumentationExtension ;
13+ import java .lang .reflect .Method ;
1114import java .util .concurrent .Callable ;
1215import java .util .concurrent .CountDownLatch ;
1316import org .junit .jupiter .api .Test ;
@@ -22,6 +25,22 @@ 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+ static {
31+ // removed in spring 7
32+ submitListenableRunnable = findMethod ("submitListenable" , Runnable .class );
33+ submitListenableCallable = findMethod ("submitListenable" , Callable .class );
34+ }
35+
36+ private static Method findMethod (String name , Class <?>... parameterTypes ) {
37+ try {
38+ return SimpleAsyncTaskExecutor .class .getMethod (name , parameterTypes );
39+ } catch (Exception e ) {
40+ return null ;
41+ }
42+ }
43+
2544 @ Test
2645 void executeRunnable () {
2746 executeTwoTasks (EXECUTOR ::execute );
@@ -39,12 +58,14 @@ void submitCallable() {
3958
4059 @ Test
4160 void submitListenableRunnable () {
42- executeTwoTasks (task -> EXECUTOR .submitListenable ((Runnable ) task ));
61+ assumeTrue (submitListenableRunnable != null );
62+ executeTwoTasks (task -> submitListenableRunnable .invoke (EXECUTOR , task ));
4363 }
4464
4565 @ Test
4666 void submitListenableCallable () {
47- executeTwoTasks (task -> EXECUTOR .submitListenable ((Callable <?>) task ));
67+ assumeTrue (submitListenableCallable != null );
68+ executeTwoTasks (task -> submitListenableCallable .invoke (EXECUTOR , task ));
4869 }
4970
5071 private static void executeTwoTasks (ThrowingConsumer <AsyncTask > task ) {
0 commit comments