You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2022/04/24 10:44:25 UTC
[maven-surefire] branch release/2.22.3 updated: [SUREFIRE-2064] Allow all supported values of [parallel] option
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch release/2.22.3
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
The following commit(s) were added to refs/heads/release/2.22.3 by this push:
new 8fab72f0e [SUREFIRE-2064] Allow all supported values of [parallel] option
8fab72f0e is described below
commit 8fab72f0efddc14441c5a7b8855d4662d3517fa2
Author: Scott Babcock <sc...@hotmail.com>
AuthorDate: Fri Apr 8 02:59:22 2022 +0200
[SUREFIRE-2064] Allow all supported values of [parallel] option
(cherry picked from commit cbf7df3564470e57af11c243356b93c74622befc)
---
.../testng/conf/TestNG740Configurator.java | 51 ++++++++++++----------
.../testng/conf/TestNGMapConfigurator.java | 13 +++++-
2 files changed, 41 insertions(+), 23 deletions(-)
diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG740Configurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG740Configurator.java
index fc02b881b..e286ccf40 100644
--- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG740Configurator.java
+++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNG740Configurator.java
@@ -20,14 +20,13 @@ package org.apache.maven.surefire.testng.conf;
*/
import org.apache.maven.surefire.testset.TestSetFailedException;
-import org.apache.maven.surefire.util.ReflectionUtils;
import org.testng.xml.XmlSuite;
import java.util.Map;
-import static java.lang.Integer.parseInt;
import static org.apache.maven.surefire.booter.ProviderParameterNames.PARALLEL_PROP;
-import static org.apache.maven.surefire.booter.ProviderParameterNames.THREADCOUNT_PROP;
+import static org.apache.maven.surefire.util.ReflectionUtils.invokeSetter;
+import static org.apache.maven.surefire.util.ReflectionUtils.tryLoadClass;
/**
* TestNG 7.4.0 configurator. Changed setParallel type to enum value.
@@ -37,34 +36,42 @@ import static org.apache.maven.surefire.booter.ProviderParameterNames.THREADCOUN
* @since 3.0.0-M6
* @since 2.22.3
*/
-public class TestNG740Configurator extends TestNG60Configurator
+public class TestNG740Configurator
+ extends TestNG60Configurator
{
+ /**
+ * Convert and apply the value of the [parallel] setting.
+ * <p>
+ * <b>NOTE</b>: Since TestNG 7.4, the value of the {@code parallel} setting of the {@link XmlSuite} class has been
+ * specified via a <b>ParallelMode</b> enumeration. This method converts the [parallel] setting specified in the
+ * Surefire plugin configuration to its corresponding constant and applies this to the specified suite object.
+ *
+ * @param suite TestNG {@link XmlSuite} object
+ * @param options Surefire plugin configuration options
+ * @throws TestSetFailedException if unable to convert specified [parallel] setting
+ */
@Override
- public void configure( XmlSuite suite, Map<String, String> options )
+ protected void configureParallel( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
{
- String threadCountAsString = options.get( THREADCOUNT_PROP );
- int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
- suite.setThreadCount( threadCount );
-
String parallel = options.get( PARALLEL_PROP );
+ // if [parallel] spec'd
if ( parallel != null )
{
- if ( !"methods".equalsIgnoreCase( parallel ) && !"classes".equalsIgnoreCase( parallel ) )
+ // try to load the [ParallelMode] enumeration
+ Class enumClass = tryLoadClass( XmlSuite.class.getClassLoader(),
+ "org.testng.xml.XmlSuite$ParallelMode" ); // if enumeration loaded
+ try
{
- throw new TestSetFailedException( "Unsupported TestNG parallel setting: "
- + parallel + " ( only METHODS or CLASSES supported )" );
+ // convert [parallel] option to corresponding constant
+ Enum<?> parallelEnum = Enum.valueOf( enumClass, parallel.toUpperCase() );
+ // set [XmlSuite] parallel mode to specified value
+ invokeSetter( suite, "setParallel", enumClass, parallelEnum );
+ }
+ catch ( IllegalArgumentException e )
+ {
+ throw new TestSetFailedException( "Unsupported TestNG [parallel] setting: " + parallel, e );
}
- Class enumClass = ReflectionUtils.tryLoadClass( XmlSuite.class.getClassLoader(),
- "org.testng.xml.XmlSuite$ParallelMode" );
- Object parallelEnum = Enum.valueOf( enumClass, parallel.toUpperCase() );
- ReflectionUtils.invokeSetter( suite, "setParallel", enumClass, parallelEnum );
- }
-
- String dataProviderThreadCount = options.get( "dataproviderthreadcount" );
- if ( dataProviderThreadCount != null )
- {
- suite.setDataProviderThreadCount( Integer.parseInt( dataProviderThreadCount ) );
}
}
}
diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
index c51aca6cc..0cb47aa73 100755
--- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
+++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/conf/TestNGMapConfigurator.java
@@ -60,11 +60,22 @@ public class TestNGMapConfigurator
@Override
public void configure( XmlSuite suite, Map<String, String> options )
throws TestSetFailedException
+ {
+ configureThreadCount( suite, options );
+ configureParallel( suite, options );
+ }
+
+ protected void configureThreadCount( XmlSuite suite, Map<String, String> options )
+ throws TestSetFailedException
{
String threadCountAsString = options.get( THREADCOUNT_PROP );
int threadCount = threadCountAsString == null ? 1 : parseInt( threadCountAsString );
suite.setThreadCount( threadCount );
-
+ }
+
+ protected void configureParallel( XmlSuite suite, Map<String, String> options )
+ throws TestSetFailedException
+ {
String parallel = options.get( PARALLEL_PROP );
if ( parallel != null )
{