-
Notifications
You must be signed in to change notification settings - Fork 1k
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 #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
a09978c
commit 7357104
Showing
16 changed files
with
332 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
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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
package org.testng.internal; | ||
|
||
import java.io.Closeable; | ||
import java.io.IOException; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.function.Supplier; | ||
import org.testng.ISuite; | ||
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 { | ||
|
||
private static final Logger logger = Logger.getLogger(ObjectBag.class); | ||
private final Map<Class<?>, Object> bag = new ConcurrentHashMap<>(); | ||
|
||
private static final Map<UUID, ObjectBag> instances = new ConcurrentHashMap<>(); | ||
|
||
public static ObjectBag getInstance(ISuite suite) { | ||
return instances.computeIfAbsent(suite.getXmlSuite().SUITE_ID, k -> new ObjectBag()); | ||
} | ||
|
||
public static void cleanup(ISuite suite) { | ||
UUID uid = suite.getXmlSuite().SUITE_ID; | ||
Optional.ofNullable(instances.get(uid)).ifPresent(ObjectBag::cleanup); | ||
instances.remove(uid); | ||
} | ||
|
||
/** | ||
* @param type - The type of the object to be created | ||
* @param supplier - A {@link Supplier} that should be used to produce a new instance | ||
* @return - Either the newly produced instance or the existing instance. | ||
*/ | ||
public Object createIfRequired(Class<?> type, Supplier<Object> supplier) { | ||
return 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.