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

[SUREFIRE-2064] Allow all supported values of [parallel] option #517

Merged
merged 1 commit into from Apr 23, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -24,9 +24,7 @@

import java.util.Map;

import static java.lang.Integer.parseInt;
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.PARALLEL_PROP;
import static org.apache.maven.surefire.api.booter.ProviderParameterNames.THREADCOUNT_PROP;
import static org.apache.maven.surefire.api.util.ReflectionUtils.invokeSetter;
import static org.apache.maven.surefire.api.util.ReflectionUtils.tryLoadClass;

Expand All @@ -37,33 +35,50 @@
*
* @since 3.0.0-M6
*/
public class TestNG740Configurator extends TestNG60Configurator
public class TestNG740Configurator
extends TestNG60Configurator
sbabcoc marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* 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
if ( enumClass != null )
{
throw new TestSetFailedException( "Unsupported TestNG parallel setting: "
+ parallel + " ( only METHODS or CLASSES supported )" );
try
{
// 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 );
}
}
else
{
throw new TestSetFailedException(
"Failed loading TestNG [ParallelMode] enumeration to convert [parallel] setting: " + parallel );
}
Class enumClass = tryLoadClass( XmlSuite.class.getClassLoader(), "org.testng.xml.XmlSuite$ParallelMode" );
Enum<?> parallelEnum = Enum.valueOf( enumClass, parallel.toUpperCase() );
invokeSetter( suite, "setParallel", enumClass, parallelEnum );
}

String dataProviderThreadCount = options.get( "dataproviderthreadcount" );
if ( dataProviderThreadCount != null )
{
suite.setDataProviderThreadCount( Integer.parseInt( dataProviderThreadCount ) );
}
}
}
Expand Up @@ -60,11 +60,22 @@ public void configure( TestNG testng, Map<String, String> options )
@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 )
{
Expand Down