16
16
import java .util .Collections ;
17
17
import java .util .List ;
18
18
import java .util .Map ;
19
+ import java .util .Objects ;
19
20
import java .util .Optional ;
20
21
import java .util .ServiceLoader ;
21
22
import java .util .Set ;
58
59
import org .testng .reporters .VerboseReporter ;
59
60
import org .testng .reporters .XMLReporter ;
60
61
import org .testng .reporters .jq .Main ;
61
- import org .testng .thread .IExecutorFactory ;
62
62
import org .testng .thread .IThreadWorkerFactory ;
63
63
import org .testng .util .Strings ;
64
64
import org .testng .xml .IPostProcessor ;
@@ -151,8 +151,6 @@ public class TestNG {
151
151
private final Map <Class <? extends IDataProviderInterceptor >, IDataProviderInterceptor >
152
152
m_dataProviderInterceptors = Maps .newLinkedHashMap ();
153
153
154
- private IExecutorFactory m_executorFactory = null ;
155
-
156
154
public static final Integer DEFAULT_VERBOSE = 1 ;
157
155
158
156
// Command line suite parameters
@@ -843,10 +841,9 @@ public void setVerbose(int verbose) {
843
841
m_verbose = verbose ;
844
842
}
845
843
846
- /** This method stands deprecated as of TestNG <code>v7.9.0</code>. */
847
- @ Deprecated
848
- public void setExecutorFactoryClass (String clazzName ) {
849
- this .m_executorFactory = createExecutorFactoryInstanceUsing (clazzName );
844
+ public void setExecutorServiceFactory (IExecutorServiceFactory factory ) {
845
+ Objects .requireNonNull (factory );
846
+ m_configuration .setExecutorServiceFactory (factory );
850
847
}
851
848
852
849
public void setListenerFactory (ITestNGListenerFactory factory ) {
@@ -857,31 +854,6 @@ public void setGenerateResultsPerSuite(boolean generateResultsPerSuite) {
857
854
this .m_generateResultsPerSuite = generateResultsPerSuite ;
858
855
}
859
856
860
- private IExecutorFactory createExecutorFactoryInstanceUsing (String clazzName ) {
861
- Class <?> cls = ClassHelper .forName (clazzName );
862
- Object instance = m_objectFactory .newInstance (cls );
863
- if (instance instanceof IExecutorFactory ) {
864
- return (IExecutorFactory ) instance ;
865
- }
866
- throw new IllegalArgumentException (
867
- clazzName + " does not implement " + IExecutorFactory .class .getName ());
868
- }
869
-
870
- /** This method stands deprecated as of TestNG <code>v7.9.0</code>. */
871
- @ Deprecated
872
- public void setExecutorFactory (IExecutorFactory factory ) {
873
- this .m_executorFactory = factory ;
874
- }
875
-
876
- /** This method stands deprecated as of TestNG <code>v7.9.0</code>. */
877
- @ Deprecated
878
- public IExecutorFactory getExecutorFactory () {
879
- if (this .m_executorFactory == null ) {
880
- this .m_executorFactory = createExecutorFactoryInstanceUsing (DEFAULT_THREADPOOL_FACTORY );
881
- }
882
- return this .m_executorFactory ;
883
- }
884
-
885
857
private void initializeCommandLineSuites () {
886
858
if (m_commandLineTestClasses != null || m_commandLineMethods != null ) {
887
859
if (null != m_commandLineMethods ) {
@@ -1018,7 +990,6 @@ private void initializeConfiguration() {
1018
990
m_configuration .setConfigurable (m_configurable );
1019
991
m_configuration .setObjectFactory (factory );
1020
992
m_configuration .setAlwaysRunListeners (this .m_alwaysRun );
1021
- m_configuration .setExecutorFactory (getExecutorFactory ());
1022
993
}
1023
994
1024
995
private void addListeners (XmlSuite s ) {
@@ -1514,9 +1485,13 @@ protected void configure(CommandLineArgs cla) {
1514
1485
m_objectFactory .newInstance ((Class <IInjectorFactory >) clazz ));
1515
1486
}
1516
1487
}
1517
- if (cla .threadPoolFactoryClass != null ) {
1518
- setExecutorFactoryClass (cla .threadPoolFactoryClass );
1519
- }
1488
+ Optional .ofNullable (cla .threadPoolFactoryClass )
1489
+ .map (ClassHelper ::forName )
1490
+ .filter (IExecutorServiceFactory .class ::isAssignableFrom )
1491
+ .map (it -> m_objectFactory .newInstance (it ))
1492
+ .map (it -> (IExecutorServiceFactory ) it )
1493
+ .ifPresent (this ::setExecutorServiceFactory );
1494
+
1520
1495
setOutputDirectory (cla .outputDirectory );
1521
1496
1522
1497
String testClasses = cla .testClass ;
0 commit comments