forked from testng-team/testng
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support suite level thread pools for data provider
Closes testng-team#2980 We can now configure TestNG such that it uses a Suite level thread pool when running data driven Tests in parallel. This can be enabled via the configuration “-shareThreadPoolForDataProviders” with a value of “true” Alternatively one can also use the suite level attribute “share-thread-pool-for-data-providers”
- Loading branch information
1 parent
a9c0174
commit 4c332ba
Showing
19 changed files
with
357 additions
and
4 deletions.
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
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,27 @@ | ||
package org.testng; | ||
|
||
import java.io.Closeable; | ||
import java.util.function.Supplier; | ||
|
||
/** | ||
* Represents a bean bag which is scoped to a specific {@link ISuite}. After a {@link ISuite} wraps | ||
* up its execution, the contents of this bean bag will be cleaned-up. | ||
*/ | ||
public interface IObjectBag { | ||
|
||
/** | ||
* @param type - The type of the object to be created | ||
* @param supplier - A {@link Supplier} that should be used to produce a new instance | ||
* @param <T> - The type of the object | ||
* @return - Either the newly produced instance or the existing instance. | ||
*/ | ||
<T> T createIfRequired(Class<T> type, Supplier<T> supplier); | ||
|
||
/** | ||
* In-case the object bag has bean objects that implement {@link java.io.Closeable} then the | ||
* {@link Closeable#close()} will be automatically invoked after a suite has run to completion but | ||
* before the test reports are generated. This will also empty the bean bag. So querying this bean | ||
* bag during reporting phase is most likely to yield only an empty value | ||
*/ | ||
void cleanup(); | ||
} |
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
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
39 changes: 39 additions & 0 deletions
39
testng-core/src/main/java/org/testng/internal/ObjectBag.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,39 @@ | ||
package org.testng.internal; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Supplier; | ||
import org.testng.IObjectBag; | ||
import org.testng.log4testng.Logger; | ||
|
||
/** | ||
* A simple bean bag that is intended to help share objects during the lifetime of TestNG without | ||
* needing it to be a singleton. | ||
*/ | ||
public final class ObjectBag implements IObjectBag { | ||
|
||
private static final Logger logger = Logger.getLogger(ObjectBag.class); | ||
private final Map<Class<?>, Object> bag = new ConcurrentHashMap<>(); | ||
|
||
@SuppressWarnings("unchecked") | ||
public <T> T createIfRequired(Class<T> type, Supplier<T> supplier) { | ||
return (T) bag.computeIfAbsent(type, t -> supplier.get()); | ||
} | ||
|
||
public void cleanup() { | ||
bag.values().stream() | ||
.filter(it -> it instanceof Closeable) | ||
.map(it -> (Closeable) it) | ||
.forEach( | ||
it -> { | ||
try { | ||
it.close(); | ||
} catch (IOException e) { | ||
logger.debug("Could not clean-up " + it, e); | ||
} | ||
}); | ||
bag.clear(); | ||
} | ||
} |
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.