Skip to content

Commit

Permalink
Add support for newVirtualThreadPerTaskExecutor (#9616)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz committed Oct 10, 2023
1 parent 62504d2 commit abc7a22
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

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;
Expand All @@ -24,6 +26,8 @@
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>
Expand All @@ -47,6 +51,24 @@ static class ThreadPoolExecutorTest extends ExecutorInstrumentationTest<ThreadPo
}
}

@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));
Expand Down

0 comments on commit abc7a22

Please sign in to comment.