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

Add support for non-fork-join test executor #3685

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
import static org.apiguardian.api.API.Status.STABLE;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_CUSTOM_CLASS_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_MAX_POOL_SIZE_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_PARALLELISM_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_SATURATE_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME;
import static org.junit.platform.engine.support.hierarchical.DefaultParallelExecutionConfigurationStrategy.CONFIG_STRATEGY_PROPERTY_NAME;

import org.apiguardian.api.API;
Expand Down Expand Up @@ -176,7 +178,7 @@ public final class Constants {
* {@value #PARALLEL_CONFIG_FIXED_PARALLELISM_PROPERTY_NAME}; defaults to
* {@code 256 + fixed.parallelism}.
*
* <p>Note: This property only takes affect on Java 9+.
* <p>Note: This property only takes effect on Java 9+.
*
* @since 5.10
*/
Expand All @@ -194,14 +196,27 @@ public final class Constants {

* <p>Value must either {@code true} or {@code false}; defaults to {@code true}.
*
* <p>Note: This property only takes affect on Java 9+.
* <p>Note: This property only takes effect on Java 9+.
*
* @since 5.10
*/
@API(status = EXPERIMENTAL, since = "5.10")
public static final String PARALLEL_CONFIG_FIXED_SATURATE_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
+ CONFIG_FIXED_SATURATE_PROPERTY_NAME;

/**
* Property name used to set the type of test executor
* (which directly relates to the type of thread pool used)
* for the {@code fixed} configuration strategy: {@value}
*
* <p>Value must be either {@code fork_join} or {@code fixed_threads}; defaults to {@code fork_join}.
*
* @since 5.11
*/
@API(status = EXPERIMENTAL, since = "5.11")
public static final String PARALLEL_CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
+ CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME;

/**
* Property name used to set the factor to be multiplied with the number of
* available processors/cores to determine the desired parallelism for the
Expand All @@ -215,6 +230,19 @@ public final class Constants {
public static final String PARALLEL_CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
+ CONFIG_DYNAMIC_FACTOR_PROPERTY_NAME;

/**
* Property name used to set the type of test executor
* (which directly relates to the type of thread pool used)
* for the {@code dynamic} configuration strategy: {@value}
*
* <p>Value must be either {@code fork_join} or {@code fixed_threads}; defaults to {@code fork_join}.
*
* @since 5.11
*/
@API(status = EXPERIMENTAL, since = "5.11")
public static final String PARALLEL_CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME = PARALLEL_CONFIG_PREFIX
+ CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME;

/**
* Property name used to specify the fully qualified class name of the
* {@link ParallelExecutionConfigurationStrategy} to be used for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@ class DefaultParallelExecutionConfiguration implements ParallelExecutionConfigur
private final int corePoolSize;
private final int keepAliveSeconds;
private final Predicate<? super ForkJoinPool> saturate;
private final TestExecutor testExecutor;

DefaultParallelExecutionConfiguration(int parallelism, int minimumRunnable, int maxPoolSize, int corePoolSize,
int keepAliveSeconds, Predicate<? super ForkJoinPool> saturate) {
int keepAliveSeconds, Predicate<? super ForkJoinPool> saturate, TestExecutor testExecutor) {
this.parallelism = parallelism;
this.minimumRunnable = minimumRunnable;
this.maxPoolSize = maxPoolSize;
this.corePoolSize = corePoolSize;
this.keepAliveSeconds = keepAliveSeconds;
this.saturate = saturate;
this.testExecutor = testExecutor;
}

@Override
Expand Down Expand Up @@ -64,4 +66,9 @@ public int getKeepAliveSeconds() {
public Predicate<? super ForkJoinPool> getSaturatePredicate() {
return saturate;
}

@Override
public TestExecutor getTestExecutor() {
return testExecutor;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import static org.apiguardian.api.API.Status.EXPERIMENTAL;
import static org.apiguardian.api.API.Status.STABLE;
import static org.junit.platform.engine.support.hierarchical.ParallelExecutionConfiguration.TestExecutor;

import java.math.BigDecimal;
import java.util.Locale;
Expand All @@ -21,6 +22,7 @@
import org.junit.platform.commons.util.Preconditions;
import org.junit.platform.commons.util.ReflectionUtils;
import org.junit.platform.engine.ConfigurationParameters;
import org.junit.platform.engine.TestDescriptor;

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

TestExecutor testExecutor = configurationParameters.get(CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME,
(str) -> TestExecutor.valueOf(str.toUpperCase())).orElse(TestExecutor.FORK_JOIN);

return new DefaultParallelExecutionConfiguration(parallelism, parallelism, maxPoolSize, parallelism,
KEEP_ALIVE_SECONDS, __ -> saturate);
KEEP_ALIVE_SECONDS, __ -> saturate, testExecutor);
}
},

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

TestExecutor testExecutor = configurationParameters.get(CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME,
(str) -> TestExecutor.valueOf(str.toUpperCase())).orElse(TestExecutor.FORK_JOIN);

return new DefaultParallelExecutionConfiguration(parallelism, parallelism, maxPoolSize, parallelism,
KEEP_ALIVE_SECONDS, __ -> saturate);
KEEP_ALIVE_SECONDS, __ -> saturate, testExecutor);
}
},

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

/**
* Property name used to disable saturation of the underlying thread pool
* used to execute {@linkplain TestDescriptor.Type#TEST test tasks}
* for the {@link #FIXED} configuration strategy.
*
* @since 1.11
*/
@API(status = EXPERIMENTAL, since = "1.11")
public static final String CONFIG_FIXED_TEST_EXECUTOR_PROPERTY_NAME = "fixed.test-executor";

/**
* Property name of the factor used to determine the desired parallelism for the
* {@link #DYNAMIC} configuration strategy.
Expand Down Expand Up @@ -207,6 +225,16 @@ public ParallelExecutionConfiguration createConfiguration(ConfigurationParameter
@API(status = EXPERIMENTAL, since = "1.10")
public static final String CONFIG_DYNAMIC_SATURATE_PROPERTY_NAME = "dynamic.saturate";

/**
* Property name used to disable saturation of the underlying thread pool
* used to execute {@linkplain TestDescriptor.Type#TEST test tasks}
* for the {@link #DYNAMIC} configuration strategy.
*
* @since 1.11
*/
@API(status = EXPERIMENTAL, since = "1.11")
public static final String CONFIG_DYNAMIC_TEST_EXECUTOR_PROPERTY_NAME = "dynamic.test-executor";

/**
* Property name used to specify the fully qualified class name of the
* {@link ParallelExecutionConfigurationStrategy} to be used by the
Expand Down
Loading
Loading