Skip to content

Commit

Permalink
Add configuration parameter
Browse files Browse the repository at this point in the history
Issue: #2229
Signed-off-by: yongjunhong <kevin0928@naver.com>
  • Loading branch information
YongGoose committed Dec 5, 2024
1 parent 56ea4b9 commit e0312cc
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ public final class VintageTestEngine implements TestEngine {

private static final int DEFAULT_THREAD_POOL_SIZE = Runtime.getRuntime().availableProcessors();
private static final int SHUTDOWN_TIMEOUT_SECONDS = 30;
private static final String PARALLEL_EXECUTION_ENABLED = "junit.jupiter.execution.parallel.enabled";
private static final String PARALLEL_POOL_SIZE = "junit.vintage.execution.parallel.pool-size";

@Override
public String getId() {
Expand Down Expand Up @@ -84,25 +86,25 @@ public void execute(ExecutionRequest request) {
EngineExecutionListener engineExecutionListener = request.getEngineExecutionListener();
VintageEngineDescriptor engineDescriptor = (VintageEngineDescriptor) request.getRootTestDescriptor();
engineExecutionListener.executionStarted(engineDescriptor);
executeAllChildren(engineDescriptor, engineExecutionListener);
executeAllChildren(engineDescriptor, engineExecutionListener, request);
engineExecutionListener.executionFinished(engineDescriptor, successful());
}

private void executeAllChildren(VintageEngineDescriptor engineDescriptor,
EngineExecutionListener engineExecutionListener) {
boolean parallelExecutionEnabled = getParallelExecutionEnabled();
EngineExecutionListener engineExecutionListener, ExecutionRequest request) {
boolean parallelExecutionEnabled = getParallelExecutionEnabled(request);

if (parallelExecutionEnabled) {
executeInParallel(engineDescriptor, engineExecutionListener);
executeInParallel(engineDescriptor, engineExecutionListener, request);
}
else {
executeSequentially(engineDescriptor, engineExecutionListener);
}
}

private void executeInParallel(VintageEngineDescriptor engineDescriptor,
EngineExecutionListener engineExecutionListener) {
ExecutorService executorService = Executors.newFixedThreadPool(getThreadPoolSize());
EngineExecutionListener engineExecutionListener, ExecutionRequest request) {
ExecutorService executorService = Executors.newFixedThreadPool(getThreadPoolSize(request));
RunnerExecutor runnerExecutor = new RunnerExecutor(engineExecutionListener);

List<CompletableFuture<Void>> futures = new ArrayList<>();
Expand Down Expand Up @@ -161,13 +163,20 @@ private void executeSequentially(VintageEngineDescriptor engineDescriptor,
}
}

private boolean getParallelExecutionEnabled() {
// get parallel execution enabled from configuration
return true;
private boolean getParallelExecutionEnabled(ExecutionRequest request) {
return request.getConfigurationParameters().getBoolean(PARALLEL_EXECUTION_ENABLED).orElse(false);
}

private int getThreadPoolSize() {
// get thread pool size from configuration
private int getThreadPoolSize(ExecutionRequest request) {
Optional<String> poolSize = request.getConfigurationParameters().get(PARALLEL_POOL_SIZE);
if (poolSize.isPresent()) {
try {
return Integer.parseInt(poolSize.get());
}
catch (NumberFormatException e) {
logger.warn(() -> "Invalid value for parallel pool size: " + poolSize.get());
}
}
return DEFAULT_THREAD_POOL_SIZE;
}

Expand Down

0 comments on commit e0312cc

Please sign in to comment.