Add support for newVirtualThreadPerTaskExecutor (#9616)
This commit is contained in:
parent
62504d28e8
commit
abc7a227e1
|
@ -78,6 +78,7 @@ final class ExecutorMatchers {
|
|||
"java.util.concurrent.ForkJoinPool",
|
||||
"java.util.concurrent.ScheduledThreadPoolExecutor",
|
||||
"java.util.concurrent.ThreadPoolExecutor",
|
||||
"java.util.concurrent.ThreadPerTaskExecutor",
|
||||
"org.apache.tomcat.util.threads.ThreadPoolExecutor",
|
||||
"org.eclipse.jetty.util.thread.QueuedThreadPool", // dispatch() covered in the jetty
|
||||
// module
|
||||
|
|
|
@ -7,6 +7,8 @@ package io.opentelemetry.javaagent.instrumentation.executors;
|
|||
|
||||
import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension;
|
||||
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -24,6 +26,8 @@ import java.util.concurrent.ScheduledThreadPoolExecutor;
|
|||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledForJreRange;
|
||||
import org.junit.jupiter.api.condition.JRE;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
abstract class ExecutorInstrumentationTest<T extends ExecutorService>
|
||||
|
@ -47,6 +51,24 @@ abstract class ExecutorInstrumentationTest<T extends ExecutorService>
|
|||
}
|
||||
}
|
||||
|
||||
@EnabledForJreRange(min = JRE.JAVA_21)
|
||||
static class VirtualThreadExecutorTest extends ExecutorInstrumentationTest<ExecutorService> {
|
||||
VirtualThreadExecutorTest() {
|
||||
super(newVirtualThreadPerTaskExecutor());
|
||||
}
|
||||
|
||||
private static ExecutorService newVirtualThreadPerTaskExecutor() {
|
||||
Method newVirtualThreadPerTaskExecutor;
|
||||
try {
|
||||
newVirtualThreadPerTaskExecutor =
|
||||
Executors.class.getMethod("newVirtualThreadPerTaskExecutor");
|
||||
return (ExecutorService) newVirtualThreadPerTaskExecutor.invoke(null);
|
||||
} catch (InvocationTargetException | NoSuchMethodException | IllegalAccessException e) {
|
||||
throw new IllegalStateException("Should not happen on Java 21+", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class WorkStealingPoolTest extends ExecutorInstrumentationTest<ExecutorService> {
|
||||
public WorkStealingPoolTest() {
|
||||
super(Executors.newWorkStealingPool(2));
|
||||
|
|
Loading…
Reference in New Issue