Skip to content

Commit 1e943fc

Browse files
committed
Fixing review comments
1 parent b78ef23 commit 1e943fc

File tree

6 files changed

+33
-92
lines changed

6 files changed

+33
-92
lines changed

testng-core-api/src/main/java/org/testng/internal/RuntimeBehavior.java

-9
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,6 @@ public static boolean ignoreCallbackInvocationSkips() {
2929
return Boolean.getBoolean(IGNORE_CALLBACK_INVOCATION_SKIPS);
3030
}
3131

32-
/**
33-
* @return - <code>true</code> if TestNG is to be using its custom implementation of {@link
34-
* java.util.concurrent.ThreadPoolExecutor} for running concurrent tests. Defaults to <code>
35-
* false</code>
36-
*/
37-
public static boolean favourCustomThreadPoolExecutor() {
38-
return Boolean.getBoolean(FAVOR_CUSTOM_THREAD_POOL_EXECUTOR);
39-
}
40-
4132
/**
4233
* @return - A comma separated list of packages that represent special listeners which users will
4334
* expect to be executed after executing the regular listeners. Here special listeners can be

testng-core/src/main/java/org/testng/SuiteTaskExecutor.java

+12-17
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import java.util.concurrent.ExecutorService;
55
import java.util.concurrent.TimeUnit;
66
import org.testng.internal.IConfiguration;
7-
import org.testng.internal.RuntimeBehavior;
87
import org.testng.internal.Utils;
98
import org.testng.internal.thread.TestNGThreadFactory;
109
import org.testng.internal.thread.graph.GraphOrchestrator;
@@ -38,22 +37,18 @@ public SuiteTaskExecutor(
3837

3938
public void execute() {
4039
String name = "suites-";
41-
if (RuntimeBehavior.favourCustomThreadPoolExecutor()) {
42-
throw new UnsupportedOperationException("This is NO LONGER Supported in TestNG");
43-
} else {
44-
service =
45-
this.configuration
46-
.getExecutorServiceFactory()
47-
.create(
48-
threadPoolSize,
49-
threadPoolSize,
50-
Integer.MAX_VALUE,
51-
TimeUnit.MILLISECONDS,
52-
queue,
53-
new TestNGThreadFactory(name));
54-
GraphOrchestrator<ISuite> executor = new GraphOrchestrator<>(service, factory, graph, null);
55-
executor.run();
56-
}
40+
service =
41+
this.configuration
42+
.getExecutorServiceFactory()
43+
.create(
44+
threadPoolSize,
45+
threadPoolSize,
46+
Integer.MAX_VALUE,
47+
TimeUnit.MILLISECONDS,
48+
queue,
49+
new TestNGThreadFactory(name));
50+
GraphOrchestrator<ISuite> executor = new GraphOrchestrator<>(service, factory, graph, null);
51+
executor.run();
5752
}
5853

5954
public void awaitCompletion() {

testng-core/src/main/java/org/testng/TestNG.java

+2-11
Original file line numberDiff line numberDiff line change
@@ -842,8 +842,8 @@ public void setVerbose(int verbose) {
842842
}
843843

844844
public void setExecutorServiceFactory(IExecutorServiceFactory factory) {
845-
Objects.requireNonNull(factory);
846-
m_configuration.setExecutorServiceFactory(factory);
845+
m_configuration.setExecutorServiceFactory(
846+
Objects.requireNonNull(factory, "ExecutorServiceFactory cannot be null"));
847847
}
848848

849849
public void setListenerFactory(ITestNGListenerFactory factory) {
@@ -1188,11 +1188,9 @@ public List<ISuite> runSuitesLocally() {
11881188
// Create a map with XmlSuite as key and corresponding SuiteRunner as value
11891189
for (XmlSuite xmlSuite : m_suites) {
11901190
if (m_configuration.isShareThreadPoolForDataProviders()) {
1191-
abortIfUsingGraphThreadPoolExecutor("Shared thread-pool for data providers");
11921191
xmlSuite.setShareThreadPoolForDataProviders(true);
11931192
}
11941193
if (m_configuration.useGlobalThreadPool()) {
1195-
abortIfUsingGraphThreadPoolExecutor("Global thread-pool");
11961194
xmlSuite.shouldUseGlobalThreadPool(true);
11971195
}
11981196
createSuiteRunners(suiteRunnerMap, xmlSuite);
@@ -1243,13 +1241,6 @@ private static void error(String s) {
12431241
LOGGER.error(s);
12441242
}
12451243

1246-
private static void abortIfUsingGraphThreadPoolExecutor(String prefix) {
1247-
if (RuntimeBehavior.favourCustomThreadPoolExecutor()) {
1248-
throw new UnsupportedOperationException(
1249-
prefix + " is NOT COMPATIBLE with TestNG's custom thread pool executor");
1250-
}
1251-
}
1252-
12531244
/**
12541245
* @return the verbose level, checking in order: the verbose level on the suite, the verbose level
12551246
* on the TestNG object, or 1.

testng-core/src/main/java/org/testng/TestTaskExecutor.java

+19-25
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.util.function.Supplier;
88
import org.testng.internal.IConfiguration;
99
import org.testng.internal.ObjectBag;
10-
import org.testng.internal.RuntimeBehavior;
1110
import org.testng.internal.Utils;
1211
import org.testng.internal.thread.TestNGThreadFactory;
1312
import org.testng.internal.thread.graph.GraphOrchestrator;
@@ -47,32 +46,27 @@ public TestTaskExecutor(
4746
public void execute() {
4847
String name = "test-" + xmlTest.getName();
4948
int threadCount = Math.max(xmlTest.getThreadCount(), 1);
50-
if (RuntimeBehavior.favourCustomThreadPoolExecutor()) {
51-
throw new UnsupportedOperationException("This is NO LONGER Supported in TestNG");
52-
49+
boolean reUse = xmlTest.getSuite().useGlobalThreadPool();
50+
Supplier<Object> supplier =
51+
() ->
52+
configuration
53+
.getExecutorServiceFactory()
54+
.create(
55+
threadCount,
56+
threadCount,
57+
0,
58+
TimeUnit.MILLISECONDS,
59+
queue,
60+
new TestNGThreadFactory(name));
61+
if (reUse) {
62+
ObjectBag bag = ObjectBag.getInstance(xmlTest.getSuite());
63+
service = (ExecutorService) bag.createIfRequired(ExecutorService.class, supplier);
5364
} else {
54-
boolean reUse = xmlTest.getSuite().useGlobalThreadPool();
55-
Supplier<Object> supplier =
56-
() ->
57-
configuration
58-
.getExecutorServiceFactory()
59-
.create(
60-
threadCount,
61-
threadCount,
62-
0,
63-
TimeUnit.MILLISECONDS,
64-
queue,
65-
new TestNGThreadFactory(name));
66-
if (reUse) {
67-
ObjectBag bag = ObjectBag.getInstance(xmlTest.getSuite());
68-
service = (ExecutorService) bag.createIfRequired(ExecutorService.class, supplier);
69-
} else {
70-
service = (ExecutorService) supplier.get();
71-
}
72-
GraphOrchestrator<ITestNGMethod> executor =
73-
new GraphOrchestrator<>(service, factory, graph, comparator);
74-
executor.run();
65+
service = (ExecutorService) supplier.get();
7566
}
67+
GraphOrchestrator<ITestNGMethod> executor =
68+
new GraphOrchestrator<>(service, factory, graph, comparator);
69+
executor.run();
7670
}
7771

7872
public void awaitCompletion() {

testng-core/src/test/java/test/dataprovider/DataProviderTest.java

-15
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import org.testng.annotations.DataProvider;
1919
import org.testng.annotations.Test;
2020
import org.testng.collections.Lists;
21-
import org.testng.internal.RuntimeBehavior;
2221
import org.testng.internal.collections.Pair;
2322
import org.testng.internal.reflect.MethodMatcherException;
2423
import org.testng.xml.XmlClass;
@@ -615,20 +614,6 @@ public void ensureSequentialDataProviderWithRetryAnalyserWorks() {
615614
runTest(false);
616615
}
617616

618-
@Test(
619-
description = "GITHUB-2980",
620-
expectedExceptions = UnsupportedOperationException.class,
621-
expectedExceptionsMessageRegExp =
622-
"Shared thread-pool for data providers is NOT COMPATIBLE with TestNG's custom thread pool executor")
623-
public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() {
624-
try {
625-
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true");
626-
runDataProviderTest(true);
627-
} finally {
628-
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false");
629-
}
630-
}
631-
632617
@Test(description = "GITHUB-2980", dataProvider = "dataProviderForIssue2980")
633618
public void ensureWeCanShareThreadPoolForDataProviders(
634619
boolean flag, Pair<List<String>, Integer> pair) {

testng-core/src/test/java/test/thread/SharedThreadPoolTest.java

-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import org.testng.TestNG;
1010
import org.testng.annotations.AfterMethod;
1111
import org.testng.annotations.Test;
12-
import org.testng.internal.RuntimeBehavior;
1312
import org.testng.xml.XmlSuite;
1413
import test.SimpleBaseTest;
1514
import test.thread.issue2019.TestClassSample;
@@ -38,20 +37,6 @@ public void ensureCommonThreadPoolIsNotUsed() {
3837
.hasSizeGreaterThanOrEqualTo(3);
3938
}
4039

41-
@Test(
42-
description = "GITHUB-2019",
43-
expectedExceptions = UnsupportedOperationException.class,
44-
expectedExceptionsMessageRegExp =
45-
"Global thread-pool is NOT COMPATIBLE with TestNG's custom thread pool executor")
46-
public void ensureErrorShownWhenUsedWithGraphThreadPoolExecutor() {
47-
try {
48-
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "true");
49-
runSimpleTest(true);
50-
} finally {
51-
System.setProperty(RuntimeBehavior.FAVOR_CUSTOM_THREAD_POOL_EXECUTOR, "false");
52-
}
53-
}
54-
5540
private static List<Long> runSimpleTest(boolean useSharedGlobalThreadPool) {
5641
TestNG testng = create(TestClassSample.class);
5742
testng.shouldUseGlobalThreadPool(useSharedGlobalThreadPool);

0 commit comments

Comments
 (0)