-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Allow custom thread pool executors to be wired in. #3075
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
testng-core-api/src/main/java/org/testng/IExecutorServiceFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package org.testng; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
/** | ||
* Represents the capability to create a custom {@link ExecutorService} by downstream consumers. The | ||
* implementation can be plugged in via the configuration parameter <code>-threadpoolfactoryclass | ||
* </code> | ||
*/ | ||
@FunctionalInterface | ||
public interface IExecutorServiceFactory { | ||
|
||
/** | ||
* @param corePoolSize the number of threads to keep in the pool, even if they are idle, unless | ||
* {@code allowCoreThreadTimeOut} is set | ||
* @param maximumPoolSize the maximum number of threads to allow in the pool | ||
* @param keepAliveTime when the number of threads is greater than the core, this is the maximum | ||
* time that excess idle threads will wait for new tasks before terminating. | ||
* @param unit the time unit for the {@code keepAliveTime} argument | ||
* @param workQueue the queue to use for holding tasks before they are executed. This queue will | ||
* hold only the {@code Runnable} tasks submitted by the {@code execute} method. | ||
* @param threadFactory the factory to use when the executor creates a new thread * | ||
* @return - An implementation of {@link ExecutorService} | ||
*/ | ||
ExecutorService create( | ||
int corePoolSize, | ||
int maximumPoolSize, | ||
long keepAliveTime, | ||
TimeUnit unit, | ||
BlockingQueue<Runnable> workQueue, | ||
ThreadFactory threadFactory); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes in
Configuration.java
to replaceIExecutorFactory
withIExecutorServiceFactory
and update the implementation accordingly are in line with the PR's objectives to enhance TestNG's thread management capabilities. The use ofObjects.requireNonNull
in thesetExecutorServiceFactory
method ensures that a non-null executor service factory is always set, which is a good practice for avoiding null-related issues.However, the default assignment of
ThreadPoolExecutor::new
toexecutorServiceFactory
at line 38 might not be fully aligned with the goal of allowing custom executor services, as it directly ties the configuration to a specific implementation ofExecutorService
. It would be beneficial to consider a more flexible default that encourages the use of custom executor services.Consider revising the default assignment for
executorServiceFactory
to encourage or facilitate the use of custom executor services, possibly by providing a more generic or abstract default implementation.