Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for newVirtualThreadPerTaskExecutor #9616

Merged
merged 5 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading