@@ -46,13 +46,11 @@ import org.junit.jupiter.api.AfterAll
4646import org.junit.jupiter.api.Assumptions
4747import org.junit.jupiter.api.Test
4848import org.junit.jupiter.api.TestInstance
49- import org.junit.jupiter.api.extension.ExtensionContext
5049import org.junit.jupiter.api.extension.RegisterExtension
5150import org.junit.jupiter.params.ParameterizedTest
5251import org.junit.jupiter.params.provider.Arguments
5352import org.junit.jupiter.params.provider.Arguments.arguments
54- import org.junit.jupiter.params.provider.ArgumentsProvider
55- import org.junit.jupiter.params.provider.ArgumentsSource
53+ import org.junit.jupiter.params.provider.MethodSource
5654import java.util.concurrent.Executors
5755import java.util.concurrent.TimeUnit
5856import java.util.function.Consumer
@@ -83,7 +81,7 @@ class KotlinCoroutinesInstrumentationTest {
8381 val tracer = testing.openTelemetry.getTracer(" test" )
8482
8583 @ParameterizedTest
86- @ArgumentsSource( DispatchersSource :: class )
84+ @MethodSource( " dispatchersSourceArguments " )
8785 fun `cancellation prevents trace` (dispatcher : DispatcherWrapper ) {
8886 runCatching {
8987 runTest(dispatcher) {
@@ -116,7 +114,7 @@ class KotlinCoroutinesInstrumentationTest {
116114 }
117115
118116 @ParameterizedTest
119- @ArgumentsSource( DispatchersSource :: class )
117+ @MethodSource( " dispatchersSourceArguments " )
120118 fun `propagates across nested jobs` (dispatcher : DispatcherWrapper ) {
121119 runTest(dispatcher) {
122120 val goodDeferred = async { 1 }
@@ -310,7 +308,7 @@ class KotlinCoroutinesInstrumentationTest {
310308 }
311309
312310 @ParameterizedTest
313- @ArgumentsSource( DispatchersSource :: class )
311+ @MethodSource( " dispatchersSourceArguments " )
314312 fun `traced mono` (dispatcherWrapper : DispatcherWrapper ) {
315313 runTest(dispatcherWrapper) {
316314 mono(dispatcherWrapper.dispatcher) {
@@ -337,7 +335,7 @@ class KotlinCoroutinesInstrumentationTest {
337335 private val animalKey: ContextKey <String > = ContextKey .named(" animal" )
338336
339337 @ParameterizedTest
340- @ArgumentsSource( DispatchersSource :: class )
338+ @MethodSource( " dispatchersSourceArguments " )
341339 fun `context contains expected value` (dispatcher : DispatcherWrapper ) {
342340 runTest(dispatcher) {
343341 val context1 = Context .current().with (animalKey, " cat" )
@@ -512,18 +510,16 @@ class KotlinCoroutinesInstrumentationTest {
512510 span.end()
513511 }
514512
515- class DispatchersSource : ArgumentsProvider {
516- override fun provideArguments (context : ExtensionContext ? ): Stream <out Arguments > = Stream .of(
517- // Wrap dispatchers since it seems that ParameterizedTest tries to automatically close
518- // Closeable arguments with no way to avoid it.
519- arguments(DispatcherWrapper (Dispatchers .Default )),
520- arguments(DispatcherWrapper (Dispatchers .IO )),
521- arguments(DispatcherWrapper (Dispatchers .Unconfined )),
522- arguments(DispatcherWrapper (threadPool.asCoroutineDispatcher())),
523- arguments(DispatcherWrapper (singleThread.asCoroutineDispatcher())),
524- arguments(DispatcherWrapper (vertx.dispatcher()))
525- )
526- }
513+ private fun dispatchersSourceArguments (): Stream <Arguments > = Stream .of(
514+ // Wrap dispatchers since it seems that ParameterizedTest tries to automatically close
515+ // Closeable arguments with no way to avoid it.
516+ arguments(DispatcherWrapper (Dispatchers .Default )),
517+ arguments(DispatcherWrapper (Dispatchers .IO )),
518+ arguments(DispatcherWrapper (Dispatchers .Unconfined )),
519+ arguments(DispatcherWrapper (threadPool.asCoroutineDispatcher())),
520+ arguments(DispatcherWrapper (singleThread.asCoroutineDispatcher())),
521+ arguments(DispatcherWrapper (vertx.dispatcher()))
522+ )
527523
528524 class DispatcherWrapper (val dispatcher : CoroutineDispatcher ) {
529525 override fun toString (): String = dispatcher.toString()
@@ -566,7 +562,7 @@ class KotlinCoroutinesInstrumentationTest {
566562 // regression test for
567563 // https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/11411
568564 @ParameterizedTest
569- @ArgumentsSource( DispatchersSource :: class )
565+ @MethodSource( " dispatchersSourceArguments " )
570566 fun `dispatch does not propagate context` (dispatcher : DispatcherWrapper ) {
571567 Assumptions .assumeTrue(dispatcher.dispatcher != Dispatchers .Unconfined )
572568
0 commit comments