Skip to content

Commit b8df67b

Browse files
committed
Add support for non-fork-join test executor
1 parent 84ac590 commit b8df67b

File tree

9 files changed

+1188
-47
lines changed

9 files changed

+1188
-47
lines changed

junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/Constants.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@
1515
import static org.apiguardian.api.API.Status.STABLE;
1616
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_CUSTOM_CLASS_PROPERTY_NAME;
1717
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME;
18+
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME;
1819
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_MAX_POOL_SIZE_PROPERTY_NAME;
1920
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_PARALLELISM_PROPERTY_NAME;
2021
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_SATURATE_PROPERTY_NAME;
22+
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME;
2123
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_STRATEGY_PROPERTY_NAME;
2224

2325
import org.apiguardian.api.API;
@@ -176,7 +178,7 @@ public final class Constants {
176178
* {@value #PARALLEL_CONFIG_FIXED_PARALLELISM_PROPERTY_NAME}; defaults to
177179
* {@code 256 + fixed.parallelism}.
178180
*
179-
* <p>Note: This property only takes affect on Java 9+.
181+
* <p>Note: This property only takes effect on Java 9+.
180182
*
181183
* @since 5.10
182184
*/
@@ -194,14 +196,27 @@ public final class Constants {
194196
195197
* <p>Value must either {@code true} or {@code false}; defaults to {@code true}.
196198
*
197-
* <p>Note: This property only takes affect on Java 9+.
199+
* <p>Note: This property only takes effect on Java 9+.
198200
*
199201
* @since 5.10
200202
*/
201203
@API(status = EXPERIMENTAL, since = "5.10")
202204
public static final String PARALLEL_CONFIG_FIXED_SATURATE_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
203205
+ CONFIG_FIXED_SATURATE_PROPERTY_NAME;
204206

207+
/**
208+
* Property name used to set the type of test executor
209+
* (which directly relates to the type of thread pool used)
210+
* for the {@code fixed} configuration strategy: {@value}
211+
*
212+
* <p>Value must be either {@code fork_join} or {@code fixed_threads}; defaults to {@code fork_join}.
213+
*
214+
* @since 5.11
215+
*/
216+
@API(status = EXPERIMENTAL, since = "5.11")
217+
public static final String PARALLEL_CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
218+
+ CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME;
219+
205220
/**
206221
* Property name used to set the factor to be multiplied with the number of
207222
* available processors/cores to determine the desired parallelism for the
@@ -215,6 +230,19 @@ public final class Constants {
215230
public static final String PARALLEL_CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
216231
+ CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME;
217232

233+
/**
234+
* Property name used to set the type of test executor
235+
* (which directly relates to the type of thread pool used)
236+
* for the {@code dynamic} configuration strategy: {@value}
237+
*
238+
* <p>Value must be either {@code fork_join} or {@code fixed_threads}; defaults to {@code fork_join}.
239+
*
240+
* @since 5.11
241+
*/
242+
@API(status = EXPERIMENTAL, since = "5.11")
243+
public static final String PARALLEL_CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
244+
+ CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME;
245+
218246
/**
219247
* Property name used to specify the fully qualified class name of the
220248
* {@link ParallelExecutionConfigurationStrategy} to be used for the

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/DefaultParallelExecutionConfiguration.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,17 @@ class DefaultParallelExecutionConfiguration implements ParallelExecutionConfigur
2424
private final int corePoolSize;
2525
private final int keepAliveSeconds;
2626
private final Predicate<? super ForkJoinPool> saturate;
27+
private final TestExecutor testExecutor;
2728

2829
DefaultParallelExecutionConfiguration(int parallelism, int minimumRunnable, int maxPoolSize, int corePoolSize,
29-
int keepAliveSeconds, Predicate<? super ForkJoinPool> saturate) {
30+
int keepAliveSeconds, Predicate<? super ForkJoinPool> saturate, TestExecutor testExecutor) {
3031
this.parallelism = parallelism;
3132
this.minimumRunnable = minimumRunnable;
3233
this.maxPoolSize = maxPoolSize;
3334
this.corePoolSize = corePoolSize;
3435
this.keepAliveSeconds = keepAliveSeconds;
3536
this.saturate = saturate;
37+
this.testExecutor = testExecutor;
3638
}
3739

3840
@Override
@@ -64,4 +66,9 @@ public int getKeepAliveSeconds() {
6466
public Predicate<? super ForkJoinPool> getSaturatePredicate() {
6567
return saturate;
6668
}
69+
70+
@Override
71+
public TestExecutor getTestExecutor() {
72+
return testExecutor;
73+
}
6774
}

junit-platform-engine/src/main/java/org/junit/platform/engine/support/hierarchical/DefaultParallelExecutionConfigurationStrategy.java

+30-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import static org.apiguardian.api.API.Status.EXPERIMENTAL;
1414
import static org.apiguardian.api.API.Status.STABLE;
15+
import static org.junit.platform.engine.support.hierarchical.ParallelExecutionConfiguration.TestExecutor;
1516

1617
import java.math.BigDecimal;
1718
import java.util.Locale;
@@ -21,6 +22,7 @@
2122
import org.junit.platform.commons.util.Preconditions;
2223
import org.junit.platform.commons.util.ReflectionUtils;
2324
import org.junit.platform.engine.ConfigurationParameters;
25+
import org.junit.platform.engine.TestDescriptor;
2426

2527
/**
2628
* Default implementations of configuration strategies for parallel test
@@ -49,8 +51,11 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
4951
boolean saturate = configurationParameters.get(CONFIG_FIXED_SATURATE_PROPERTY_NAME,
5052
Boolean::valueOf).orElse(true);
5153

54+
TestExecutor testExecutor = configurationParameters.get(CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME,
55+
(str) -> TestExecutor.valueOf(str.toUpperCase())).orElse(TestExecutor.FORK_JOIN);
56+
5257
return new DefaultParallelExecutionConfiguration(parallelism, parallelism, maxPoolSize, parallelism,
53-
KEEP_ALIVE_SECONDS, __ -> saturate);
58+
KEEP_ALIVE_SECONDS, __ -> saturate, testExecutor);
5459
}
5560
},
5661

@@ -84,8 +89,11 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
8489
boolean saturate = configurationParameters.get(CONFIG_DYNAMIC_SATURATE_PROPERTY_NAME,
8590
Boolean::valueOf).orElse(true);
8691

92+
TestExecutor testExecutor = configurationParameters.get(CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME,
93+
(str) -> TestExecutor.valueOf(str.toUpperCase())).orElse(TestExecutor.FORK_JOIN);
94+
8795
return new DefaultParallelExecutionConfiguration(parallelism, parallelism, maxPoolSize, parallelism,
88-
KEEP_ALIVE_SECONDS, __ -> saturate);
96+
KEEP_ALIVE_SECONDS, __ -> saturate, testExecutor);
8997
}
9098
},
9199

@@ -163,6 +171,16 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
163171
@API(status = EXPERIMENTAL, since = "1.10")
164172
public static final String CONFIG_FIXED_SATURATE_PROPERTY_NAME = "fixed.saturate";
165173

174+
/**
175+
* Property name used to disable saturation of the underlying thread pool
176+
* used to execute {@linkplain TestDescriptor.Type#TEST test tasks}
177+
* for the {@link #FIXED} configuration strategy.
178+
*
179+
* @since 1.11
180+
*/
181+
@API(status = EXPERIMENTAL, since = "1.11")
182+
public static final String CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME = "fixed.test-executor";
183+
166184
/**
167185
* Property name of the factor used to determine the desired parallelism for the
168186
* {@link #DYNAMIC} configuration strategy.
@@ -207,6 +225,16 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
207225
@API(status = EXPERIMENTAL, since = "1.10")
208226
public static final String CONFIG_DYNAMIC_SATURATE_PROPERTY_NAME = "dynamic.saturate";
209227

228+
/**
229+
* Property name used to disable saturation of the underlying thread pool
230+
* used to execute {@linkplain TestDescriptor.Type#TEST test tasks}
231+
* for the {@link #DYNAMIC} configuration strategy.
232+
*
233+
* @since 1.11
234+
*/
235+
@API(status = EXPERIMENTAL, since = "1.11")
236+
public static final String CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME = "dynamic.test-executor";
237+
210238
/**
211239
* Property name used to specify the fully qualified class name of the
212240
* {@link ParallelExecutionConfigurationStrategy} to be used by the

0 commit comments

Comments
 (0)