nonBlockers = Collections.synchronizedList(new ArrayList<>());
-
- public ConfigurableParallelComputer() {
- this(true, true, Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY), false);
- }
-
- public ConfigurableParallelComputer(boolean fClasses, boolean fMethods) {
- this(fClasses, fMethods, Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY), false);
- }
-
- public ConfigurableParallelComputer(boolean fClasses, boolean fMethods, Integer numberOfThreads, boolean perCore) {
- this(
- fClasses,
- fMethods,
- Executors.newFixedThreadPool(
- numberOfThreads * (perCore ? Runtime.getRuntime().availableProcessors() : 1),
- DAEMON_THREAD_FACTORY),
- true);
- }
-
- private ConfigurableParallelComputer(
- boolean fClasses, boolean fMethods, ExecutorService executorService, boolean fixedPool) {
- this.fClasses = fClasses;
- this.fMethods = fMethods;
- fService = executorService;
- this.fixedPool = fixedPool;
- }
-
- @SuppressWarnings({"UnusedDeclaration"})
- public void close() throws ExecutionException {
- for (AsynchronousRunner nonBlocker : nonBlockers) {
- nonBlocker.waitForCompletion();
- }
-
- fService.shutdown();
- try {
- if (!fService.awaitTermination(10, java.util.concurrent.TimeUnit.SECONDS)) {
- throw new RuntimeException("Executor did not shut down within timeout");
- }
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
- }
- }
-
- private Runner parallelize(Runner runner, RunnerScheduler runnerInterceptor) {
- if (runner instanceof ParentRunner>) {
- ((ParentRunner>) runner).setScheduler(runnerInterceptor);
- }
- return runner;
- }
-
- private RunnerScheduler getMethodInterceptor() {
- if (fClasses && fMethods) {
- final AsynchronousRunner blockingAsynchronousRunner = new AsynchronousRunner(fService);
- nonBlockers.add(blockingAsynchronousRunner);
- return blockingAsynchronousRunner;
- }
- return fMethods ? new AsynchronousRunner(fService) : new SynchronousRunner();
- }
-
- private RunnerScheduler getClassInterceptor() {
- if (fClasses) {
- return fMethods ? new SynchronousRunner() : new AsynchronousRunner(fService);
- }
- return new SynchronousRunner();
- }
-
- @Override
- public Runner getSuite(RunnerBuilder builder, java.lang.Class>[] classes) throws InitializationError {
- Runner suite = super.getSuite(builder, classes);
- return fClasses ? parallelize(suite, getClassInterceptor()) : suite;
- }
-
- @Override
- protected Runner getRunner(RunnerBuilder builder, Class> testClass) throws Throwable {
- Runner runner = super.getRunner(builder, testClass);
- return fMethods && !isTestSuite(testClass) ? parallelize(runner, getMethodInterceptor()) : runner;
- }
-
- private boolean isTestSuite(Class> testClass) {
- // Todo: Find out how/if this is enough
- final Suite.SuiteClasses annotation = testClass.getAnnotation(Suite.SuiteClasses.class);
- return (annotation != null);
- }
-
- @Override
- public String toString() {
- return "ConfigurableParallelComputer{" + "classes=" + fClasses + ", methods=" + fMethods + ", fixedPool="
- + fixedPool + '}';
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/FilteringRequest.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/FilteringRequest.java
deleted file mode 100644
index 96b410a6e9..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/FilteringRequest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import org.junit.runner.Request;
-import org.junit.runner.Runner;
-import org.junit.runner.manipulation.Filter;
-import org.junit.runner.manipulation.NoTestsRemainException;
-
-/**
- * Moved nested class from {@link JUnitCoreWrapper}.
- */
-final class FilteringRequest extends Request {
- private Runner filteredRunner;
-
- FilteringRequest(Request req, Filter filter) {
- try {
- Runner runner = req.getRunner();
- filter.apply(runner);
- filteredRunner = runner;
- } catch (NoTestsRemainException e) {
- filteredRunner = null;
- }
- }
-
- @Override
- public Runner getRunner() {
- return filteredRunner;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCore.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCore.java
deleted file mode 100644
index d4101ce8a0..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCore.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.common.junit4.Notifier;
-import org.junit.runner.Result;
-import org.junit.runner.Runner;
-import org.junit.runner.notification.RunListener;
-
-/**
- * JUnitCore solves bugs in original junit class {@link org.junit.runner.JUnitCore}.
- * The notifier method {@link org.junit.runner.notification.RunNotifier#fireTestRunFinished}
- * is called anyway in finally block.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.19
- * @see JUnit issue 1186
- */
-class JUnitCore {
- private final Notifier notifier;
-
- JUnitCore(Notifier notifier) {
- this.notifier = notifier;
- }
-
- Result run(Runner runner) throws TestSetFailedException {
- Result result = new Result();
- RunListener listener = result.createListener();
- notifier.addFirstListener(listener);
- try {
- notifier.fireTestRunStarted(runner.getDescription());
- runner.run(notifier);
- } catch (Throwable e) {
- afterException(e);
- } finally {
- notifier.fireTestRunFinished(result);
- notifier.removeListener(listener);
- afterFinished();
- }
- return result;
- }
-
- protected void afterException(Throwable e) throws TestSetFailedException {
- throw new TestSetFailedException(e);
- }
-
- protected void afterFinished() {}
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
deleted file mode 100644
index 51eea78d40..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreParameters.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.maven.surefire.api.booter.ProviderParameterNames;
-
-/**
- * @author Kristian Rosenvold
- */
-public final class JUnitCoreParameters {
- public static final String PARALLEL_KEY = ProviderParameterNames.PARALLEL_PROP;
-
- public static final String PERCORETHREADCOUNT_KEY = "perCoreThreadCount";
-
- public static final String THREADCOUNT_KEY = ProviderParameterNames.THREADCOUNT_PROP;
-
- public static final String THREADCOUNTSUITES_KEY = ProviderParameterNames.THREADCOUNTSUITES_PROP;
-
- public static final String THREADCOUNTCLASSES_KEY = ProviderParameterNames.THREADCOUNTCLASSES_PROP;
-
- public static final String THREADCOUNTMETHODS_KEY = ProviderParameterNames.THREADCOUNTMETHODS_PROP;
-
- public static final String USEUNLIMITEDTHREADS_KEY = "useUnlimitedThreads";
-
- public static final String PARALLEL_TIMEOUT_KEY = ProviderParameterNames.PARALLEL_TIMEOUT_PROP;
-
- public static final String PARALLEL_TIMEOUTFORCED_KEY = ProviderParameterNames.PARALLEL_TIMEOUTFORCED_PROP;
-
- public static final String PARALLEL_OPTIMIZE_KEY = ProviderParameterNames.PARALLEL_OPTIMIZE_PROP;
-
- public static final String ENABLE_OUT_ERR_ELEMENTS_KEY = ProviderParameterNames.ENABLE_OUT_ERR_ELEMENTS_PROP;
-
- public static final String ENABLE_PROPERTIES_ELEMENT_KEY = ProviderParameterNames.ENABLE_PROPERTIES_ELEMENT_PROP;
-
- private final String parallel;
-
- private final boolean perCoreThreadCount;
-
- private final int threadCount;
-
- private final int threadCountSuites;
-
- private final int threadCountClasses;
-
- private final int threadCountMethods;
-
- private final double parallelTestsTimeoutInSeconds;
-
- private final double parallelTestsTimeoutForcedInSeconds;
-
- private final boolean useUnlimitedThreads;
-
- private final boolean parallelOptimization;
-
- private final boolean enableOutErrElements;
-
- private final boolean enablePropertiesElement;
-
- public JUnitCoreParameters(Map properties) {
- parallel = property(properties, PARALLEL_KEY, "none").toLowerCase();
- perCoreThreadCount = property(properties, PERCORETHREADCOUNT_KEY, true);
- threadCount = property(properties, THREADCOUNT_KEY, 0);
- threadCountMethods = property(properties, THREADCOUNTMETHODS_KEY, 0);
- threadCountClasses = property(properties, THREADCOUNTCLASSES_KEY, 0);
- threadCountSuites = property(properties, THREADCOUNTSUITES_KEY, 0);
- useUnlimitedThreads = property(properties, USEUNLIMITEDTHREADS_KEY, false);
- parallelTestsTimeoutInSeconds = Math.max(property(properties, PARALLEL_TIMEOUT_KEY, 0d), 0);
- parallelTestsTimeoutForcedInSeconds = Math.max(property(properties, PARALLEL_TIMEOUTFORCED_KEY, 0d), 0);
- parallelOptimization = property(properties, PARALLEL_OPTIMIZE_KEY, true);
- enableOutErrElements = property(properties, ENABLE_OUT_ERR_ELEMENTS_KEY, true);
- enablePropertiesElement = property(properties, ENABLE_PROPERTIES_ELEMENT_KEY, true);
- }
-
- private static Collection lowerCase(String... elements) {
- ArrayList lowerCase = new ArrayList<>();
- for (String element : elements) {
- lowerCase.add(element.toLowerCase());
- }
- return lowerCase;
- }
-
- private boolean isAllParallel() {
- return "all".equals(parallel);
- }
-
- public boolean isParallelMethods() {
- return isAllParallel()
- || lowerCase("both", "methods", "suitesAndMethods", "classesAndMethods")
- .contains(parallel);
- }
-
- public boolean isParallelClasses() {
- return isAllParallel()
- || lowerCase("both", "classes", "suitesAndClasses", "classesAndMethods")
- .contains(parallel);
- }
-
- public boolean isParallelSuites() {
- return isAllParallel()
- || lowerCase("suites", "suitesAndClasses", "suitesAndMethods").contains(parallel);
- }
-
- /**
- * @deprecated Instead use the expression isParallelMethods() && isParallelClasses().
- * @return {@code true} if classes and methods are both parallel
- */
- @Deprecated
- @SuppressWarnings("unused")
- public boolean isParallelBoth() {
- return isParallelMethods() && isParallelClasses();
- }
-
- public boolean isPerCoreThreadCount() {
- return perCoreThreadCount;
- }
-
- public int getThreadCount() {
- return threadCount;
- }
-
- public int getThreadCountMethods() {
- return threadCountMethods;
- }
-
- public int getThreadCountClasses() {
- return threadCountClasses;
- }
-
- public int getThreadCountSuites() {
- return threadCountSuites;
- }
-
- public boolean isUseUnlimitedThreads() {
- return useUnlimitedThreads;
- }
-
- public double getParallelTestsTimeoutInSeconds() {
- return parallelTestsTimeoutInSeconds;
- }
-
- public double getParallelTestsTimeoutForcedInSeconds() {
- return parallelTestsTimeoutForcedInSeconds;
- }
-
- public boolean isNoThreading() {
- return !isParallelismSelected();
- }
-
- public boolean isParallelismSelected() {
- return isParallelSuites() || isParallelClasses() || isParallelMethods();
- }
-
- public boolean isParallelOptimization() {
- return parallelOptimization;
- }
-
- public boolean isEnableOutErrElements() {
- return enableOutErrElements;
- }
-
- public boolean isEnablePropertiesElement() {
- return enablePropertiesElement;
- }
-
- @Override
- public String toString() {
- return "parallel='" + parallel + '\'' + ", perCoreThreadCount=" + perCoreThreadCount + ", threadCount="
- + threadCount + ", useUnlimitedThreads=" + useUnlimitedThreads + ", threadCountSuites="
- + threadCountSuites
- + ", threadCountClasses=" + threadCountClasses + ", threadCountMethods=" + threadCountMethods
- + ", parallelOptimization=" + parallelOptimization
- + ", enableOutErrElements=" + enableOutErrElements
- + ", enablePropertiesElement=" + enablePropertiesElement;
- }
-
- private static boolean property(Map properties, String key, boolean fallback) {
- return properties.containsKey(key) ? Boolean.valueOf(properties.get(key)) : fallback;
- }
-
- private static String property(Map properties, String key, String fallback) {
- return properties.containsKey(key) ? properties.get(key) : fallback;
- }
-
- private static int property(Map properties, String key, int fallback) {
- return properties.containsKey(key) ? Integer.valueOf(properties.get(key)) : fallback;
- }
-
- private static double property(Map properties, String key, double fallback) {
- return properties.containsKey(key) ? Double.valueOf(properties.get(key)) : fallback;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
deleted file mode 100644
index f2f58fe815..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreProvider.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.surefire.api.booter.Command;
-import org.apache.maven.surefire.api.provider.AbstractProvider;
-import org.apache.maven.surefire.api.provider.CommandChainReader;
-import org.apache.maven.surefire.api.provider.CommandListener;
-import org.apache.maven.surefire.api.provider.ProviderParameters;
-import org.apache.maven.surefire.api.report.ReporterFactory;
-import org.apache.maven.surefire.api.suite.RunResult;
-import org.apache.maven.surefire.api.testset.TestListResolver;
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.api.util.RunOrderCalculator;
-import org.apache.maven.surefire.api.util.ScanResult;
-import org.apache.maven.surefire.api.util.ScannerFilter;
-import org.apache.maven.surefire.api.util.TestsToRun;
-import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
-import org.apache.maven.surefire.common.junit4.JUnitTestFailureListener;
-import org.apache.maven.surefire.common.junit4.Notifier;
-import org.apache.maven.surefire.common.junit48.FilterFactory;
-import org.apache.maven.surefire.common.junit48.JUnit48Reflector;
-import org.apache.maven.surefire.common.junit48.JUnit48TestChecker;
-import org.junit.runner.Description;
-import org.junit.runner.manipulation.Filter;
-
-import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture;
-import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
-import static org.apache.maven.surefire.api.report.RunMode.RERUN_TEST_AFTER_FAILURE;
-import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter;
-import static org.apache.maven.surefire.api.util.TestsToRun.fromClass;
-import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.generateFailingTestDescriptions;
-import static org.apache.maven.surefire.common.junit4.JUnit4RunListenerFactory.createCustomListeners;
-import static org.apache.maven.surefire.common.junit4.Notifier.pureNotifier;
-import static org.apache.maven.surefire.junitcore.ConcurrentRunListener.createInstance;
-
-/**
- * @author Kristian Rosenvold
- */
-@SuppressWarnings({"UnusedDeclaration"})
-public class JUnitCoreProvider extends AbstractProvider {
- private final ClassLoader testClassLoader;
-
- private final JUnitCoreParameters jUnitCoreParameters;
-
- private final ScannerFilter scannerFilter;
-
- private final String customRunListeners;
-
- private final ProviderParameters providerParameters;
-
- private final ScanResult scanResult;
-
- private final int rerunFailingTestsCount;
-
- private final JUnit48Reflector jUnit48Reflector;
-
- private final RunOrderCalculator runOrderCalculator;
-
- private final TestListResolver testResolver;
-
- private final CommandChainReader commandsReader;
-
- private TestsToRun testsToRun;
-
- public JUnitCoreProvider(ProviderParameters bootParams) {
- // don't start a thread in CommandReader while we are in in-plugin process
- commandsReader = bootParams.isInsideFork() ? bootParams.getCommandReader() : null;
- providerParameters = bootParams;
- testClassLoader = bootParams.getTestClassLoader();
- scanResult = bootParams.getScanResult();
- runOrderCalculator = bootParams.getRunOrderCalculator();
- jUnitCoreParameters = new JUnitCoreParameters(bootParams.getProviderProperties());
- scannerFilter = new JUnit48TestChecker(testClassLoader);
- testResolver = bootParams.getTestRequest().getTestListResolver();
- rerunFailingTestsCount = bootParams.getTestRequest().getRerunFailingTestsCount();
- customRunListeners = bootParams.getProviderProperties().get("listener");
- jUnit48Reflector = new JUnit48Reflector(testClassLoader);
- }
-
- @Override
- public Iterable> getSuites() {
- testsToRun = scanClassPath();
- return testsToRun;
- }
-
- private boolean isSingleThreaded() {
- return jUnitCoreParameters.isNoThreading();
- }
-
- @Override
- public RunResult invoke(Object forkTestSet) throws TestSetFailedException {
- ReporterFactory reporterFactory = providerParameters.getReporterFactory();
- JUnit4RunListener listener = createRunListener(reporterFactory);
- listener.setRunMode(NORMAL_RUN);
- ConsoleLogger logger = listener.getConsoleLogger();
- Notifier notifier = new Notifier(listener, getSkipAfterFailureCount());
- // startCapture() called in createRunListener() in prior to setTestsToRun()
-
- Filter filter = jUnit48Reflector.isJUnit48Available() ? createJUnit48Filter() : null;
-
- if (testsToRun == null) {
- setTestsToRun(forkTestSet);
- }
-
- // Add test failure listener
- JUnitTestFailureListener testFailureListener = new JUnitTestFailureListener();
- notifier.addListener(testFailureListener);
-
- if (isFailFast() && commandsReader != null) {
- registerPleaseStopJUnitListener(notifier);
- }
-
- final RunResult runResult;
-
- try {
- JUnitCoreWrapper core = new JUnitCoreWrapper(notifier, jUnitCoreParameters, logger);
-
- if (commandsReader != null) {
- registerShutdownListener(testsToRun);
- commandsReader.awaitStarted();
- }
-
- notifier.asFailFast(isFailFast());
- core.execute(testsToRun, createCustomListeners(customRunListeners), filter);
- notifier.asFailFast(false);
-
- // Rerun failing tests if rerunFailingTestsCount is larger than 0
- if (isRerunFailingTests()) {
- listener.setRunMode(RERUN_TEST_AFTER_FAILURE);
- Notifier rerunNotifier = pureNotifier();
- notifier.copyListenersTo(rerunNotifier);
- JUnitCoreWrapper rerunCore = new JUnitCoreWrapper(rerunNotifier, jUnitCoreParameters, logger);
- for (int i = 0;
- i < rerunFailingTestsCount
- && !testFailureListener.getAllFailures().isEmpty();
- i++) {
- Set failures = generateFailingTestDescriptions(testFailureListener.getAllFailures());
- testFailureListener.reset();
- FilterFactory filterFactory = new FilterFactory(testClassLoader);
- Filter failureDescriptionFilter = filterFactory.createMatchAnyDescriptionFilter(failures);
- rerunCore.execute(testsToRun, failureDescriptionFilter);
- }
- }
- } finally {
- runResult = reporterFactory.close();
- notifier.removeListeners();
- }
- return runResult;
- }
-
- private void setTestsToRun(Object forkTestSet) throws TestSetFailedException {
- if (forkTestSet instanceof TestsToRun) {
- testsToRun = (TestsToRun) forkTestSet;
- } else if (forkTestSet instanceof Class) {
- Class> theClass = (Class>) forkTestSet;
- testsToRun = fromClass(theClass);
- } else {
- testsToRun = scanClassPath();
- }
- }
-
- private boolean isRerunFailingTests() {
- return rerunFailingTestsCount > 0;
- }
-
- private boolean isFailFast() {
- return providerParameters.getSkipAfterFailureCount() > 0;
- }
-
- private int getSkipAfterFailureCount() {
- return isFailFast() ? providerParameters.getSkipAfterFailureCount() : 0;
- }
-
- private void registerShutdownListener(final TestsToRun testsToRun) {
- commandsReader.addShutdownListener(new CommandListener() {
- @Override
- public void update(Command command) {
- testsToRun.markTestSetFinished();
- }
- });
- }
-
- private void registerPleaseStopJUnitListener(final Notifier stoppable) {
- commandsReader.addSkipNextTestsListener(new CommandListener() {
- @Override
- public void update(Command command) {
- stoppable.pleaseStop();
- }
- });
- }
-
- private JUnit4RunListener createRunListener(ReporterFactory reporterFactory) {
- final JUnit4RunListener listener;
- if (isSingleThreaded()) {
- listener = new NonConcurrentRunListener(reporterFactory.createTestReportListener());
- } else {
- Map testSetMap = new ConcurrentHashMap<>();
- boolean parallelClasses = isParallelTypes();
- boolean parallelBoth = isParallelMethodsAndTypes();
- ConcurrentRunListener concurrentListener =
- createInstance(testSetMap, reporterFactory, parallelClasses, parallelBoth);
- listener = new JUnitCoreRunListener(concurrentListener, testSetMap);
- }
-
- startCapture(listener);
- return listener;
- }
-
- private boolean isParallelMethodsAndTypes() {
- return jUnitCoreParameters.isParallelMethods() && isParallelTypes();
- }
-
- private boolean isParallelTypes() {
- return jUnitCoreParameters.isParallelClasses() || jUnitCoreParameters.isParallelSuites();
- }
-
- private Filter createJUnit48Filter() {
- final FilterFactory factory = new FilterFactory(testClassLoader);
- Map props = providerParameters.getProviderProperties();
- Filter groupFilter = factory.canCreateGroupFilter(props) ? factory.createGroupFilter(props) : null;
- TestListResolver methodFilter = optionallyWildcardFilter(testResolver);
- boolean onlyGroups = methodFilter.isEmpty() || methodFilter.isWildcard();
- if (onlyGroups) {
- return groupFilter;
- } else {
- Filter jUnitMethodFilter = factory.createMethodFilter(methodFilter);
- return groupFilter == null ? jUnitMethodFilter : factory.and(groupFilter, jUnitMethodFilter);
- }
- }
-
- private TestsToRun scanClassPath() {
- TestsToRun scanned = scanResult.applyFilter(scannerFilter, testClassLoader);
- return runOrderCalculator.orderTestClasses(scanned);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java
deleted file mode 100644
index 31a939f401..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreRunListener.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Map;
-
-import org.apache.maven.surefire.api.report.StackTraceWriter;
-import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
-import org.apache.maven.surefire.common.junit4.JUnit4StackTraceWriter;
-import org.junit.runner.Description;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-
-import static org.apache.maven.surefire.api.util.internal.TestClassMethodNameUtils.extractClassName;
-
-/**
- * Noteworthy things about JUnit4 listening:
- *
- * A class that is annotated with @Ignore will have one invocation of "testSkipped" with source==name
- * A method that is annotated with @Ignore will have a invocation of testSkipped with source and name distinct
- * Methods annotated with @Ignore trigger no further events.
- *
- * @see org.apache.maven.surefire.junitcore.ConcurrentRunListener for details about parallel running
- */
-final class JUnitCoreRunListener extends JUnit4RunListener {
- private final Map classMethodCounts;
-
- /**
- * @param reporter the report manager to log testing events to
- * @param classMethodCounts A map of methods
- */
- JUnitCoreRunListener(ConcurrentRunListener reporter, Map classMethodCounts) {
- super(reporter);
- this.classMethodCounts = classMethodCounts;
- }
-
- /**
- * Called right before any tests from a specific class are run.
- *
- * @see org.junit.runner.notification.RunListener#testRunStarted(org.junit.runner.Description)
- */
- @Override
- public void testRunStarted(Description description) throws Exception {
- fillTestCountMap(description);
- reporter.testSetStarting(null); // Not entirely meaningful as we can see
- }
-
- @Override
- public void testRunFinished(Result result) throws Exception {
- try {
- reporter.testSetCompleted(null);
- } finally {
- classMethodCounts.clear();
- }
- }
-
- private void fillTestCountMap(Description testDesc) {
- for (Description child : testDesc.getChildren()) {
- if (!asTestLeaf(child)) {
- fillTestCountMap(child);
- }
- }
- }
-
- private boolean asTestLeaf(Description description) {
- if (description.isTest()) {
- final String testClassName = extractClassName(description.getDisplayName());
- if (testClassName != null) {
- final TestSet testSet;
- if (classMethodCounts.containsKey(testClassName)) {
- testSet = classMethodCounts.get(testClassName);
- } else {
- testSet = new TestSet(testClassName, getRunMode(), classMethodIndexer);
- classMethodCounts.put(testClassName, testSet);
- }
- testSet.incrementTestMethodCount();
- }
- return true;
- } else {
- return false;
- }
- }
-
- @Override
- protected StackTraceWriter createStackTraceWriter(Failure failure) {
- return new JUnit4StackTraceWriter(failure);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
deleted file mode 100644
index 96fc928fa8..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.Queue;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.api.util.TestsToRun;
-import org.apache.maven.surefire.common.junit4.Notifier;
-import org.apache.maven.surefire.junitcore.pc.ParallelComputer;
-import org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder;
-import org.junit.Ignore;
-import org.junit.runner.Computer;
-import org.junit.runner.Description;
-import org.junit.runner.Request;
-import org.junit.runner.Result;
-import org.junit.runner.manipulation.Filter;
-import org.junit.runner.notification.RunListener;
-import org.junit.runner.notification.StoppedByUserException;
-
-import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createDescription;
-import static org.apache.maven.surefire.common.junit4.JUnit4Reflector.createIgnored;
-import static org.apache.maven.surefire.common.junit4.JUnit4RunListener.rethrowAnyTestMechanismFailures;
-import static org.junit.runner.Computer.serial;
-import static org.junit.runner.Request.classes;
-
-/**
- * Encapsulates access to JUnitCore
- *
- * @author Kristian Rosenvold
- */
-final class JUnitCoreWrapper {
- private final Notifier notifier;
- private final JUnitCoreParameters jUnitCoreParameters;
- private final ConsoleLogger consoleStream;
-
- JUnitCoreWrapper(Notifier notifier, JUnitCoreParameters jUnitCoreParameters, ConsoleLogger consoleStream) {
- this.notifier = notifier;
- this.jUnitCoreParameters = jUnitCoreParameters;
- this.consoleStream = consoleStream;
- }
-
- void execute(TestsToRun testsToRun, Filter filter) throws TestSetFailedException {
- execute(testsToRun, true, Collections.emptyList(), filter);
- }
-
- void execute(TestsToRun testsToRun, Collection listeners, Filter filter)
- throws TestSetFailedException {
- execute(testsToRun, false, listeners, filter);
- }
-
- private void execute(TestsToRun testsToRun, boolean useIterated, Collection listeners, Filter filter)
- throws TestSetFailedException {
- if (testsToRun.allowEagerReading()) {
- executeEager(testsToRun, filter, listeners);
- } else {
- executeLazy(testsToRun, useIterated, filter, listeners);
- }
- }
-
- private JUnitCore createJUnitCore(Notifier notifier, Collection listeners) {
- JUnitCore junitCore = new JUnitCore();
-
- // custom listeners added last
- notifier.addListeners(listeners);
-
- return junitCore;
- }
-
- private void executeEager(TestsToRun testsToRun, Filter filter, Collection listeners)
- throws TestSetFailedException {
- JUnitCore junitCore = createJUnitCore(notifier, listeners);
- Class>[] tests = testsToRun.getLocatedClasses();
- Computer computer = createComputer();
- createRequestAndRun(filter, computer, junitCore.withReportedTests(tests), tests);
- }
-
- private void executeLazy(
- TestsToRun testsToRun, boolean useIterated, Filter filter, Collection listeners)
- throws TestSetFailedException {
- JUnitCore junitCore = createJUnitCore(notifier, listeners);
- for (Iterator> it = useIterated ? testsToRun.iterated() : testsToRun.iterator(); it.hasNext(); ) {
- Class> clazz = it.next();
- Computer computer = createComputer();
- createRequestAndRun(filter, computer, junitCore.withReportedTests(clazz), clazz);
- }
- }
-
- private void createRequestAndRun(Filter filter, Computer computer, JUnitCore junitCore, Class>... classesToRun)
- throws TestSetFailedException {
- Request req = classes(computer, classesToRun);
- if (filter != null) {
- req = new FilteringRequest(req, filter);
- if (req.getRunner() == null) {
- // nothing to run
- return;
- }
- }
-
- Result run = junitCore.run(req.getRunner());
- rethrowAnyTestMechanismFailures(run);
-
- if (computer instanceof ParallelComputer) {
- String timeoutMessage = ((ParallelComputer) computer).describeElapsedTimeout();
- if (!timeoutMessage.isEmpty()) {
- throw new TestSetFailedException(timeoutMessage);
- }
- }
- }
-
- private Computer createComputer() {
- return jUnitCoreParameters.isNoThreading()
- ? serial()
- : new ParallelComputerBuilder(consoleStream, jUnitCoreParameters).buildComputer();
- }
-
- private final class JUnitCore extends org.apache.maven.surefire.junitcore.JUnitCore {
- JUnitCore() {
- super(JUnitCoreWrapper.this.notifier);
- }
-
- JUnitCore withReportedTests(Class>... tests) {
- Queue stoppedTests = JUnitCoreWrapper.this.notifier.getRemainingTestClasses();
- if (stoppedTests != null) {
- for (Class> test : tests) {
- stoppedTests.add(test.getName());
- }
- }
- return this;
- }
-
- @Override
- @SuppressWarnings("checkstyle:innerassignment")
- protected void afterException(Throwable e) throws TestSetFailedException {
- if (JUnitCoreWrapper.this.notifier.isFailFast() && e instanceof StoppedByUserException) {
- Queue stoppedTests = JUnitCoreWrapper.this.notifier.getRemainingTestClasses();
- if (stoppedTests != null) {
- String reason = e.getClass().getName();
- Ignore reasonForSkippedTest = createIgnored(reason);
- for (String clazz; (clazz = stoppedTests.poll()) != null; ) {
- Description skippedTest = createDescription(clazz, reasonForSkippedTest);
- JUnitCoreWrapper.this.notifier.fireTestIgnored(skippedTest);
- }
- }
- } else {
- super.afterException(e);
- }
- }
-
- @Override
- protected void afterFinished() {
- Queue stoppedTests = JUnitCoreWrapper.this.notifier.getRemainingTestClasses();
- if (stoppedTests != null) {
- stoppedTests.clear();
- }
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
deleted file mode 100644
index a4846be6d2..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/LogicalStream.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import org.apache.maven.surefire.api.report.TestOutputReceiver;
-import org.apache.maven.surefire.api.report.TestOutputReportEntry;
-
-/**
- * A stream-like object that preserves ordering between stdout/stderr
- */
-@Deprecated // remove this class after StatelessXmlReporter is capable of parallel test sets processing
-final class LogicalStream {
- private final Queue output = new ConcurrentLinkedQueue<>();
-
- synchronized void write(TestOutputReportEntry reportEntry) {
- output.add(reportEntry);
- }
-
- void writeDetails(TestOutputReceiver outputReceiver) {
- for (TestOutputReportEntry entry = output.poll(); entry != null; entry = output.poll()) {
- outputReceiver.writeTestOutput(entry);
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/MethodsParallelRunListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/MethodsParallelRunListener.java
deleted file mode 100644
index f157a35f13..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/MethodsParallelRunListener.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Map;
-
-import org.apache.maven.surefire.api.report.ReporterFactory;
-
-/**
- * @author Kristian Rosenvold
- */
-@Deprecated // remove this class after StatelessXmlReporter is capable of parallel test sets processing
-final class MethodsParallelRunListener extends ConcurrentRunListener {
- private volatile TestSet lastStarted;
-
- private final Object lock = new Object();
-
- MethodsParallelRunListener(
- Map classMethodCounts, ReporterFactory reporterFactory, boolean reportImmediately) {
- super(reporterFactory, reportImmediately, classMethodCounts);
- }
-
- @Override
- protected void checkIfTestSetCanBeReported(TestSet testSetForTest) {
- synchronized (lock) {
- if (testSetForTest != lastStarted) {
- if (lastStarted != null) {
- lastStarted.setAllScheduled(getRunListener());
- }
- lastStarted = testSetForTest;
- }
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
deleted file mode 100644
index 0959aaa136..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/NonConcurrentRunListener.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Collections;
-import java.util.Map;
-
-import org.apache.maven.surefire.api.report.SimpleReportEntry;
-import org.apache.maven.surefire.api.report.TestOutputReportEntry;
-import org.apache.maven.surefire.api.report.TestReportListener;
-import org.apache.maven.surefire.api.report.TestSetReportEntry;
-import org.apache.maven.surefire.api.util.internal.ClassMethod;
-import org.apache.maven.surefire.common.junit4.JUnit4RunListener;
-import org.junit.runner.Description;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-
-import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps;
-import static org.apache.maven.surefire.common.junit4.JUnit4ProviderUtil.toClassMethod;
-
-/**
- * A class to be used when there is no JUnit parallelism (methods or/and class). This allows to workaround JUnit
- * limitation a la Junit4 provider. Specifically, we can redirect properly the output even if we don't have class
- * demarcation in JUnit. It works when if there is a JVM instance per test run, i.e. with reuseForks=false and
- * forkCount greater than one.
- */
-@Deprecated // remove this class after StatelessXmlReporter is capable of parallel test sets processing
-class NonConcurrentRunListener extends JUnit4RunListener {
- private Description currentTestSetDescription;
-
- private Description lastFinishedDescription;
-
- NonConcurrentRunListener(TestReportListener reporter) {
- super(reporter);
- }
-
- private TestSetReportEntry createReportEntryForTestSet(Description description, Map systemProps) {
- ClassMethod classMethod = toClassMethod(description);
- String className = classMethod.getClazz();
- String methodName = classMethod.getMethod();
- long testRunId = classMethodIndexer.indexClassMethod(className, methodName);
- return new SimpleReportEntry(getRunMode(), testRunId, className, null, null, null, systemProps);
- }
-
- private TestSetReportEntry createTestSetReportEntryStarted(Description description) {
- return createReportEntryForTestSet(description, Collections.emptyMap());
- }
-
- private TestSetReportEntry createTestSetReportEntryFinished(Description description) {
- return createReportEntryForTestSet(description, systemProps());
- }
-
- @Override
- public void testStarted(Description description) throws Exception {
- finishLastTestSetIfNecessary(description);
- super.testStarted(description);
- }
-
- private void finishLastTestSetIfNecessary(Description description) {
- if (describesNewTestSet(description)) {
- currentTestSetDescription = description;
- if (lastFinishedDescription != null) {
- reporter.testSetCompleted(createTestSetReportEntryFinished(lastFinishedDescription));
- lastFinishedDescription = null;
- }
- reporter.testSetStarting(createTestSetReportEntryStarted(description));
- }
- }
-
- private boolean describesNewTestSet(Description description) {
- if (currentTestSetDescription != null) {
- if (null != description.getTestClass()) {
- return !description.getTestClass().equals(currentTestSetDescription.getTestClass());
- } else if (description.isSuite()) {
- return description.getChildren().equals(currentTestSetDescription.getChildren());
- }
-
- return false;
- }
-
- return true;
- }
-
- @Override
- public void testFinished(Description description) throws Exception {
- super.testFinished(description);
- lastFinishedDescription = description;
- }
-
- @Override
- public void testIgnored(Description description) throws Exception {
- finishLastTestSetIfNecessary(description);
-
- super.testIgnored(description);
- lastFinishedDescription = description;
- }
-
- @Override
- public void testFailure(Failure failure) throws Exception {
- finishLastTestSetIfNecessary(failure.getDescription());
-
- super.testFailure(failure);
- lastFinishedDescription = failure.getDescription();
- }
-
- @Override
- public void testAssumptionFailure(Failure failure) {
- finishLastTestSetIfNecessary(failure.getDescription());
-
- super.testAssumptionFailure(failure);
- lastFinishedDescription = failure.getDescription();
- }
-
- @Override
- public void testRunStarted(Description description) throws Exception {}
-
- @Override
- public void testRunFinished(Result result) throws Exception {
- if (lastFinishedDescription != null) {
- reporter.testSetCompleted(createTestSetReportEntryFinished(lastFinishedDescription));
- lastFinishedDescription = null;
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java
deleted file mode 100644
index 6d57ce864d..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/SynchronousRunner.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import org.junit.runners.model.RunnerScheduler;
-
-/**
- * Since SUREFIRE 2.18 this class is deprecated.
- * Use {@link org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder} instead.
- *
- * @author Kristian Rosenvold
- */
-@Deprecated
-class SynchronousRunner implements RunnerScheduler {
- @Override
- public void schedule(final Runnable childStatement) {
- childStatement.run();
- }
-
- @Override
- public void finished() {}
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
deleted file mode 100644
index cdff242e8f..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.maven.surefire.api.report.CategorizedReportEntry;
-import org.apache.maven.surefire.api.report.ConsoleOutputReceiverForCurrentThread;
-import org.apache.maven.surefire.api.report.ReportEntry;
-import org.apache.maven.surefire.api.report.TestOutputReceiver;
-import org.apache.maven.surefire.api.report.TestOutputReportEntry;
-import org.apache.maven.surefire.api.report.TestReportListener;
-
-/**
- * Represents the test-state of a single test method that is run.
- *
- * Notes about thread safety: This instance is serially confined to 1-3 threads (construction, test-run, reporting),
- * without any actual parallel access
- */
-@Deprecated // remove this class after StatelessXmlReporter is capable of parallel test sets processing
-class TestMethod implements TestOutputReceiver {
- private static final InheritableThreadLocal TEST_METHOD = new InheritableThreadLocal<>();
-
- private final AtomicReference output = new AtomicReference<>();
-
- private final ReportEntry description;
-
- private final TestSet testSet;
-
- private final long startTime;
-
- private volatile long endTime;
-
- private volatile ReportEntry testFailure;
-
- private volatile ReportEntry testError;
-
- private volatile ReportEntry testIgnored;
-
- private volatile ReportEntry testAssumption;
-
- TestMethod(ReportEntry description, TestSet testSet) {
- this.description = description;
- this.testSet = testSet;
- startTime = System.currentTimeMillis();
- }
-
- void testFinished() {
- setEndTime();
- }
-
- void testIgnored(ReportEntry description) {
- testIgnored = description;
- setEndTime();
- }
-
- void testFailure(ReportEntry failure) {
- this.testFailure = failure;
- setEndTime();
- }
-
- void testError(ReportEntry failure) {
- this.testError = failure;
- setEndTime();
- }
-
- void testAssumption(ReportEntry failure) {
- this.testAssumption = failure;
- setEndTime();
- }
-
- private void setEndTime() {
- this.endTime = System.currentTimeMillis();
- }
-
- int getElapsed() {
- return endTime > 0 ? (int) (endTime - startTime) : 0;
- }
-
- long getStartTime() {
- return startTime;
- }
-
- long getEndTime() {
- return endTime;
- }
-
- void replay(TestReportListener reporter) {
- if (testIgnored != null) {
- reporter.testSkipped(createReportEntry(testIgnored));
- } else {
- ReportEntry descriptionReport = createReportEntry(description);
- reporter.testStarting(descriptionReport);
- LogicalStream ls = output.get();
- if (ls != null) {
- ls.writeDetails(reporter);
- }
-
- if (testFailure != null) {
- reporter.testFailed(createReportEntry(testFailure));
- } else if (testError != null) {
- reporter.testError(createReportEntry(testError));
- } else if (testAssumption != null) {
- reporter.testAssumptionFailure(createReportEntry(testAssumption));
- } else {
- reporter.testSucceeded(descriptionReport);
- }
- }
- }
-
- private ReportEntry createReportEntry(ReportEntry reportEntry) {
- return new CategorizedReportEntry(
- reportEntry.getRunMode(),
- reportEntry.getTestRunId(),
- reportEntry.getSourceName(),
- reportEntry.getName(),
- reportEntry.getGroup(),
- reportEntry.getStackTraceWriter(),
- getElapsed(),
- reportEntry.getMessage());
- }
-
- void attachToThread() {
- TEST_METHOD.set(this);
- ConsoleOutputReceiverForCurrentThread.set(this);
- }
-
- void detachFromCurrentThread() {
- TEST_METHOD.remove();
- ConsoleOutputReceiverForCurrentThread.remove();
- }
-
- static TestMethod getThreadTestMethod() {
- return TEST_METHOD.get();
- }
-
- LogicalStream getLogicalStream() {
- LogicalStream ls = output.get();
- if (ls == null) {
- ls = new LogicalStream();
- if (!output.compareAndSet(null, ls)) {
- ls = output.get();
- }
- }
- return ls;
- }
-
- @Override
- public void writeTestOutput(TestOutputReportEntry reportEntry) {
- getLogicalStream().write(reportEntry);
- }
-
- TestSet getTestSet() {
- return testSet;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java
deleted file mode 100644
index 3d7bebf726..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.apache.maven.surefire.api.report.ReportEntry;
-import org.apache.maven.surefire.api.report.RunMode;
-import org.apache.maven.surefire.api.report.SimpleReportEntry;
-import org.apache.maven.surefire.api.report.TestOutputReportEntry;
-import org.apache.maven.surefire.api.report.TestReportListener;
-import org.apache.maven.surefire.api.report.TestSetReportEntry;
-import org.apache.maven.surefire.report.ClassMethodIndexer;
-
-import static org.apache.maven.surefire.api.util.internal.ObjectUtils.systemProps;
-
-/**
- * * Represents the test-state of a testset that is run.
- */
-@Deprecated // remove this class after StatelessXmlReporter is capable of parallel test sets processing
-public class TestSet {
- private static final InheritableThreadLocal TEST_SET = new InheritableThreadLocal<>();
-
- private final String testClassName;
-
- private final Collection testMethods = new ConcurrentLinkedQueue<>();
-
- private final AtomicBoolean played = new AtomicBoolean();
-
- private final AtomicInteger numberOfCompletedChildren = new AtomicInteger();
-
- // While the two parameters may seem duplicated, it is not entirely the case,
- // since numberOfTests has the correct value from the start, while testMethods grows as method execution starts.
-
- private final AtomicInteger numberOfTests = new AtomicInteger();
-
- private final RunMode runMode;
-
- private final ClassMethodIndexer classMethodIndexer;
-
- private volatile boolean allScheduled;
-
- public TestSet(String testClassName, RunMode runMode, ClassMethodIndexer classMethodIndexer) {
- this.testClassName = testClassName;
- this.runMode = runMode;
- this.classMethodIndexer = classMethodIndexer;
- }
-
- final RunMode getRunMode() {
- return runMode;
- }
-
- final ClassMethodIndexer getClassMethodIndexer() {
- return classMethodIndexer;
- }
-
- public void replay(TestReportListener target) {
- if (played.compareAndSet(false, true)) {
- try {
- TestSetReportEntry report = createReportEntryStarted();
-
- target.testSetStarting(report);
-
- long startTime = 0;
- long endTime = 0;
- for (TestMethod testMethod : testMethods) {
- if (startTime == 0 || testMethod.getStartTime() < startTime) {
- startTime = testMethod.getStartTime();
- }
-
- if (endTime == 0 || testMethod.getEndTime() > endTime) {
- endTime = testMethod.getEndTime();
- }
-
- testMethod.replay(target);
- }
-
- int elapsed = (int) (endTime - startTime);
-
- report = createReportEntryCompleted(elapsed);
-
- target.testSetCompleted(report);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
- }
-
- public TestMethod createThreadAttachedTestMethod(ReportEntry description) {
- TestMethod testMethod = new TestMethod(description, this);
- addTestMethod(testMethod);
- testMethod.attachToThread();
- return testMethod;
- }
-
- private TestSetReportEntry createReportEntryStarted() {
- return createReportEntry(null, Collections.emptyMap());
- }
-
- private TestSetReportEntry createReportEntryCompleted(int elapsed) {
- return createReportEntry(elapsed, systemProps());
- }
-
- private TestSetReportEntry createReportEntry(Integer elapsed, Map systemProps) {
- return new SimpleReportEntry(
- runMode,
- classMethodIndexer.indexClass(testClassName),
- testClassName,
- null,
- testClassName,
- null,
- null,
- elapsed,
- systemProps);
- }
-
- public void incrementTestMethodCount() {
- numberOfTests.incrementAndGet();
- }
-
- private void addTestMethod(TestMethod testMethod) {
- testMethods.add(testMethod);
- }
-
- public void incrementFinishedTests(TestReportListener reporterManager, boolean reportImmediately) {
- numberOfCompletedChildren.incrementAndGet();
- if (allScheduled && isAllTestsDone() && reportImmediately) {
- replay(reporterManager);
- }
- }
-
- public void setAllScheduled(TestReportListener reporterManager) {
- allScheduled = true;
- if (isAllTestsDone()) {
- replay(reporterManager);
- }
- }
-
- private boolean isAllTestsDone() {
- return numberOfTests.get() == numberOfCompletedChildren.get();
- }
-
- public void attachToThread() {
- TEST_SET.set(this);
- }
-
- public static TestSet getThreadTestSet() {
- return TEST_SET.get();
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/AbstractThreadPoolStrategy.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/AbstractThreadPoolStrategy.java
deleted file mode 100644
index 3d1c0aa131..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/AbstractThreadPoolStrategy.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Collection;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-
-/**
- * Abstract parallel scheduling strategy in private package.
- * The remaining abstract methods have to be implemented differently
- * depending if the thread pool is shared with other strategies or not.
- *
- * @author Tibor Digana (tibor17)
- * @see SchedulingStrategy
- * @see SharedThreadPoolStrategy
- * @see NonSharedThreadPoolStrategy
- * @since 2.16
- */
-abstract class AbstractThreadPoolStrategy extends SchedulingStrategy {
- private final ExecutorService threadPool;
-
- private final Collection> futureResults;
-
- private volatile boolean isDestroyed;
-
- AbstractThreadPoolStrategy(ConsoleLogger logger, ExecutorService threadPool) {
- this(logger, threadPool, null);
- }
-
- AbstractThreadPoolStrategy(ConsoleLogger logger, ExecutorService threadPool, Collection> futureResults) {
- super(logger);
- this.threadPool = threadPool;
- this.futureResults = futureResults;
- }
-
- protected final ExecutorService getThreadPool() {
- return threadPool;
- }
-
- protected final Collection> getFutureResults() {
- return futureResults;
- }
-
- @Override
- public void schedule(Runnable task) {
- if (canSchedule()) {
- Future> futureResult = threadPool.submit(task);
- if (futureResults != null) {
- futureResults.add(futureResult);
- }
- }
- }
-
- @Override
- protected boolean stop() {
- boolean wasRunning = disable();
- if (threadPool.isShutdown()) {
- wasRunning = false;
- } else {
- threadPool.shutdown();
- }
- return wasRunning;
- }
-
- @Override
- protected boolean stopNow() {
- boolean wasRunning = disable();
- if (threadPool.isShutdown()) {
- wasRunning = false;
- } else {
- threadPool.shutdownNow();
- }
- return wasRunning;
- }
-
- /**
- * @see Scheduler.ShutdownHandler
- */
- @Override
- protected void setDefaultShutdownHandler(Scheduler.ShutdownHandler handler) {
- if (threadPool instanceof ThreadPoolExecutor) {
- ThreadPoolExecutor pool = (ThreadPoolExecutor) threadPool;
- handler.setRejectedExecutionHandler(pool.getRejectedExecutionHandler());
- pool.setRejectedExecutionHandler(handler);
- }
- }
-
- @Override
- public boolean destroy() {
- try {
- if (!isDestroyed) // just an optimization
- {
- disable();
- threadPool.shutdown();
- this.isDestroyed |= threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
- }
- return isDestroyed;
- } catch (InterruptedException e) {
- return false;
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Balancer.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Balancer.java
deleted file mode 100644
index bbaabb8ae4..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Balancer.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * The Balancer controls the maximum of concurrent threads in the current Scheduler(s) and prevents
- * from own thread resources exhaustion if other group of schedulers share the same pool of threads.
- *
- * If a permit is available, {@link #acquirePermit()} simply returns and a new test is scheduled
- * by {@link Scheduler#schedule(Runnable)} in the current runner. Otherwise waiting for a release.
- * One permit is released as soon as the child thread has finished.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public interface Balancer {
-
- /**
- * Acquires a permit from this balancer, blocking until one is available.
- *
- * @return {@code true} if current thread is NOT interrupted
- * while waiting for a permit.
- */
- boolean acquirePermit();
-
- /**
- * Releases a permit, returning it to the balancer.
- */
- void releasePermit();
-
- void releaseAllPermits();
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/BalancerFactory.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/BalancerFactory.java
deleted file mode 100644
index 58d2618ddc..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/BalancerFactory.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * @author Tibor Digana (tibor17)
- * @see Balancer
- * @since 2.16
- */
-public class BalancerFactory {
- private BalancerFactory() {}
-
- /**
- * Infinite permits.
- * @return Balancer wih infinite permits
- */
- public static Balancer createInfinitePermitsBalancer() {
- return balancer(0, false);
- }
-
- /**
- * Balancer without fairness.
- * Fairness guarantees the waiting schedulers to wake up in order they acquired a permit.
- *
- * @param concurrency number of permits to acquire when maintaining concurrency on tests
- * @return Balancer with given number of permits
- */
- public static Balancer createBalancer(int concurrency) {
- return balancer(concurrency, false);
- }
-
- /**
- * Balancer with fairness.
- * Fairness guarantees the waiting schedulers to wake up in order they acquired a permit.
- *
- * @param concurrency number of permits to acquire when maintaining concurrency on tests
- * @return Balancer with given number of permits
- */
- public static Balancer createBalancerWithFairness(int concurrency) {
- return balancer(concurrency, true);
- }
-
- private static Balancer balancer(int concurrency, boolean fairness) {
- boolean shouldBalance = concurrency > 0 && concurrency < Integer.MAX_VALUE;
- return shouldBalance ? new ThreadResourcesBalancer(concurrency, fairness) : new NullBalancer();
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Concurrency.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Concurrency.java
deleted file mode 100644
index 7850083972..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Concurrency.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * @author tibor17 (Tibor Digana)
- * @since 2.17
- */
-final class Concurrency {
- int suites, classes, methods, capacity;
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Destroyable.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Destroyable.java
deleted file mode 100644
index 53037e80b2..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Destroyable.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * Destroys the embedded thread-pool.
- *
- * @author Tibor Digana (tibor17)
- * @see ParallelComputerBuilder
- * @since 2.18
- */
-public interface Destroyable {
- /**
- * Calling {@link java.util.concurrent.ThreadPoolExecutor#shutdown()}
- * and {@link java.util.concurrent.ThreadPoolExecutor#awaitTermination(long, java.util.concurrent.TimeUnit)}.
- *
- * @return {@code true} if not interrupted in current thread
- */
- boolean destroy();
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ExecutionStatus.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ExecutionStatus.java
deleted file mode 100644
index 9595a40845..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ExecutionStatus.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * Status of {@link ParallelComputer ParallelComputer runtime}.
- * Used together with shutdown hook.
- *
- * @author Tibor Digana (tibor17)
- * @see ParallelComputer
- * @since 2.18
- */
-enum ExecutionStatus {
- STARTED,
- FINISHED,
- TIMEOUT
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/InvokerStrategy.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/InvokerStrategy.java
deleted file mode 100644
index e83ff5d391..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/InvokerStrategy.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-
-/**
- * The sequentially executing strategy in private package.
- *
- * @author Tibor Digana (tibor17)
- * @see SchedulingStrategy
- * @since 2.16
- */
-final class InvokerStrategy extends SchedulingStrategy {
-
- private final Queue activeThreads = new ConcurrentLinkedQueue<>();
-
- protected InvokerStrategy(ConsoleLogger logger) {
- super(logger);
- }
-
- @Override
- public void schedule(Runnable task) {
- if (canSchedule()) {
- final Thread currentThread = Thread.currentThread();
- try {
- activeThreads.add(currentThread);
- task.run();
- } finally {
- activeThreads.remove(currentThread);
- }
- }
- }
-
- @Override
- protected boolean stop() {
- return disable();
- }
-
- @Override
- protected boolean stopNow() {
- final boolean stopped = disable();
-
- for (Thread activeThread = activeThreads.poll(); activeThread != null; activeThread = activeThreads.poll()) {
- activeThread.interrupt();
- }
- return stopped;
- }
-
- @Override
- public boolean hasSharedThreadPool() {
- return false;
- }
-
- @Override
- public boolean finished() throws InterruptedException {
- return disable();
- }
-
- @Override
- public boolean destroy() {
- return stop();
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NonSharedThreadPoolStrategy.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NonSharedThreadPoolStrategy.java
deleted file mode 100644
index ee251af9fa..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NonSharedThreadPoolStrategy.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-
-/**
- * Parallel strategy for non-shared thread pool in private package.
- *
- * @author Tibor Digana (tibor17)
- * @see AbstractThreadPoolStrategy
- * @since 2.16
- */
-final class NonSharedThreadPoolStrategy extends AbstractThreadPoolStrategy {
- NonSharedThreadPoolStrategy(ConsoleLogger logger, ExecutorService threadPool) {
- super(logger, threadPool);
- }
-
- @Override
- public boolean hasSharedThreadPool() {
- return false;
- }
-
- @Override
- public boolean finished() throws InterruptedException {
- boolean wasRunning = disable();
- getThreadPool().shutdown();
- getThreadPool().awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
- return wasRunning;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NullBalancer.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NullBalancer.java
deleted file mode 100644
index 7f5c2307a6..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NullBalancer.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * This balancer implements {@link Balancer} and does not do anything -no blocking operation.
- *
- * @author Tibor Digana (tibor17)
- * @see Balancer
- * @since 2.16
- */
-final class NullBalancer implements Balancer {
- @Override
- public boolean acquirePermit() {
- return true;
- }
-
- @Override
- public void releasePermit() {}
-
- @Override
- public void releaseAllPermits() {}
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputer.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputer.java
deleted file mode 100644
index ec14246970..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputer.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Collection;
-import java.util.TreeSet;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.ThreadFactory;
-
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.api.util.internal.DaemonThreadFactory;
-import org.junit.runner.Computer;
-import org.junit.runner.Description;
-
-import static java.util.concurrent.TimeUnit.NANOSECONDS;
-
-/**
- * ParallelComputer extends JUnit {@link Computer} and has a shutdown functionality.
- *
- * @author Tibor Digana (tibor17)
- * @see ParallelComputerBuilder
- * @since 2.16
- */
-public abstract class ParallelComputer extends Computer {
- private static final ThreadFactory DAEMON_THREAD_FACTORY = DaemonThreadFactory.newDaemonThreadFactory();
-
- private static final double NANOS_IN_A_SECOND = 1E9;
-
- private final ShutdownStatus shutdownStatus = new ShutdownStatus();
-
- private final ShutdownStatus forcedShutdownStatus = new ShutdownStatus();
-
- private final long timeoutNanos;
-
- private final long timeoutForcedNanos;
-
- private ScheduledExecutorService shutdownScheduler;
-
- public ParallelComputer(double timeoutInSeconds, double timeoutForcedInSeconds) {
- this.timeoutNanos = secondsToNanos(timeoutInSeconds);
- this.timeoutForcedNanos = secondsToNanos(timeoutForcedInSeconds);
- }
-
- protected abstract ShutdownResult describeStopped(boolean shutdownNow);
-
- protected abstract boolean shutdownThreadPoolsAwaitingKilled();
-
- protected final void beforeRunQuietly() {
- shutdownStatus.setDescriptionsBeforeShutdown(hasTimeout() ? scheduleShutdown() : null);
- forcedShutdownStatus.setDescriptionsBeforeShutdown(hasTimeoutForced() ? scheduleForcedShutdown() : null);
- }
-
- protected final boolean afterRunQuietly() {
- shutdownStatus.tryFinish();
- forcedShutdownStatus.tryFinish();
- boolean notInterrupted = true;
- if (shutdownScheduler != null) {
- shutdownScheduler.shutdownNow();
- /**
- * Clear interrupted status of the (main) Thread.
- * Could be previously interrupted by {@link InvokerStrategy} after triggering immediate shutdown.
- */
- Thread.interrupted();
- try {
- shutdownScheduler.awaitTermination(Long.MAX_VALUE, NANOSECONDS);
- } catch (InterruptedException e) {
- notInterrupted = false;
- }
- }
- notInterrupted &= shutdownThreadPoolsAwaitingKilled();
- return notInterrupted;
- }
-
- public String describeElapsedTimeout() throws TestSetFailedException {
- final StringBuilder msg = new StringBuilder();
- final boolean isShutdownTimeout = shutdownStatus.isTimeoutElapsed();
- final boolean isForcedShutdownTimeout = forcedShutdownStatus.isTimeoutElapsed();
- if (isShutdownTimeout || isForcedShutdownTimeout) {
- msg.append("The test run has finished abruptly after timeout of ");
- msg.append(nanosToSeconds(minTimeout(timeoutNanos, timeoutForcedNanos)));
- msg.append(" seconds.\n");
-
- try {
- final TreeSet executedTests = new TreeSet<>();
- final TreeSet incompleteTests = new TreeSet<>();
-
- if (isShutdownTimeout) {
- printShutdownHook(executedTests, incompleteTests, shutdownStatus.getDescriptionsBeforeShutdown());
- }
-
- if (isForcedShutdownTimeout) {
- printShutdownHook(
- executedTests, incompleteTests, forcedShutdownStatus.getDescriptionsBeforeShutdown());
- }
-
- if (!executedTests.isEmpty()) {
- msg.append("These tests were executed in prior to the shutdown operation:\n");
- for (String executedTest : executedTests) {
- msg.append(executedTest).append('\n');
- }
- }
-
- if (!incompleteTests.isEmpty()) {
- msg.append("These tests are incomplete:\n");
- for (String incompleteTest : incompleteTests) {
- msg.append(incompleteTest).append('\n');
- }
- }
- } catch (InterruptedException e) {
- throw new TestSetFailedException("Timed termination was interrupted.", e);
- } catch (ExecutionException e) {
- throw new TestSetFailedException(e.getLocalizedMessage(), e.getCause());
- }
- }
- return msg.toString();
- }
-
- private Future scheduleShutdown() {
- return getShutdownScheduler().schedule(createShutdownTask(), timeoutNanos, NANOSECONDS);
- }
-
- private Future scheduleForcedShutdown() {
- return getShutdownScheduler().schedule(createForcedShutdownTask(), timeoutForcedNanos, NANOSECONDS);
- }
-
- private ScheduledExecutorService getShutdownScheduler() {
- if (shutdownScheduler == null) {
- shutdownScheduler = Executors.newScheduledThreadPool(2, DAEMON_THREAD_FACTORY);
- }
- return shutdownScheduler;
- }
-
- private Callable createShutdownTask() {
- return new Callable() {
- @Override
- public ShutdownResult call() throws Exception {
- boolean stampedStatusWithTimeout = ParallelComputer.this.shutdownStatus.tryTimeout();
- return stampedStatusWithTimeout ? ParallelComputer.this.describeStopped(false) : null;
- }
- };
- }
-
- private Callable createForcedShutdownTask() {
- return new Callable() {
- @Override
- public ShutdownResult call() throws Exception {
- boolean stampedStatusWithTimeout = ParallelComputer.this.forcedShutdownStatus.tryTimeout();
- return stampedStatusWithTimeout ? ParallelComputer.this.describeStopped(true) : null;
- }
- };
- }
-
- private double nanosToSeconds(long nanos) {
- return (double) nanos / NANOS_IN_A_SECOND;
- }
-
- private boolean hasTimeout() {
- return timeoutNanos > 0;
- }
-
- private boolean hasTimeoutForced() {
- return timeoutForcedNanos > 0;
- }
-
- private static long secondsToNanos(double seconds) {
- double nanos = seconds > 0 ? seconds * NANOS_IN_A_SECOND : 0;
- return Double.isInfinite(nanos) || nanos >= Long.MAX_VALUE ? 0 : (long) nanos;
- }
-
- private static long minTimeout(long timeout1, long timeout2) {
- if (timeout1 == 0) {
- return timeout2;
- } else if (timeout2 == 0) {
- return timeout1;
- } else {
- return Math.min(timeout1, timeout2);
- }
- }
-
- private static void printShutdownHook(
- Collection executedTests,
- Collection incompleteTests,
- Future testsBeforeShutdown)
- throws ExecutionException, InterruptedException {
- if (testsBeforeShutdown != null) {
- final ShutdownResult shutdownResult = testsBeforeShutdown.get();
- if (shutdownResult != null) {
- for (final Description test : shutdownResult.getTriggeredTests()) {
- if (test != null && test.getDisplayName() != null) {
- executedTests.add(test.getDisplayName());
- }
- }
-
- for (final Description test : shutdownResult.getIncompleteTests()) {
- if (test != null && test.getDisplayName() != null) {
- incompleteTests.add(test.getDisplayName());
- }
- }
- }
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
deleted file mode 100755
index 08f365cf7d..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
+++ /dev/null
@@ -1,594 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.api.util.internal.DaemonThreadFactory;
-import org.apache.maven.surefire.junitcore.JUnitCoreParameters;
-import org.junit.internal.runners.ErrorReportingRunner;
-import org.junit.runner.Description;
-import org.junit.runner.Runner;
-import org.junit.runner.manipulation.Filter;
-import org.junit.runner.manipulation.NoTestsRemainException;
-import org.junit.runner.notification.RunNotifier;
-import org.junit.runners.ParentRunner;
-import org.junit.runners.Suite;
-import org.junit.runners.model.InitializationError;
-import org.junit.runners.model.RunnerBuilder;
-
-import static org.apache.maven.surefire.junitcore.pc.ParallelComputerUtil.resolveConcurrency;
-import static org.apache.maven.surefire.junitcore.pc.SchedulingStrategies.createParallelStrategy;
-import static org.apache.maven.surefire.junitcore.pc.SchedulingStrategies.createParallelStrategyUnbounded;
-import static org.apache.maven.surefire.junitcore.pc.Type.CLASSES;
-import static org.apache.maven.surefire.junitcore.pc.Type.METHODS;
-import static org.apache.maven.surefire.junitcore.pc.Type.SUITES;
-
-@SuppressWarnings({"javadoc", "checkstyle:javadoctype"})
-/*
- * Executing suites, classes and methods with defined concurrency. In this example the threads which completed
- * the suites and classes can be reused in parallel methods.
- *
- * JUnitCoreParameters parameters = ...;
- * ParallelComputerBuilder builder = new ParallelComputerBuilder(parameters);
- * builder.useOnePool(8).parallelSuites(2).parallelClasses(4).parallelMethods();
- * ParallelComputerBuilder.ParallelComputer computer = builder.buildComputer();
- * Class>[] tests = {...};
- * new JUnitCore().run(computer, tests);
- *
- * Note that the type has always at least one thread even if unspecified. The capacity in
- * {@link ParallelComputerBuilder#useOnePool(int)} must be greater than the number of concurrent suites and classes
- * altogether.
- *
- * The Computer can be stopped in a separate thread. Pending tests will be interrupted if the argument is
- * {@code true}.
- *
- * computer.describeStopped(true);
- *
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public final class ParallelComputerBuilder {
- private static final ThreadFactory DAEMON_THREAD_FACTORY = DaemonThreadFactory.newDaemonThreadFactory();
-
- private static final Class extends Annotation> JCIP_NOT_THREAD_SAFE = loadNotThreadSafeAnnotations();
-
- private static final Set NULL_SINGLETON = Collections.singleton(null);
-
- static final int TOTAL_POOL_SIZE_UNDEFINED = 0;
-
- private final Map parallelGroups = new EnumMap<>(Type.class);
-
- private final ConsoleLogger logger;
-
- private boolean useSeparatePools;
-
- private int totalPoolSize;
-
- private JUnitCoreParameters parameters;
-
- private boolean optimize;
-
- private boolean runningInTests;
-
- /**
- * Calling {@link #useSeparatePools()}.
- * Can be used only in unit tests.
- * Do NOT call this constructor in production.
- */
- ParallelComputerBuilder(ConsoleLogger logger) {
- this.logger = logger;
- runningInTests = true;
- useSeparatePools();
- parallelGroups.put(SUITES, 0);
- parallelGroups.put(CLASSES, 0);
- parallelGroups.put(METHODS, 0);
- }
-
- public ParallelComputerBuilder(ConsoleLogger logger, JUnitCoreParameters parameters) {
- this(logger);
- runningInTests = false;
- this.parameters = parameters;
- }
-
- public ParallelComputer buildComputer() {
- return new PC();
- }
-
- ParallelComputerBuilder useSeparatePools() {
- totalPoolSize = TOTAL_POOL_SIZE_UNDEFINED;
- useSeparatePools = true;
- return this;
- }
-
- ParallelComputerBuilder useOnePool() {
- totalPoolSize = TOTAL_POOL_SIZE_UNDEFINED;
- useSeparatePools = false;
- return this;
- }
-
- /**
- * @param totalPoolSize Pool size where suites, classes and methods are executed in parallel.
- * If the totalPoolSize is {@link Integer#MAX_VALUE}, the pool capacity is not
- * limited.
- * @throws IllegalArgumentException If totalPoolSize is < 1.
- */
- ParallelComputerBuilder useOnePool(int totalPoolSize) {
- if (totalPoolSize < 1) {
- throw new IllegalArgumentException("Size of common pool is less than 1.");
- }
- this.totalPoolSize = totalPoolSize;
- useSeparatePools = false;
- return this;
- }
-
- boolean isOptimized() {
- return optimize;
- }
-
- ParallelComputerBuilder optimize(boolean optimize) {
- this.optimize = optimize;
- return this;
- }
-
- ParallelComputerBuilder parallelSuites() {
- return parallel(SUITES);
- }
-
- ParallelComputerBuilder parallelSuites(int nThreads) {
- return parallel(nThreads, SUITES);
- }
-
- ParallelComputerBuilder parallelClasses() {
- return parallel(CLASSES);
- }
-
- ParallelComputerBuilder parallelClasses(int nThreads) {
- return parallel(nThreads, CLASSES);
- }
-
- ParallelComputerBuilder parallelMethods() {
- return parallel(METHODS);
- }
-
- ParallelComputerBuilder parallelMethods(int nThreads) {
- return parallel(nThreads, METHODS);
- }
-
- private ParallelComputerBuilder parallel(int nThreads, Type parallelType) {
- if (nThreads < 0) {
- throw new IllegalArgumentException("negative nThreads " + nThreads);
- }
-
- if (parallelType == null) {
- throw new IllegalArgumentException("null parallelType");
- }
-
- parallelGroups.put(parallelType, nThreads);
- return this;
- }
-
- private ParallelComputerBuilder parallel(Type parallelType) {
- return parallel(Integer.MAX_VALUE, parallelType);
- }
-
- private double parallelTestsTimeoutInSeconds() {
- return parameters == null ? 0d : parameters.getParallelTestsTimeoutInSeconds();
- }
-
- private double parallelTestsTimeoutForcedInSeconds() {
- return parameters == null ? 0d : parameters.getParallelTestsTimeoutForcedInSeconds();
- }
-
- @SuppressWarnings("unchecked")
- private static Class extends Annotation> loadNotThreadSafeAnnotations() {
- try {
- Class c = Class.forName("net.jcip.annotations.NotThreadSafe");
- return c.isAnnotation() ? (Class extends Annotation>) c : null;
- } catch (ClassNotFoundException e) {
- return null;
- }
- }
-
- final class PC extends ParallelComputer {
- private final SingleThreadScheduler notThreadSafeTests =
- new SingleThreadScheduler(ParallelComputerBuilder.this.logger);
-
- private final Collection suites = new LinkedHashSet<>();
-
- private final Collection nestedSuites = new LinkedHashSet<>();
-
- private final Collection classes = new LinkedHashSet<>();
-
- private final Collection nestedClasses = new LinkedHashSet<>();
-
- private final Collection notParallelRunners = new LinkedHashSet<>();
-
- private int poolCapacity;
-
- private boolean splitPool;
-
- private final Map allGroups;
-
- private long nestedClassesChildren;
-
- private volatile Scheduler master;
-
- private PC() {
- super(parallelTestsTimeoutInSeconds(), parallelTestsTimeoutForcedInSeconds());
- allGroups = new EnumMap<>(ParallelComputerBuilder.this.parallelGroups);
- poolCapacity = ParallelComputerBuilder.this.totalPoolSize;
- splitPool = ParallelComputerBuilder.this.useSeparatePools;
- }
-
- Collection getSuites() {
- return suites;
- }
-
- Collection getNestedSuites() {
- return nestedSuites;
- }
-
- Collection getClasses() {
- return classes;
- }
-
- Collection getNestedClasses() {
- return nestedClasses;
- }
-
- Collection getNotParallelRunners() {
- return notParallelRunners;
- }
-
- int getPoolCapacity() {
- return poolCapacity;
- }
-
- boolean isSplitPool() {
- return splitPool;
- }
-
- @Override
- protected ShutdownResult describeStopped(boolean shutdownNow) {
- ShutdownResult shutdownResult = notThreadSafeTests.describeStopped(shutdownNow);
- final Scheduler m = master;
- if (m != null) {
- ShutdownResult shutdownResultOfMaster = m.describeStopped(shutdownNow);
- shutdownResult.getTriggeredTests().addAll(shutdownResultOfMaster.getTriggeredTests());
- shutdownResult.getIncompleteTests().addAll(shutdownResultOfMaster.getIncompleteTests());
- }
- return shutdownResult;
- }
-
- @Override
- protected boolean shutdownThreadPoolsAwaitingKilled() {
- boolean notInterrupted = notThreadSafeTests.shutdownThreadPoolsAwaitingKilled();
- final Scheduler m = master;
- if (m != null) {
- notInterrupted &= m.shutdownThreadPoolsAwaitingKilled();
- }
- return notInterrupted;
- }
-
- @Override
- public Runner getSuite(RunnerBuilder builder, Class>[] cls) throws InitializationError {
- try {
- super.getSuite(builder, cls);
- populateChildrenFromSuites();
-
- WrappedRunners suiteSuites = wrapRunners(suites);
- WrappedRunners suiteClasses = wrapRunners(classes);
-
- long suitesCount = suites.size();
- long classesCount = classes.size() + nestedClasses.size();
- long methodsCount = suiteClasses.embeddedChildrenCount + nestedClassesChildren;
- if (!ParallelComputerBuilder.this.runningInTests) {
- determineThreadCounts(suitesCount, classesCount, methodsCount);
- }
-
- return setSchedulers(suiteSuites.wrappingSuite, suiteClasses.wrappingSuite);
- } catch (TestSetFailedException e) {
- throw new InitializationError(Collections.singletonList(e));
- }
- }
-
- @Override
- protected Runner getRunner(RunnerBuilder builder, Class> testClass) throws Throwable {
- Runner runner = super.getRunner(builder, testClass);
- if (canSchedule(runner)) {
- if (!isThreadSafe(runner)) {
- ((ParentRunner) runner).setScheduler(notThreadSafeTests.newRunnerScheduler());
- notParallelRunners.add(runner);
- } else if (runner instanceof Suite) {
- suites.add((Suite) runner);
- } else {
- classes.add((ParentRunner) runner);
- }
- } else {
- notParallelRunners.add(runner);
- }
- return runner;
- }
-
- private void determineThreadCounts(long suites, long classes, long methods) throws TestSetFailedException {
- RunnerCounter counts =
- ParallelComputerBuilder.this.optimize ? new RunnerCounter(suites, classes, methods) : null;
- Concurrency concurrency = resolveConcurrency(ParallelComputerBuilder.this.parameters, counts);
- allGroups.put(SUITES, concurrency.suites);
- allGroups.put(CLASSES, concurrency.classes);
- allGroups.put(METHODS, concurrency.methods);
- poolCapacity = concurrency.capacity;
- splitPool &= concurrency.capacity <= 0; // fault if negative; should not happen
- }
-
- private WrappedRunners wrapRunners(Collection runners) throws InitializationError {
- // Do NOT use allGroups here.
- long childrenCounter = 0;
- ArrayList runs = new ArrayList<>();
- for (T runner : runners) {
- if (runner != null) {
- int children = countChildren(runner);
- childrenCounter += children;
- runs.add(runner);
- }
- }
- return runs.isEmpty() ? new WrappedRunners() : new WrappedRunners(createSuite(runs), childrenCounter);
- }
-
- private int countChildren(Runner runner) {
- Description description = runner.getDescription();
- Collection children = description == null ? null : description.getChildren();
- return children == null ? 0 : children.size();
- }
-
- private ExecutorService createPool(int poolSize) {
- return poolSize < Integer.MAX_VALUE
- ? Executors.newFixedThreadPool(poolSize, DAEMON_THREAD_FACTORY)
- : Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY);
- }
-
- private Scheduler createMaster(ExecutorService pool, int poolSize) {
- // can be 0, 1, 2 or 3
- final int finalRunnersCounter = countFinalRunners();
-
- final SchedulingStrategy strategy;
- if (finalRunnersCounter <= 1 || poolSize <= 1) {
- strategy = new InvokerStrategy(ParallelComputerBuilder.this.logger);
- } else if (pool != null && poolSize == Integer.MAX_VALUE) {
- strategy = new SharedThreadPoolStrategy(ParallelComputerBuilder.this.logger, pool);
- } else {
- strategy = createParallelStrategy(ParallelComputerBuilder.this.logger, finalRunnersCounter);
- }
- return new Scheduler(ParallelComputerBuilder.this.logger, null, strategy);
- }
-
- private int countFinalRunners() {
- int counter = notParallelRunners.isEmpty() ? 0 : 1;
-
- if (!suites.isEmpty() && allGroups.get(SUITES) > 0) {
- ++counter;
- }
-
- if (!classes.isEmpty() && allGroups.get(CLASSES) > 0) {
- ++counter;
- }
-
- return counter;
- }
-
- private void populateChildrenFromSuites() {
- // Do NOT use allGroups here.
- Filter filter = new SuiteFilter();
- for (Iterator it = suites.iterator(); it.hasNext(); ) {
- ParentRunner suite = it.next();
- try {
- suite.filter(filter);
- } catch (NoTestsRemainException e) {
- it.remove();
- }
- }
- }
-
- private int totalPoolSize() {
- if (poolCapacity == TOTAL_POOL_SIZE_UNDEFINED) {
- int total = 0;
- for (int nThreads : allGroups.values()) {
- total += nThreads;
- if (total < 0) {
- total = Integer.MAX_VALUE;
- break;
- }
- }
- return total;
- } else {
- return poolCapacity;
- }
- }
-
- private Runner setSchedulers(ParentRunner suiteSuites, ParentRunner suiteClasses) throws InitializationError {
- int parallelSuites = allGroups.get(SUITES);
- int parallelClasses = allGroups.get(CLASSES);
- int parallelMethods = allGroups.get(METHODS);
- int poolSize = totalPoolSize();
- ExecutorService commonPool = splitPool || poolSize == 0 ? null : createPool(poolSize);
- master = createMaster(commonPool, poolSize);
-
- if (suiteSuites != null) {
- // a scheduler for parallel suites
- if (commonPool != null && parallelSuites > 0) {
- Balancer balancer = BalancerFactory.createBalancerWithFairness(parallelSuites);
- suiteSuites.setScheduler(createScheduler(null, commonPool, true, balancer));
- } else {
- suiteSuites.setScheduler(createScheduler(parallelSuites));
- }
- }
-
- // schedulers for parallel classes
- ArrayList allSuites = new ArrayList<>(suites);
- allSuites.addAll(nestedSuites);
- if (suiteClasses != null) {
- allSuites.add(suiteClasses);
- }
- if (!allSuites.isEmpty()) {
- setSchedulers(allSuites, parallelClasses, commonPool);
- }
-
- // schedulers for parallel methods
- ArrayList allClasses = new ArrayList<>(classes);
- allClasses.addAll(nestedClasses);
- if (!allClasses.isEmpty()) {
- setSchedulers(allClasses, parallelMethods, commonPool);
- }
-
- // resulting runner for Computer#getSuite() scheduled by master scheduler
- ParentRunner all = createFinalRunner(removeNullRunners(
- Arrays.asList(suiteSuites, suiteClasses, createSuite(notParallelRunners))));
- all.setScheduler(master);
- return all;
- }
-
- private ParentRunner createFinalRunner(List runners) throws InitializationError {
- return new Suite(null, runners) {
- @Override
- public void run(RunNotifier notifier) {
- try {
- beforeRunQuietly();
- super.run(notifier);
- } finally {
- afterRunQuietly();
- }
- }
- };
- }
-
- private void setSchedulers(Iterable extends ParentRunner> runners, int poolSize, ExecutorService commonPool) {
- if (commonPool != null) {
- Balancer concurrencyLimit = BalancerFactory.createBalancerWithFairness(poolSize);
- boolean doParallel = poolSize > 0;
- for (ParentRunner runner : runners) {
- runner.setScheduler(
- createScheduler(runner.getDescription(), commonPool, doParallel, concurrencyLimit));
- }
- } else {
- ExecutorService pool = null;
- if (poolSize == Integer.MAX_VALUE) {
- pool = Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY);
- } else if (poolSize > 0) {
- pool = Executors.newFixedThreadPool(poolSize, DAEMON_THREAD_FACTORY);
- }
- boolean doParallel = pool != null;
- for (ParentRunner runner : runners) {
- runner.setScheduler(createScheduler(
- runner.getDescription(),
- pool,
- doParallel,
- BalancerFactory.createInfinitePermitsBalancer()));
- }
- }
- }
-
- private Scheduler createScheduler(
- Description desc, ExecutorService pool, boolean doParallel, Balancer concurrency) {
- SchedulingStrategy strategy = doParallel & pool != null
- ? new SharedThreadPoolStrategy(ParallelComputerBuilder.this.logger, pool)
- : new InvokerStrategy(ParallelComputerBuilder.this.logger);
- return new Scheduler(ParallelComputerBuilder.this.logger, desc, master, strategy, concurrency);
- }
-
- private Scheduler createScheduler(int poolSize) {
- final SchedulingStrategy strategy;
- if (poolSize == Integer.MAX_VALUE) {
- strategy = createParallelStrategyUnbounded(ParallelComputerBuilder.this.logger);
- } else if (poolSize == 0) {
- strategy = new InvokerStrategy(ParallelComputerBuilder.this.logger);
- } else {
- strategy = createParallelStrategy(ParallelComputerBuilder.this.logger, poolSize);
- }
- return new Scheduler(ParallelComputerBuilder.this.logger, null, master, strategy);
- }
-
- private boolean canSchedule(Runner runner) {
- return !(runner instanceof ErrorReportingRunner) && runner instanceof ParentRunner;
- }
-
- private boolean isThreadSafe(Runner runner) {
- return runner.getDescription().getAnnotation(JCIP_NOT_THREAD_SAFE) == null;
- }
-
- private class SuiteFilter extends Filter {
- // Do NOT use allGroups in SuiteFilter.
-
- @Override
- public boolean shouldRun(Description description) {
- return true;
- }
-
- @Override
- public void apply(Object child) throws NoTestsRemainException {
- super.apply(child);
- if (child instanceof ParentRunner) {
- ParentRunner runner = (ParentRunner) child;
- if (!isThreadSafe(runner)) {
- runner.setScheduler(notThreadSafeTests.newRunnerScheduler());
- } else if (child instanceof Suite) {
- nestedSuites.add((Suite) child);
- } else {
- ParentRunner parentRunner = (ParentRunner) child;
- nestedClasses.add(parentRunner);
- nestedClassesChildren +=
- parentRunner.getDescription().getChildren().size();
- }
- }
- }
-
- @Override
- public String describe() {
- return "";
- }
- }
- }
-
- private static Suite createSuite(Collection runners) throws InitializationError {
- final List onlyRunners = removeNullRunners(runners);
- return onlyRunners.isEmpty() ? null : new Suite(null, onlyRunners) {};
- }
-
- private static List removeNullRunners(Collection runners) {
- final List onlyRunners = new ArrayList<>(runners);
- onlyRunners.removeAll(NULL_SINGLETON);
- return onlyRunners;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtil.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtil.java
deleted file mode 100644
index 95b0bb3d81..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerUtil.java
+++ /dev/null
@@ -1,331 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.junitcore.JUnitCoreParameters;
-import org.junit.runner.Description;
-
-/**
- * An algorithm which configures {@link ParallelComputer} with allocated thread resources by given
- * {@link org.apache.maven.surefire.junitcore.JUnitCoreParameters}.
- * The {@code AbstractSurefireMojo} has to provide correct combinations of thread-counts and
- * configuration parameter {@code parallel}.
- *
- * @author Tibor Digana (tibor17)
- * @see org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder
- * @since 2.16
- */
-final class ParallelComputerUtil {
- private static final Collection UNUSED_DESCRIPTIONS = Arrays.asList(
- null, Description.createSuiteDescription("null"), Description.TEST_MECHANISM, Description.EMPTY);
-
- private static int availableProcessors = Runtime.getRuntime().availableProcessors();
-
- private ParallelComputerUtil() {
- throw new IllegalStateException("Suppresses calling constructor, ensuring non-instantiability.");
- }
-
- /*
- * For testing purposes.
- */
- static void overrideAvailableProcessors(int availableProcessors) {
- ParallelComputerUtil.availableProcessors = availableProcessors;
- }
-
- /*
- * For testing purposes.
- */
- static void setDefaultAvailableProcessors() {
- ParallelComputerUtil.availableProcessors = Runtime.getRuntime().availableProcessors();
- }
-
- static Concurrency resolveConcurrency(JUnitCoreParameters params, RunnerCounter counts)
- throws TestSetFailedException {
- if (!params.isParallelismSelected()) {
- throw new TestSetFailedException("Unspecified parameter '" + JUnitCoreParameters.PARALLEL_KEY + "'.");
- }
-
- if (!params.isUseUnlimitedThreads() && !hasThreadCount(params) && !hasThreadCounts(params)) {
- throw new TestSetFailedException("Unspecified thread-count(s). "
- + "See the parameters "
- + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY + ", "
- + JUnitCoreParameters.THREADCOUNT_KEY + ", "
- + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", "
- + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", "
- + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + ".");
- }
-
- if (params.isUseUnlimitedThreads()) {
- return concurrencyForUnlimitedThreads(params);
- } else if (hasThreadCount(params)) {
- if (hasThreadCounts(params)) {
- return isLeafUnspecified(params)
- ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount(params, counts)
- : concurrencyFromAllThreadCounts(params);
- } else {
- return estimateConcurrency(params, counts);
- }
- } else {
- return concurrencyFromThreadCounts(params);
- }
- }
-
- static boolean isUnusedDescription(Description examined) {
- if (UNUSED_DESCRIPTIONS.contains(examined)) {
- return true;
- } else {
- // UNUSED_DESCRIPTIONS ensures that "examined" cannot be null
- for (Description unused : UNUSED_DESCRIPTIONS) {
- if (unused != null && unused.getDisplayName().equals(examined.getDisplayName())) {
- return true;
- }
- }
- return false;
- }
- }
-
- static void removeUnusedDescriptions(Collection examined) {
- for (Iterator it = examined.iterator(); it.hasNext(); ) {
- if (isUnusedDescription(it.next())) {
- it.remove();
- }
- }
- }
-
- private static Concurrency concurrencyForUnlimitedThreads(JUnitCoreParameters params) {
- Concurrency concurrency = new Concurrency();
- concurrency.suites = params.isParallelSuites() ? threadCountSuites(params) : 0;
- concurrency.classes = params.isParallelClasses() ? threadCountClasses(params) : 0;
- concurrency.methods = params.isParallelMethods() ? threadCountMethods(params) : 0;
- concurrency.capacity = Integer.MAX_VALUE;
- return concurrency;
- }
-
- private static Concurrency estimateConcurrency(JUnitCoreParameters params, RunnerCounter counts) {
- final Concurrency concurrency = new Concurrency();
- final int parallelEntities = countParallelEntities(params);
- concurrency.capacity = multiplyByCoreCount(params, params.getThreadCount());
- if (parallelEntities == 1 || counts == null || counts.classes == 0) {
- // Estimate parallel thread counts.
- double ratio = 1d / parallelEntities;
- int threads = multiplyByCoreCount(params, ratio * params.getThreadCount());
- concurrency.suites = params.isParallelSuites() ? minSuites(threads, counts) : 0;
- concurrency.classes = params.isParallelClasses() ? minClasses(threads, counts) : 0;
- concurrency.methods = params.isParallelMethods() ? minMethods(threads, counts) : 0;
- if (parallelEntities == 1) {
- concurrency.capacity = 0;
- } else {
- adjustLeaf(params, concurrency);
- }
- } else {
- // Try to allocate suites+classes+methods within threadCount,
- concurrency.suites = params.isParallelSuites() ? toNonNegative(counts.suites) : 0;
- concurrency.classes = params.isParallelClasses() ? toNonNegative(counts.classes) : 0;
- concurrency.methods =
- params.isParallelMethods() ? toNonNegative(Math.ceil(counts.methods / (double) counts.classes)) : 0;
- double sum = toNonNegative(concurrency.suites + concurrency.classes + concurrency.methods);
- if (concurrency.capacity < sum && sum != 0) {
- // otherwise allocate them using the weighting factor < 1.
- double weight = concurrency.capacity / sum;
- concurrency.suites *= weight;
- concurrency.classes *= weight;
- concurrency.methods *= weight;
- }
- adjustLeaf(params, concurrency);
- }
- return concurrency;
- }
-
- private static Concurrency concurrencyFromAllThreadCountsButUnspecifiedLeafCount(
- JUnitCoreParameters params, RunnerCounter counts) {
- Concurrency concurrency = new Concurrency();
- concurrency.suites = params.isParallelSuites() ? params.getThreadCountSuites() : 0;
- concurrency.suites = params.isParallelSuites() ? multiplyByCoreCount(params, concurrency.suites) : 0;
- concurrency.classes = params.isParallelClasses() ? params.getThreadCountClasses() : 0;
- concurrency.classes = params.isParallelClasses() ? multiplyByCoreCount(params, concurrency.classes) : 0;
- concurrency.methods = params.isParallelMethods() ? params.getThreadCountMethods() : 0;
- concurrency.methods = params.isParallelMethods() ? multiplyByCoreCount(params, concurrency.methods) : 0;
- concurrency.capacity = multiplyByCoreCount(params, params.getThreadCount());
-
- if (counts != null) {
- concurrency.suites = toNonNegative(Math.min(concurrency.suites, counts.suites));
- concurrency.classes = toNonNegative(Math.min(concurrency.classes, counts.classes));
- }
-
- setLeafInfinite(params, concurrency);
-
- return concurrency;
- }
-
- private static Concurrency concurrencyFromAllThreadCounts(JUnitCoreParameters params) {
- Concurrency concurrency = new Concurrency();
- concurrency.suites = params.isParallelSuites() ? params.getThreadCountSuites() : 0;
- concurrency.classes = params.isParallelClasses() ? params.getThreadCountClasses() : 0;
- concurrency.methods = params.isParallelMethods() ? params.getThreadCountMethods() : 0;
- concurrency.capacity = params.getThreadCount();
- double all = sumThreadCounts(concurrency);
-
- concurrency.suites = params.isParallelSuites()
- ? multiplyByCoreCount(params, concurrency.capacity * (concurrency.suites / all))
- : 0;
-
- concurrency.classes = params.isParallelClasses()
- ? multiplyByCoreCount(params, concurrency.capacity * (concurrency.classes / all))
- : 0;
-
- concurrency.methods = params.isParallelMethods()
- ? multiplyByCoreCount(params, concurrency.capacity * (concurrency.methods / all))
- : 0;
-
- concurrency.capacity = multiplyByCoreCount(params, concurrency.capacity);
- adjustPrecisionInLeaf(params, concurrency);
- return concurrency;
- }
-
- private static Concurrency concurrencyFromThreadCounts(JUnitCoreParameters params) {
- Concurrency concurrency = new Concurrency();
- concurrency.suites = params.isParallelSuites() ? threadCountSuites(params) : 0;
- concurrency.classes = params.isParallelClasses() ? threadCountClasses(params) : 0;
- concurrency.methods = params.isParallelMethods() ? threadCountMethods(params) : 0;
- concurrency.capacity = toNonNegative(sumThreadCounts(concurrency));
- return concurrency;
- }
-
- private static int countParallelEntities(JUnitCoreParameters params) {
- int count = 0;
- if (params.isParallelSuites()) {
- count++;
- }
-
- if (params.isParallelClasses()) {
- count++;
- }
-
- if (params.isParallelMethods()) {
- count++;
- }
- return count;
- }
-
- private static void adjustPrecisionInLeaf(JUnitCoreParameters params, Concurrency concurrency) {
- if (params.isParallelMethods()) {
- concurrency.methods = concurrency.capacity - concurrency.suites - concurrency.classes;
- } else if (params.isParallelClasses()) {
- concurrency.classes = concurrency.capacity - concurrency.suites;
- }
- }
-
- private static void adjustLeaf(JUnitCoreParameters params, Concurrency concurrency) {
- if (params.isParallelMethods()) {
- concurrency.methods = Integer.MAX_VALUE;
- } else if (params.isParallelClasses()) {
- concurrency.classes = Integer.MAX_VALUE;
- }
- }
-
- private static void setLeafInfinite(JUnitCoreParameters params, Concurrency concurrency) {
- if (params.isParallelMethods()) {
- concurrency.methods = Integer.MAX_VALUE;
- } else if (params.isParallelClasses()) {
- concurrency.classes = Integer.MAX_VALUE;
- } else if (params.isParallelSuites()) {
- concurrency.suites = Integer.MAX_VALUE;
- }
- }
-
- private static boolean isLeafUnspecified(JUnitCoreParameters params) {
- int maskOfParallel = params.isParallelSuites() ? 4 : 0;
- maskOfParallel |= params.isParallelClasses() ? 2 : 0;
- maskOfParallel |= params.isParallelMethods() ? 1 : 0;
-
- int maskOfConcurrency = params.getThreadCountSuites() > 0 ? 4 : 0;
- maskOfConcurrency |= params.getThreadCountClasses() > 0 ? 2 : 0;
- maskOfConcurrency |= params.getThreadCountMethods() > 0 ? 1 : 0;
-
- maskOfConcurrency &= maskOfParallel;
-
- int leaf = Integer.lowestOneBit(maskOfParallel);
- return maskOfConcurrency == maskOfParallel - leaf;
- }
-
- private static double sumThreadCounts(Concurrency concurrency) {
- double sum = concurrency.suites;
- sum += concurrency.classes;
- sum += concurrency.methods;
- return sum;
- }
-
- private static boolean hasThreadCounts(JUnitCoreParameters jUnitCoreParameters) {
- return (jUnitCoreParameters.isParallelSuites() && jUnitCoreParameters.getThreadCountSuites() > 0)
- || (jUnitCoreParameters.isParallelClasses() && jUnitCoreParameters.getThreadCountClasses() > 0)
- || (jUnitCoreParameters.isParallelMethods() && jUnitCoreParameters.getThreadCountMethods() > 0);
- }
-
- private static boolean hasThreadCount(JUnitCoreParameters jUnitCoreParameters) {
- return jUnitCoreParameters.getThreadCount() > 0;
- }
-
- private static int threadCountMethods(JUnitCoreParameters jUnitCoreParameters) {
- return multiplyByCoreCount(jUnitCoreParameters, jUnitCoreParameters.getThreadCountMethods());
- }
-
- private static int threadCountClasses(JUnitCoreParameters jUnitCoreParameters) {
- return multiplyByCoreCount(jUnitCoreParameters, jUnitCoreParameters.getThreadCountClasses());
- }
-
- private static int threadCountSuites(JUnitCoreParameters jUnitCoreParameters) {
- return multiplyByCoreCount(jUnitCoreParameters, jUnitCoreParameters.getThreadCountSuites());
- }
-
- private static int multiplyByCoreCount(JUnitCoreParameters jUnitCoreParameters, double threadsPerCore) {
- double numberOfThreads = jUnitCoreParameters.isPerCoreThreadCount()
- ? threadsPerCore * (double) availableProcessors
- : threadsPerCore;
-
- return numberOfThreads > 0 ? toNonNegative(numberOfThreads) : Integer.MAX_VALUE;
- }
-
- private static int minSuites(int threads, RunnerCounter counts) {
- long count = counts == null ? Integer.MAX_VALUE : counts.suites;
- return Math.min(threads, toNonNegative(count));
- }
-
- private static int minClasses(int threads, RunnerCounter counts) {
- long count = counts == null ? Integer.MAX_VALUE : counts.classes;
- return Math.min(threads, toNonNegative(count));
- }
-
- private static int minMethods(int threads, RunnerCounter counts) {
- long count = counts == null ? Integer.MAX_VALUE : counts.methods;
- return Math.min(threads, toNonNegative(count));
- }
-
- private static int toNonNegative(long num) {
- return (int) Math.min(num > 0 ? num : 0, Integer.MAX_VALUE);
- }
-
- private static int toNonNegative(double num) {
- return (int) Math.min(num > 0 ? num : 0, Integer.MAX_VALUE);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/RunnerCounter.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/RunnerCounter.java
deleted file mode 100644
index 55e7e64b2f..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/RunnerCounter.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * Counts number of JUnit suites, classes and methods.
- *
- * @author tibor17 (Tibor Digana)
- * @see ParallelComputerBuilder
- * @since 2.17
- */
-final class RunnerCounter {
- final long suites;
-
- final long classes;
-
- final long methods;
-
- RunnerCounter(long suites, long classes, long methods) {
- this.suites = suites;
- this.classes = classes;
- this.methods = methods;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Scheduler.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Scheduler.java
deleted file mode 100644
index b92f53f376..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Scheduler.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Collection;
-import java.util.Set;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.CopyOnWriteArraySet;
-import java.util.concurrent.RejectedExecutionException;
-import java.util.concurrent.RejectedExecutionHandler;
-import java.util.concurrent.ThreadPoolExecutor;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.junit.runner.Description;
-import org.junit.runners.model.RunnerScheduler;
-
-/**
- * Schedules tests, controls thread resources, awaiting tests and other schedulers finished, and
- * a master scheduler can shutdown slaves.
- *
- * The scheduler objects should be first created (and wired) and set in runners
- * {@link org.junit.runners.ParentRunner#setScheduler(org.junit.runners.model.RunnerScheduler)}.
- *
- * A new instance of scheduling strategy should be passed to the constructor of this scheduler.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public class Scheduler implements RunnerScheduler {
- private final Balancer balancer;
-
- private final SchedulingStrategy strategy;
-
- private final Set slaves = new CopyOnWriteArraySet<>();
-
- private final Description description;
-
- private final ConsoleLogger logger;
-
- private volatile boolean shutdown = false;
-
- private volatile boolean started = false;
-
- private volatile boolean finished = false;
-
- private volatile Controller masterController;
-
- /**
- * Use e.g. parallel classes have own non-shared thread pool, and methods another pool.
- *
- * You can use it with one infinite thread pool shared in strategies across all
- * suites, class runners, etc.
- *
- * @param logger console logger
- * @param description JUnit description of class
- * @param strategy scheduling strategy
- */
- public Scheduler(ConsoleLogger logger, Description description, SchedulingStrategy strategy) {
- this(logger, description, strategy, -1);
- }
-
- /**
- * Should be used if schedulers in parallel children and parent use one instance of bounded thread pool.
- *
- * Set this scheduler in a e.g. one suite of classes, then every individual class runner should reference
- * {@link #Scheduler(ConsoleLogger, org.junit.runner.Description, Scheduler, SchedulingStrategy)}
- * or {@link #Scheduler(ConsoleLogger, org.junit.runner.Description, Scheduler, SchedulingStrategy, int)}.
- *
- * @param logger current logger implementation
- * @param description description of current runner
- * @param strategy scheduling strategy with a shared thread pool
- * @param concurrency determines maximum concurrent children scheduled a time via {@link #schedule(Runnable)}
- * @throws NullPointerException if null strategy
- */
- public Scheduler(ConsoleLogger logger, Description description, SchedulingStrategy strategy, int concurrency) {
- this(logger, description, strategy, BalancerFactory.createBalancer(concurrency));
- }
-
- /**
- * New instances should be used by schedulers with limited concurrency by balancer
- * against other groups of schedulers. The schedulers share one pool.
- *
- * Unlike in {@link #Scheduler(ConsoleLogger, org.junit.runner.Description, SchedulingStrategy, int)} which was
- * limiting the concurrency of children of a runner where this scheduler was set, {@code this}
- * balancer is limiting the concurrency of all children in runners having schedulers created by this
- * constructor.
- *
- * @param logger current logger implementation
- * @param description description of current runner
- * @param strategy scheduling strategy which may share threads with other strategy
- * @param balancer determines maximum concurrent children scheduled a time via {@link #schedule(Runnable)}
- * @throws NullPointerException if null strategy or balancer
- */
- public Scheduler(ConsoleLogger logger, Description description, SchedulingStrategy strategy, Balancer balancer) {
- strategy.setDefaultShutdownHandler(newShutdownHandler());
- this.logger = logger;
- this.description = description;
- this.strategy = strategy;
- this.balancer = balancer;
- masterController = null;
- }
-
- /**
- * Can be used by e.g. a runner having parallel classes in use case with parallel
- * suites, classes and methods sharing the same thread pool.
- *
- * @param logger current logger implementation
- * @param description description of current runner
- * @param masterScheduler scheduler sharing own threads with this slave
- * @param strategy scheduling strategy for this scheduler
- * @param balancer determines maximum concurrent children scheduled a time via {@link #schedule(Runnable)}
- * @throws NullPointerException if null masterScheduler, strategy or balancer
- */
- public Scheduler(
- ConsoleLogger logger,
- Description description,
- Scheduler masterScheduler,
- SchedulingStrategy strategy,
- Balancer balancer) {
- this(logger, description, strategy, balancer);
- strategy.setDefaultShutdownHandler(newShutdownHandler());
- masterScheduler.register(this);
- }
-
- /**
- * @param logger console logger
- * @param description JUnit description of class
- * @param masterScheduler a reference to
- * {@link #Scheduler(ConsoleLogger, org.junit.runner.Description, SchedulingStrategy, int)}
- * or {@link #Scheduler(ConsoleLogger, org.junit.runner.Description, SchedulingStrategy)}
- * @param strategy scheduling strategy
- * @param concurrency determines maximum concurrent children scheduled a time via {@link #schedule(Runnable)}
- *
- * @see #Scheduler(ConsoleLogger, org.junit.runner.Description, SchedulingStrategy)
- * @see #Scheduler(ConsoleLogger, org.junit.runner.Description, SchedulingStrategy, int)
- */
- public Scheduler(
- ConsoleLogger logger,
- Description description,
- Scheduler masterScheduler,
- SchedulingStrategy strategy,
- int concurrency) {
- this(logger, description, strategy, concurrency);
- strategy.setDefaultShutdownHandler(newShutdownHandler());
- masterScheduler.register(this);
- }
-
- /**
- * Should be used with individual pools on suites, classes and methods, see
- * {@link org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder#useSeparatePools()}.
- *
- * Cached thread pool is infinite and can be always shared.
- *
- * @param logger console logger
- * @param description JUnit description of class
- * @param masterScheduler parent scheduler
- * @param strategy scheduling strategy
- */
- public Scheduler(
- ConsoleLogger logger, Description description, Scheduler masterScheduler, SchedulingStrategy strategy) {
- this(logger, description, masterScheduler, strategy, 0);
- }
-
- private void setController(Controller masterController) {
- if (masterController == null) {
- throw new NullPointerException("null ExecutionController");
- }
- this.masterController = masterController;
- }
-
- /**
- * @param slave a slave scheduler to register
- * @return {@code true} if successfully registered the slave.
- */
- private boolean register(Scheduler slave) {
- boolean canRegister = slave != null && slave != this;
- if (canRegister) {
- Controller controller = new Controller(slave);
- canRegister = !slaves.contains(controller);
- if (canRegister) {
- slaves.add(controller);
- slave.setController(controller);
- }
- }
- return canRegister;
- }
-
- /**
- * @return {@code true} if new tasks can be scheduled.
- */
- private boolean canSchedule() {
- return !shutdown && (masterController == null || masterController.canSchedule());
- }
-
- protected void logQuietly(Throwable t) {
- logger.error(t);
- }
-
- protected void logQuietly(String msg) {
- logger.warning(msg);
- }
-
- /**
- * Attempts to stop all actively executing tasks and immediately returns a collection
- * of descriptions of those tasks which have started prior to this call.
- *
- * This scheduler and other registered schedulers will stop, see {@link #register(Scheduler)}.
- * If shutdownNow is set, waiting methods will be interrupted via {@link Thread#interrupt}.
- *
- * @param stopNow if {@code true} interrupts waiting test methods
- * @return collection of descriptions started before shutting down
- */
- protected ShutdownResult describeStopped(boolean stopNow) {
- Collection executedTests = new ConcurrentLinkedQueue<>();
- Collection incompleteTests = new ConcurrentLinkedQueue<>();
- stop(executedTests, incompleteTests, false, stopNow);
- return new ShutdownResult(executedTests, incompleteTests);
- }
-
- /**
- * Stop/Shutdown/Interrupt scheduler and its children (if any).
- *
- * @param executedTests Started tests which have finished normally or abruptly till called this method.
- * @param incompleteTests Started tests which have finished incomplete due to shutdown.
- * @param tryCancelFutures Useful to set to {@code false} if a timeout is specified in plugin config.
- * When the runner of
- * {@link ParallelComputer#getSuite(org.junit.runners.model.RunnerBuilder, Class[])}
- * is finished in
- * {@link org.junit.runners.Suite#run(org.junit.runner.notification.RunNotifier)}
- * all the thread-pools created by {@link ParallelComputerBuilder.PC} are already dead.
- * See the unit test {@code ParallelComputerBuilder#timeoutAndForcedShutdown()}.
- * @param stopNow Interrupting tests by {@link java.util.concurrent.ExecutorService#shutdownNow()} or
- * {@link java.util.concurrent.Future#cancel(boolean) Future#cancel(true)} or
- * {@link Thread#interrupt()}.
- */
- private void stop(
- Collection executedTests,
- Collection incompleteTests,
- boolean tryCancelFutures,
- boolean stopNow) {
- shutdown = true;
- try {
- if (started && !ParallelComputerUtil.isUnusedDescription(description)) {
- if (executedTests != null) {
- executedTests.add(description);
- }
-
- if (incompleteTests != null && !finished) {
- incompleteTests.add(description);
- }
- }
-
- for (Controller slave : slaves) {
- slave.stop(executedTests, incompleteTests, tryCancelFutures, stopNow);
- }
- } finally {
- try {
- balancer.releaseAllPermits();
- } finally {
- if (stopNow) {
- strategy.stopNow();
- } else if (tryCancelFutures) {
- strategy.stop();
- } else {
- strategy.disable();
- }
- }
- }
- }
-
- protected boolean shutdownThreadPoolsAwaitingKilled() {
- if (masterController == null) {
- stop(null, null, true, false);
- boolean isNotInterrupted = true;
- if (strategy != null) {
- isNotInterrupted = strategy.destroy();
- }
- for (Controller slave : slaves) {
- isNotInterrupted &= slave.destroy();
- }
- return isNotInterrupted;
- } else {
- throw new UnsupportedOperationException("cannot call this method if this is not a master scheduler");
- }
- }
-
- protected void beforeExecute() {}
-
- protected void afterExecute() {}
-
- @Override
- public void schedule(Runnable childStatement) {
- if (childStatement == null) {
- logQuietly("cannot schedule null");
- } else if (canSchedule() && strategy.canSchedule()) {
- try {
- boolean isNotInterrupted = balancer.acquirePermit();
- if (isNotInterrupted && !shutdown) {
- Runnable task = wrapTask(childStatement);
- strategy.schedule(task);
- started = true;
- }
- } catch (RejectedExecutionException e) {
- stop(null, null, true, false);
- } catch (Throwable t) {
- balancer.releasePermit();
- logQuietly(t);
- }
- }
- }
-
- @Override
- public void finished() {
- try {
- strategy.finished();
- } catch (InterruptedException e) {
- logQuietly(e);
- } finally {
- finished = true;
- }
- }
-
- private Runnable wrapTask(final Runnable task) {
- return new Runnable() {
- @Override
- public void run() {
- try {
- beforeExecute();
- task.run();
- } finally {
- try {
- afterExecute();
- } finally {
- balancer.releasePermit();
- }
- }
- }
- };
- }
-
- protected ShutdownHandler newShutdownHandler() {
- return new ShutdownHandler();
- }
-
- /**
- * If this is a master scheduler, the slaves can stop scheduling by the master through the controller.
- */
- private final class Controller {
- private final Scheduler slave;
-
- private Controller(Scheduler slave) {
- this.slave = slave;
- }
-
- /**
- * @return {@code true} if new children can be scheduled.
- */
- boolean canSchedule() {
- return Scheduler.this.canSchedule();
- }
-
- void stop(
- Collection executedTests,
- Collection incompleteTests,
- boolean tryCancelFutures,
- boolean shutdownNow) {
- slave.stop(executedTests, incompleteTests, tryCancelFutures, shutdownNow);
- }
-
- /**
- * @see org.apache.maven.surefire.junitcore.pc.Destroyable#destroy()
- */
- boolean destroy() {
- return slave.strategy.destroy();
- }
-
- @Override
- public int hashCode() {
- return slave.hashCode();
- }
-
- @Override
- public boolean equals(Object o) {
- return o == this || (o instanceof Controller) && slave.equals(((Controller) o).slave);
- }
- }
-
- /**
- * There is a way to shutdown the hierarchy of schedulers. You can do it in master scheduler via
- * {@link #shutdownThreadPoolsAwaitingKilled()} which kills the current master and children recursively.
- * If alternatively a shared {@link java.util.concurrent.ExecutorService} used by the master and children
- * schedulers is shutdown from outside, then the {@link ShutdownHandler} is a hook calling current
- * {@link #describeStopped(boolean)}. The method {@link #describeStopped(boolean)} is again shutting down children
- * schedulers recursively as well.
- */
- public class ShutdownHandler implements RejectedExecutionHandler {
- private volatile RejectedExecutionHandler poolHandler;
-
- protected ShutdownHandler() {
- poolHandler = null;
- }
-
- public void setRejectedExecutionHandler(RejectedExecutionHandler poolHandler) {
- this.poolHandler = poolHandler;
- }
-
- @Override
- public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
- if (executor.isShutdown()) {
- Scheduler.this.stop(null, null, true, false);
- }
- final RejectedExecutionHandler poolHandler = this.poolHandler;
- if (poolHandler != null) {
- poolHandler.rejectedExecution(r, executor);
- }
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategies.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategies.java
deleted file mode 100644
index f2a4e7d1e6..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategies.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.ThreadFactory;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.surefire.api.util.internal.DaemonThreadFactory;
-
-/**
- * The factory of {@link SchedulingStrategy}.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public class SchedulingStrategies {
- private static final ThreadFactory DAEMON_THREAD_FACTORY = DaemonThreadFactory.newDaemonThreadFactory();
-
- /**
- * @param logger current error logger
- * @return sequentially executing strategy
- */
- public static SchedulingStrategy createInvokerStrategy(ConsoleLogger logger) {
- return new InvokerStrategy(logger);
- }
-
- /**
- * @param logger current error logger
- * @param nThreads fixed pool capacity
- * @return parallel scheduling strategy
- */
- public static SchedulingStrategy createParallelStrategy(ConsoleLogger logger, int nThreads) {
- return new NonSharedThreadPoolStrategy(logger, Executors.newFixedThreadPool(nThreads, DAEMON_THREAD_FACTORY));
- }
-
- /**
- * @param logger current error logger
- * @return parallel scheduling strategy with unbounded capacity
- */
- public static SchedulingStrategy createParallelStrategyUnbounded(ConsoleLogger logger) {
- return new NonSharedThreadPoolStrategy(logger, Executors.newCachedThreadPool(DAEMON_THREAD_FACTORY));
- }
-
- /**
- * The threadPool passed to this strategy can be shared in other strategies.
- *
- * The call {@link SchedulingStrategy#finished()} is waiting until own tasks have finished.
- * New tasks will not be scheduled by this call in this strategy. This strategy is not
- * waiting for other strategies to finish. The {@link org.junit.runners.model.RunnerScheduler#finished()} may
- * freely use {@link SchedulingStrategy#finished()}.
- *
- * @param logger current error logger
- * @param threadPool thread pool possibly shared with other strategies
- * @return parallel strategy with shared thread pool
- * @throws NullPointerException if threadPool is null
- */
- public static SchedulingStrategy createParallelSharedStrategy(ConsoleLogger logger, ExecutorService threadPool) {
- if (threadPool == null) {
- throw new NullPointerException("null threadPool in #createParallelSharedStrategy");
- }
- return new SharedThreadPoolStrategy(logger, threadPool);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategy.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategy.java
deleted file mode 100644
index 7495464e8a..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategy.java
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-
-/**
- * Specifies the strategy of scheduling whether sequential, or parallel.
- * The strategy may use a thread pool shared with other strategies.
- *
- * One instance of strategy can be used just by one {@link Scheduler}.
- *
- * The strategy is scheduling tasks in {@link #schedule(Runnable)} and awaiting them
- * completed in {@link #finished()}. Both methods should be used in one thread.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public abstract class SchedulingStrategy implements Destroyable {
-
- private final AtomicBoolean canSchedule = new AtomicBoolean(true);
-
- private final ConsoleLogger logger;
-
- protected SchedulingStrategy(ConsoleLogger logger) {
- this.logger = logger;
- }
-
- /**
- * Schedules tasks if {@link #canSchedule()}.
- *
- * @param task runnable to schedule in a thread pool or invoke
- * @throws java.util.concurrent.RejectedExecutionException if task
- * cannot be scheduled for execution
- * @throws NullPointerException if task is null
- * @see org.junit.runners.model.RunnerScheduler#schedule(Runnable)
- * @see java.util.concurrent.Executor#execute(Runnable)
- */
- protected abstract void schedule(Runnable task);
-
- /**
- * Waiting for scheduled tasks to finish.
- * New tasks will not be scheduled by calling this method.
- *
- * @return {@code true} if successfully stopped the scheduler, else
- * {@code false} if already stopped (a shared thread
- * pool was shutdown externally).
- * @throws InterruptedException if interrupted while waiting
- * for scheduled tasks to finish
- * @see org.junit.runners.model.RunnerScheduler#finished()
- */
- protected abstract boolean finished() throws InterruptedException;
-
- /**
- * Stops scheduling new tasks (e.g. by {@link java.util.concurrent.ExecutorService#shutdown()}
- * on a private thread pool which cannot be shared with other strategy).
- *
- * @return {@code true} if successfully stopped the scheduler, else
- * {@code false} if already stopped (a shared thread
- * pool was shutdown externally).
- * @see java.util.concurrent.ExecutorService#shutdown()
- */
- protected abstract boolean stop();
-
- /**
- * Stops scheduling new tasks and {@code interrupts} running tasks
- * (e.g. by {@link java.util.concurrent.ExecutorService#shutdownNow()} on a private thread pool
- * which cannot be shared with other strategy).
- *
- * This method calls {@link #stop()} by default.
- *
- * @return {@code true} if successfully stopped the scheduler, else
- * {@code false} if already stopped (a shared thread
- * pool was shutdown externally).
- * @see java.util.concurrent.ExecutorService#shutdownNow()
- */
- protected boolean stopNow() {
- return stop();
- }
-
- /**
- * Persistently disables this strategy. Atomically ignores {@link Balancer} to acquire a new permit.
- * The method {@link #canSchedule()} atomically returns {@code false}.
- * @return {@code true} if {@link #canSchedule()} has return {@code true} on the beginning of this method call.
- */
- protected boolean disable() {
- return canSchedule.getAndSet(false);
- }
-
- protected void setDefaultShutdownHandler(Scheduler.ShutdownHandler handler) {}
-
- /**
- * @return {@code true} if a thread pool associated with this strategy
- * can be shared with other strategies.
- */
- protected abstract boolean hasSharedThreadPool();
-
- /**
- * @return {@code true} unless stopped, finished or disabled.
- */
- protected boolean canSchedule() {
- return canSchedule.get();
- }
-
- protected void logQuietly(Throwable t) {
- logger.error(t);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SharedThreadPoolStrategy.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SharedThreadPoolStrategy.java
deleted file mode 100644
index e24ad1bfa0..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SharedThreadPoolStrategy.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-
-/**
- * Parallel strategy for shared thread pool in private package.
- *
- * @author Tibor Digana (tibor17)
- * @see AbstractThreadPoolStrategy
- * @since 2.16
- */
-final class SharedThreadPoolStrategy extends AbstractThreadPoolStrategy {
- SharedThreadPoolStrategy(ConsoleLogger logger, ExecutorService threadPool) {
- super(logger, threadPool, new ConcurrentLinkedQueue<>());
- }
-
- @Override
- public boolean hasSharedThreadPool() {
- return true;
- }
-
- @Override
- public boolean finished() throws InterruptedException {
- boolean wasRunningAll = disable();
- for (Future> futureResult : getFutureResults()) {
- try {
- futureResult.get();
- } catch (InterruptedException e) {
- // after called external ExecutorService#shutdownNow()
- wasRunningAll = false;
- } catch (ExecutionException e) {
- // JUnit core throws exception.
- if (e.getCause() != null) {
- logQuietly(e.getCause());
- }
- } catch (CancellationException e) {
- /**
- * Cancelled by {@link Future#cancel(boolean)} in {@link stop()} and {@link stopNow()}.
- */
- }
- }
- return wasRunningAll;
- }
-
- @Override
- protected boolean stop() {
- return stop(false);
- }
-
- @Override
- protected boolean stopNow() {
- return stop(true);
- }
-
- private boolean stop(boolean interrupt) {
- final boolean wasRunning = disable();
- for (Future> futureResult : getFutureResults()) {
- futureResult.cancel(interrupt);
- }
- return wasRunning;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownResult.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownResult.java
deleted file mode 100644
index c43914f7d8..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownResult.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Collection;
-import java.util.Collections;
-
-import org.junit.runner.Description;
-
-/**
- * Populates collection {@code triggeredTests} of descriptions started before shutting down.
- * Populates collection {@code incompleteTests} which describes started tests but unfinished due to abrupt shutdown.
- * The collection {@code triggeredTests} contains all elements from {@code incompleteTests}.
- *
- * @author Tibor Digana (tibor17)
- * @see Scheduler
- * @since 2.18
- */
-public final class ShutdownResult {
- private final Collection triggeredTests;
-
- private final Collection incompleteTests;
-
- public ShutdownResult(Collection triggeredTests, Collection incompleteTests) {
- this.triggeredTests = triggeredTests == null ? Collections.emptySet() : triggeredTests;
- this.incompleteTests = incompleteTests == null ? Collections.emptySet() : incompleteTests;
- }
-
- public Collection getTriggeredTests() {
- return triggeredTests;
- }
-
- public Collection getIncompleteTests() {
- return incompleteTests;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownStatus.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownStatus.java
deleted file mode 100644
index cde6fe7361..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ShutdownStatus.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.Future;
-import java.util.concurrent.atomic.AtomicReference;
-
-/**
- * Wrapper of {@link ParallelComputer ParallelComputer status information} and tests been populated before
- * a shutdown hook has been triggered.
- *
- * @author Tibor Digana (tibor17)
- * @see ParallelComputer
- * @since 2.18
- */
-final class ShutdownStatus {
- private final AtomicReference status = new AtomicReference<>(ExecutionStatus.STARTED);
-
- private Future descriptionsBeforeShutdown;
-
- boolean tryFinish() {
- return status.compareAndSet(ExecutionStatus.STARTED, ExecutionStatus.FINISHED);
- }
-
- boolean tryTimeout() {
- return status.compareAndSet(ExecutionStatus.STARTED, ExecutionStatus.TIMEOUT);
- }
-
- boolean isTimeoutElapsed() {
- return status.get() == ExecutionStatus.TIMEOUT;
- }
-
- Future getDescriptionsBeforeShutdown() {
- return descriptionsBeforeShutdown;
- }
-
- void setDescriptionsBeforeShutdown(Future descriptionsBeforeShutdown) {
- this.descriptionsBeforeShutdown = descriptionsBeforeShutdown;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SingleThreadScheduler.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SingleThreadScheduler.java
deleted file mode 100644
index 304fa87dd9..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SingleThreadScheduler.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.Collection;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadFactory;
-import java.util.concurrent.ThreadPoolExecutor;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
-import org.apache.maven.surefire.api.util.internal.DaemonThreadFactory;
-import org.junit.runner.Description;
-import org.junit.runners.model.RunnerScheduler;
-
-/**
- * Used to execute tests annotated with net.jcip.annotations.NotThreadSafe.
- *
- *
- * @author Tibor Digana (tibor17)
- * @see ParallelComputerBuilder
- * @since 2.18
- */
-final class SingleThreadScheduler {
- private final ConsoleLogger logger;
-
- private final ExecutorService pool = newPool();
-
- private final Scheduler master;
-
- private static ExecutorService newPool() {
- ThreadFactory tf = DaemonThreadFactory.newDaemonThreadFactory("maven-surefire-plugin@NotThreadSafe");
- return new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(), tf);
- }
-
- SingleThreadScheduler(ConsoleLogger logger) {
- this.logger = logger;
- SchedulingStrategy strategy = SchedulingStrategies.createParallelSharedStrategy(logger, pool);
- master = new Scheduler(logger, null, strategy);
- }
-
- RunnerScheduler newRunnerScheduler() {
- SchedulingStrategy strategy = SchedulingStrategies.createParallelSharedStrategy(logger, pool);
- return new Scheduler(logger, null, master, strategy);
- }
-
- /**
- * @see Scheduler#describeStopped(boolean)
- */
- ShutdownResult describeStopped(boolean shutdownNow) {
- ShutdownResult shutdownResult = master.describeStopped(shutdownNow);
- return new ShutdownResult(
- copyExisting(shutdownResult.getTriggeredTests()), copyExisting(shutdownResult.getIncompleteTests()));
- }
-
- /**
- * @see Scheduler#shutdownThreadPoolsAwaitingKilled()
- */
- boolean shutdownThreadPoolsAwaitingKilled() {
- return master.shutdownThreadPoolsAwaitingKilled();
- }
-
- private Collection copyExisting(Collection descriptions) {
- Collection activeChildren = new ConcurrentLinkedQueue<>(descriptions);
- ParallelComputerUtil.removeUnusedDescriptions(activeChildren);
- return activeChildren;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ThreadResourcesBalancer.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ThreadResourcesBalancer.java
deleted file mode 100644
index 5bb47dd4a1..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ThreadResourcesBalancer.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import java.util.concurrent.Semaphore;
-
-/**
- * @author Tibor Digana (tibor17)
- * @see Balancer
- * @since 2.16
- */
-final class ThreadResourcesBalancer implements Balancer {
- private final Semaphore balancer;
-
- private final int numPermits;
-
- /**
- * fair set to false.
- *
- * @param numPermits number of permits to acquire when maintaining concurrency on tests.
- * Must be >0 and < {@link Integer#MAX_VALUE}.
- * @see #ThreadResourcesBalancer(int, boolean)
- */
- ThreadResourcesBalancer(int numPermits) {
- this(numPermits, false);
- }
-
- /**
- * @param numPermits number of permits to acquire when maintaining concurrency on tests.
- * Must be >0 and < {@link Integer#MAX_VALUE}.
- * @param fair {@code true} guarantees the waiting schedulers to wake up in order they acquired a permit
- * @throws IllegalArgumentException if numPermits is not positive number
- */
- ThreadResourcesBalancer(int numPermits, boolean fair) {
- if (numPermits <= 0) {
- throw new IllegalArgumentException(String.format("numPermits=%d should be positive number", numPermits));
- }
- balancer = new Semaphore(numPermits, fair);
- this.numPermits = numPermits;
- }
-
- /**
- * Acquires a permit from this balancer, blocking until one is available.
- *
- * @return {@code true} if current thread is NOT interrupted
- * while waiting for a permit.
- */
- @Override
- public boolean acquirePermit() {
- try {
- balancer.acquire();
- return true;
- } catch (InterruptedException e) {
- return false;
- }
- }
-
- /**
- * Releases a permit, returning it to the balancer.
- */
- @Override
- public void releasePermit() {
- balancer.release();
- }
-
- @Override
- public void releaseAllPermits() {
- balancer.release(numPermits);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Type.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Type.java
deleted file mode 100644
index a48397f1ac..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Type.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-/**
- * @author tibor17 (Tibor Digana)
- * @since 2.17
- */
-enum Type {
- SUITES,
- CLASSES,
- METHODS
-}
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/WrappedRunners.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/WrappedRunners.java
deleted file mode 100644
index 5b47a544ad..0000000000
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/WrappedRunners.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore.pc;
-
-import org.junit.runners.ParentRunner;
-
-/**
- * We need to wrap runners in a suite and count children of these runners.
- *
- * Old JUnit versions do not cache children after the first call of
- * {@link org.junit.runners.ParentRunner#getChildren()}.
- * Due to performance reasons, the children have to be observed just once.
- *
- * @author tibor17 (Tibor Digana)
- * @see ParallelComputerBuilder
- * @since 2.17
- */
-final class WrappedRunners {
- final ParentRunner wrappingSuite;
-
- final long embeddedChildrenCount;
-
- WrappedRunners(ParentRunner wrappingSuite, long embeddedChildrenCount) {
- this.wrappingSuite = wrappingSuite;
- this.embeddedChildrenCount = embeddedChildrenCount;
- }
-
- WrappedRunners() {
- this(null, 0);
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/main/resources/META-INF/services/org.apache.maven.surefire.api.provider.SurefireProvider b/surefire-providers/surefire-junit47/src/main/resources/META-INF/services/org.apache.maven.surefire.api.provider.SurefireProvider
deleted file mode 100644
index 584ed7a3e1..0000000000
--- a/surefire-providers/surefire-junit47/src/main/resources/META-INF/services/org.apache.maven.surefire.api.provider.SurefireProvider
+++ /dev/null
@@ -1 +0,0 @@
-org.apache.maven.surefire.junitcore.JUnitCoreProvider
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentRunListenerTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentRunListenerTest.java
deleted file mode 100644
index 00f6104a0d..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConcurrentRunListenerTest.java
+++ /dev/null
@@ -1,329 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import junit.framework.Assert;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
-import org.apache.maven.surefire.api.report.ReporterFactory;
-import org.apache.maven.surefire.api.testset.TestSetFailedException;
-import org.apache.maven.surefire.report.RunStatistics;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.Computer;
-import org.junit.runner.JUnitCore;
-
-/**
- * @author Kristian Rosenvold
- */
-public class ConcurrentRunListenerTest extends TestCase {
- // Tests are in order of increasing complexity
- public void testNoErrorsCounting() throws Exception {
- runClasses(3, 0, 0, DummyAllOk.class);
- }
-
- public void testNoErrorsCounting2() throws Exception {
- runClasses(2, 0, 0, Dummy3.class);
- }
-
- public void testOneIgnoreCounting() throws Exception {
- runClasses(3, 1, 0, DummyWithOneIgnore.class);
- }
-
- public void testOneFailureCounting() throws Exception {
- runClasses(3, 0, 1, DummyWithFailure.class);
- }
-
- public void testWithErrorsCountingDemultiplexed() throws Exception {
- runClasses(6, 1, 1, DummyWithOneIgnore.class, DummyWithFailure.class);
- }
-
- public void testJunitResultCountingDemultiplexed() throws Exception {
- runClasses(8, 1, 1, DummyWithOneIgnore.class, DummyWithFailure.class, Dummy3.class);
- }
-
- public void testJunitResultCountingJUnit3Demultiplexed() throws Exception {
- runClasses(3, 0, 0, Junit3Tc1.class, Junit3Tc2.class);
- }
-
- public void testJunitResultCountingJUnit3OddTest() throws Exception {
- runClasses(2, 0, 0, Junit3OddTest1.class);
- }
-
- public void testJunit3WithNestedSuite() throws TestSetFailedException {
- runClasses(4, 0, 0, Junit3WithNestedSuite.class);
- }
-
- public void testJunit3NestedSuite() throws Exception {
- runClasses(2, 0, 0, Junit3OddTest1.class);
- }
-
- public void testSimpleOutput() throws Exception {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- PrintStream collector = new PrintStream(byteArrayOutputStream);
- PrintStream orgOur = System.out;
- System.setOut(collector);
-
- RunStatistics result = runClasses(Dummy3.class);
- assertReporter(result, 2, 0, 0, "msgs");
-
- String foo = new String(byteArrayOutputStream.toByteArray());
- assertNotNull(foo);
-
- System.setOut(orgOur);
- }
-
- public void testOutputOrdering() throws Exception {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- PrintStream collector = new PrintStream(byteArrayOutputStream);
- PrintStream orgOur = System.out;
- System.setOut(collector);
-
- RunStatistics result = runClasses(DummyWithOneIgnore.class, DummyWithFailure.class, Dummy3.class);
- assertReporter(result, 8, 1, 1, "msgs");
-
- String foo = new String(byteArrayOutputStream.toByteArray());
- assertNotNull(foo);
-
- System.setOut(orgOur);
-
- // final List stringList = result.getEvents();
- // assertEquals( 23, stringList.size() );
- }
-
- private void runClasses(int success, int ignored, int failure, Class>... classes) throws TestSetFailedException {
- DefaultReporterFactory reporterFactory = createReporterFactory();
- HashMap classMethodCounts = new HashMap<>();
- ConcurrentRunListener reporter = new ClassesParallelRunListener(classMethodCounts, reporterFactory);
- JUnitCoreRunListener runListener = new JUnitCoreRunListener(reporter, classMethodCounts);
- RunStatistics result = runClasses(reporterFactory, runListener, classes);
- assertReporter(result, success, ignored, failure, "classes");
- classMethodCounts.clear();
-
- reporterFactory = createReporterFactory();
- reporter = new MethodsParallelRunListener(classMethodCounts, reporterFactory, true);
- runListener = new JUnitCoreRunListener(reporter, classMethodCounts);
- result = runClasses(reporterFactory, runListener, classes);
- assertReporter(result, success, ignored, failure, "methods");
- }
-
- private RunStatistics runClasses(Class>... classes) throws TestSetFailedException {
- HashMap classMethodCounts = new HashMap<>();
- final DefaultReporterFactory reporterManagerFactory = createReporterFactory();
- org.junit.runner.notification.RunListener demultiplexingRunListener =
- createRunListener(reporterManagerFactory, classMethodCounts);
-
- JUnitCore jUnitCore = new JUnitCore();
-
- jUnitCore.addListener(demultiplexingRunListener);
- Computer computer = new Computer();
-
- jUnitCore.run(computer, classes);
- reporterManagerFactory.close();
- return reporterManagerFactory.getGlobalRunStatistics();
- }
-
- private RunStatistics runClasses(
- DefaultReporterFactory reporterManagerFactory,
- org.junit.runner.notification.RunListener demultiplexingRunListener,
- Class>... classes)
- throws TestSetFailedException {
-
- JUnitCore jUnitCore = new JUnitCore();
-
- jUnitCore.addListener(demultiplexingRunListener);
- Computer computer = new Computer();
-
- jUnitCore.run(computer, classes);
- return reporterManagerFactory.getGlobalRunStatistics();
- }
-
- private org.junit.runner.notification.RunListener createRunListener(
- ReporterFactory reporterFactory, Map testSetMap) {
- ConcurrentRunListener handler = new ClassesParallelRunListener(testSetMap, reporterFactory);
- return new JUnitCoreRunListener(handler, testSetMap);
- }
-
- /**
- *
- */
- public static class DummyWithOneIgnore {
- @Test
- public void testNotMuch() {}
-
- @Ignore
- @Test
- public void testStub1() {}
-
- @Test
- public void testStub2() {}
- }
-
- /**
- *
- */
- public static class DummyWithFailure {
- @Test
- public void testBeforeFail() {}
-
- @Test
- public void testWillFail() {
- Assert.fail("We will fail");
- }
-
- @Test
- public void testAfterFail() {}
- }
-
- /**
- *
- */
- public static class DummyAllOk {
-
- @Test
- public void testNotMuchA() {}
-
- @Test
- public void testStub1A() {}
-
- @Test
- public void testStub2A() {}
- }
-
- /**
- *
- */
- public static class Dummy3 {
-
- @Test
- public void testNotMuchA() {
- System.out.println("tNMA1");
- System.err.println("tNMA1err");
- }
-
- @Test
- public void testStub2A() {
- System.out.println("tS2A");
- System.err.println("tS2AErr");
- }
- }
-
- /**
- *
- */
- public static class Junit3Tc1 extends TestCase {
-
- public Junit3Tc1() {
- super("testNotMuchJunit3TC1");
- }
-
- public void testNotMuchJunit3TC1() {
- System.out.println("Junit3TC1");
- }
-
- public static junit.framework.Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new Junit3Tc1());
- return suite;
- }
- }
-
- /**
- *
- */
- public static class Junit3Tc2 extends TestCase {
- public Junit3Tc2(String testMethod) {
- super(testMethod);
- }
-
- public void testNotMuchJunit3TC2() {
- System.out.println("Junit3TC2");
- }
-
- public void testStubJ3TC2A() {
- System.out.println("testStubJ3TC2A");
- }
-
- public static junit.framework.Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTest(new Junit3Tc2("testNotMuchJunit3TC2"));
- suite.addTest(new Junit3Tc2("testStubJ3TC2A"));
- return suite;
- }
- }
-
- /**
- *
- */
- public static class Junit3OddTest1 extends TestCase {
- public static junit.framework.Test suite() {
- TestSuite suite = new TestSuite();
-
- suite.addTest(new Junit3OddTest1("testMe"));
- suite.addTest(new Junit3OddTest1("testMe2"));
-
- return suite;
- }
-
- public Junit3OddTest1(String name) {
- super(name);
- }
-
- public void testMe() {
- assertTrue(true);
- }
- }
-
- /**
- *
- */
- public static class Junit3WithNestedSuite extends TestCase {
- public static junit.framework.Test suite() {
- TestSuite suite = new TestSuite();
-
- suite.addTest(new Junit3WithNestedSuite("testMe"));
- suite.addTest(new Junit3WithNestedSuite("testMe2"));
- suite.addTestSuite(Junit3Tc2.class);
- return suite;
- }
-
- public Junit3WithNestedSuite(String name) {
- super(name);
- }
-
- public void testMe2() {
- assertTrue(true);
- }
- }
-
- private DefaultReporterFactory createReporterFactory() {
- return JUnitCoreTester.defaultNoXml();
- }
-
- private void assertReporter(RunStatistics result, int success, int ignored, int failure, String message) {
- assertEquals(message, success, result.getCompletedCount());
- assertEquals(message, ignored, result.getSkipped());
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
deleted file mode 100644
index 07f83b5c16..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ConfigurableParallelComputerTest.java
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.ExecutionException;
-
-import junit.framework.TestCase;
-import org.junit.Test;
-import org.junit.runner.Computer;
-import org.junit.runner.JUnitCore;
-import org.junit.runner.Result;
-import org.junit.runner.notification.RunListener;
-
-/**
- * Simple test of ConfigurableParallelComputer.
- *
- * @author Kristian Rosenvold
- */
-public class ConfigurableParallelComputerTest extends TestCase {
- private static final int NUMTESTS = 1000;
-
- // I'm sorry about all the sout's in this test; but if you deadlock when building you will appreciate it.
-
- @Test
- public void testAnythingYouWantToPlayWith() throws Exception {
- Result result = new Result();
- Class>[] realClasses = new Class[] {Dummy.class, Dummy2.class};
-
- DiagnosticRunListener diagnosticRunListener = new DiagnosticRunListener(false, result.createListener());
- JUnitCore jUnitCore = getJunitCore(diagnosticRunListener);
- ConfigurableParallelComputer computer = new ConfigurableParallelComputer(true, false);
- jUnitCore.run(computer, realClasses);
- computer.close();
- assertEquals("All tests should succeed, right ?", 5, result.getRunCount());
- }
-
- @Test
- public void testOneMethod() throws ExecutionException {
- JUnitCore jUnitCore = new JUnitCore();
- ConfigurableParallelComputer computer = new ConfigurableParallelComputer(false, true);
- jUnitCore.run(computer, new Class[] {Dummy.class, Dummy.class, Dummy.class});
- computer.close();
- }
-
- @Test
- public void testSerial() throws Exception {
- Result result = new Result();
- Class>[] realClasses = getClassList();
- JUnitCore jUnitCore = getJunitCore(result);
- Computer computer = new Computer();
- timedRun(NUMTESTS, result, realClasses, jUnitCore, computer);
- }
-
- @Test
- public void testFullTestRunPC() throws Exception {
- Result result = new Result();
- Class>[] realClasses = getClassList();
- JUnitCore jUnitCore = getJunitCore(result);
- Computer computer = new ConfigurableParallelComputer(true, true);
- timedRun(NUMTESTS, result, realClasses, jUnitCore, computer);
- }
-
- @Test
- public void testWithFailingAssertionCPC() throws Exception {
- runWithFailingAssertion(new ConfigurableParallelComputer(false, true, 6, true));
- runWithFailingAssertion(new ConfigurableParallelComputer(true, false, 12, false));
- runWithFailingAssertion(new ConfigurableParallelComputer(true, true, 2, false));
- }
-
- @Test
- public void testWithSlowTestJustAfew() throws Exception {
- Result result = new Result();
- final Computer computer = new ConfigurableParallelComputer(false, true, 3, false);
- Class>[] realClasses = getClassList(SlowTest.class, 5); // 300 ms in methods, 600 in classes
-
- JUnitCore jUnitCore = getJunitCore(result);
- runIt(realClasses, jUnitCore, computer);
- }
-
- private void runWithFailingAssertion(Computer computer) throws ExecutionException {
- Result result = new Result();
- Class>[] realClasses = getClassList(FailingAssertions.class);
- JUnitCore jUnitCore = getJunitCore(result);
- runIt(realClasses, jUnitCore, computer);
- assertEquals(
- "No tests should fail, right ?", NUMTESTS, result.getFailures().size());
- assertEquals("All tests should succeed, right ?", 0, result.getIgnoreCount());
- assertEquals("All tests should succeed, right ?", NUMTESTS * 3, result.getRunCount());
- }
-
- @Test
- public void testWithFailure() throws Exception {
- Computer computer = new ConfigurableParallelComputer(false, true, 4, true);
- Result result = new Result();
- Class>[] realClasses = getClassList(Failure.class);
- JUnitCore jUnitCore = getJunitCore(result);
- runIt(realClasses, jUnitCore, computer);
- assertEquals(
- "No tests should fail, right ?", NUMTESTS, result.getFailures().size());
- assertEquals("All tests should succeed, right ?", 0, result.getIgnoreCount());
- assertEquals("All tests should succeed, right ?", NUMTESTS * 3, result.getRunCount());
- }
-
- @Test
- public void testFixedThreadPool() throws Exception {
- Result result = new Result();
- Class>[] realClasses = getClassList();
- JUnitCore jUnitCore = getJunitCore(result);
- ConfigurableParallelComputer computer = new ConfigurableParallelComputer(false, true, 2, false);
- timedRun(NUMTESTS, result, realClasses, jUnitCore, computer);
- }
-
- @Test
- public void testClassesUnlimited() throws Exception {
- Result result = new Result();
- Class>[] realClasses = getClassList();
- JUnitCore jUnitCore = getJunitCore(result);
- ConfigurableParallelComputer computer = new ConfigurableParallelComputer(true, false);
- timedRun(NUMTESTS, result, realClasses, jUnitCore, computer);
- }
-
- @Test
- public void testBothUnlimited() throws Exception {
- Result result = new Result();
- Class>[] realClasses = getClassList();
- DiagnosticRunListener diagnosticRunListener = new DiagnosticRunListener(false, result.createListener());
- JUnitCore jUnitCore = getJunitCore(diagnosticRunListener);
- ConfigurableParallelComputer computer = new ConfigurableParallelComputer(true, true);
- timedRun(NUMTESTS, result, realClasses, jUnitCore, computer);
- }
-
- private JUnitCore getJunitCore(Result result) {
- RunListener listener = result.createListener();
- JUnitCore jUnitCore = new JUnitCore();
- jUnitCore.addListener(listener);
- return jUnitCore;
- }
-
- private JUnitCore getJunitCore(RunListener listener) {
- JUnitCore jUnitCore = new JUnitCore();
- jUnitCore.addListener(listener);
- return jUnitCore;
- }
-
- private long runIt(Class>[] realClasses, JUnitCore jUnitCore, Computer computer) throws ExecutionException {
- long start = System.currentTimeMillis();
- jUnitCore.run(computer, realClasses);
- if (computer instanceof ConfigurableParallelComputer) {
- ((ConfigurableParallelComputer) computer).close();
- }
- return System.currentTimeMillis() - start;
- }
-
- private long timedRun(int numTests, Result result, Class>[] realClasses, JUnitCore jUnitCore, Computer computer)
- throws ExecutionException {
- long time = runIt(realClasses, jUnitCore, computer);
- assertEquals("No tests should fail, right ?", 0, result.getFailures().size());
- assertEquals("All tests should succeed, right ?", 0, result.getIgnoreCount());
- assertEquals("All tests should succeed, right ?", numTests * 3, result.getRunCount());
- return time;
- }
-
- private Class>[] getClassList() {
- return getClassList(Dummy.class, NUMTESTS);
- }
-
- private Class>[] getClassList(Class> testClass) {
- return getClassList(testClass, NUMTESTS);
- }
-
- private Class>[] getClassList(Class> testClass, int numItems) {
- List> realClasses = new ArrayList<>();
- for (int i = 0; i < numItems; i++) {
- realClasses.add(testClass);
- }
- return realClasses.toArray(new Class[realClasses.size()]);
- }
-
- static void sleepReallyEvenOnWindows(long ms) throws InterruptedException {
- long endAt = System.currentTimeMillis() + ms;
- Thread.sleep(ms);
- while (endAt > System.currentTimeMillis()) {
- Thread.sleep(ms / 10);
- Thread.yield();
- }
- }
-
- /**
- *
- */
- public static class Dummy {
- @Test
- public void testNotMuch() {}
-
- @Test
- public void testStub1() {
- // Add your code here
- }
-
- @Test
- public void testStub2() {
- // Add your code here
- }
- }
-
- /**
- *
- */
- public static class Dummy2 {
- @Test
- public void testNotMuch() {}
-
- @Test
- public void testDummy2() {
- // Add your code here
- }
- }
-
- /**
- *
- */
- public static class SlowTest {
- final int scaling = 100;
-
- @Test
- public void testNotMuch() throws InterruptedException {
- sleepReallyEvenOnWindows(scaling);
- }
-
- @Test
- public void testNotMuch2() throws InterruptedException {
- sleepReallyEvenOnWindows(3 * scaling);
- }
-
- @Test
- public void testNotMuch3() throws InterruptedException {
- sleepReallyEvenOnWindows(2 * scaling);
- }
- }
-
- /**
- *
- */
- public static class FailingAssertions {
- @Test
- public void testNotMuch() {}
-
- @Test
- public void testNotMuch2() {}
-
- @Test
- public void testWithFail() {
- fail("We excpect this");
- }
- }
-
- /**
- *
- */
- public static class Failure {
- @Test
- public void testNotMuch() {}
-
- @Test
- public void testNotMuch2() {}
-
- @Test
- public void testWithException() {
- throw new RuntimeException("We expect this");
- }
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
deleted file mode 100644
index 78042fa40a..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/DiagnosticRunListener.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- * Also licensed under CPL http://junit.sourceforge.net/cpl-v10.html
- */
-
-import java.util.concurrent.atomic.AtomicInteger;
-
-import org.junit.runner.Description;
-import org.junit.runner.Result;
-import org.junit.runner.notification.Failure;
-import org.junit.runner.notification.RunListener;
-
-/**
- * @author Kristian Rosenvold, kristianAzeniorD0Tno
- */
-public class DiagnosticRunListener extends RunListener {
- private final AtomicInteger numTestStarted = new AtomicInteger();
-
- private final AtomicInteger numTestFailed = new AtomicInteger();
-
- private final AtomicInteger numTestAssumptionsFailed = new AtomicInteger();
-
- private final AtomicInteger numTestFinished = new AtomicInteger();
-
- private final AtomicInteger numTestIgnored = new AtomicInteger();
-
- private final boolean printToConsole;
-
- private final RunListener target;
-
- private void print(String event, Description description) {
- if (printToConsole) {
- System.out.println(Thread.currentThread().toString() + ", event = " + event + ", " + description);
- }
- }
-
- private void print(String event, Result description) {
- if (printToConsole) {
- System.out.println(Thread.currentThread().toString() + ", event = " + event + ", " + description);
- }
- }
-
- private void print(String event, Failure description) {
- if (printToConsole) {
- System.out.println(Thread.currentThread().toString() + ", event = " + event + ", " + description);
- }
- }
-
- public DiagnosticRunListener(boolean printToConsole, RunListener target) {
- this.printToConsole = printToConsole;
- this.target = target;
- }
-
- @Override
- public void testRunStarted(Description description) throws Exception {
- print("testRunStarted", description);
- if (target != null) {
- target.testRunStarted(description);
- }
- }
-
- @Override
- public void testRunFinished(Result result) throws Exception {
- print("testRunFinished", result);
- if (target != null) {
- target.testRunFinished(result);
- }
- }
-
- @Override
- public void testStarted(Description description) throws Exception {
- numTestStarted.incrementAndGet();
- print("testStarted", description);
- if (target != null) {
- target.testStarted(description);
- }
- }
-
- @Override
- public void testFinished(Description description) throws Exception {
- numTestFinished.incrementAndGet();
- print("testFinished", description);
- if (target != null) {
- target.testFinished(description);
- }
- }
-
- @Override
- public void testFailure(Failure failure) throws Exception {
- numTestFailed.incrementAndGet();
- print("testFailure", failure);
- if (target != null) {
- target.testFailure(failure);
- }
- }
-
- @Override
- public void testAssumptionFailure(Failure failure) {
- numTestAssumptionsFailed.incrementAndGet();
- print("testAssumptionFailure", failure);
- if (target != null) {
- target.testAssumptionFailure(failure);
- }
- }
-
- @Override
- public void testIgnored(Description description) throws Exception {
- numTestIgnored.incrementAndGet();
- print("testIgnored", description);
- if (target != null) {
- target.testIgnored(description);
- }
- }
-
- @Override
- public String toString() {
- return "DiagnosticRunListener{" + "numTestIgnored=" + numTestIgnored + ", numTestStarted=" + numTestStarted
- + ", numTestFailed=" + numTestFailed + ", numTestAssumptionsFailed=" + numTestAssumptionsFailed
- + ", numTestFinished=" + numTestFinished + '}';
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java
deleted file mode 100644
index 5c01d272cc..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit47SuiteTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-import org.apache.maven.surefire.junitcore.pc.OptimizedParallelComputerTest;
-import org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilderTest;
-import org.apache.maven.surefire.junitcore.pc.ParallelComputerUtilTest;
-import org.apache.maven.surefire.junitcore.pc.SchedulingStrategiesTest;
-
-/**
- * Adapt the JUnit47 tests which use only annotations to the JUnit3 test suite.
- *
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-public class JUnit47SuiteTest extends TestCase {
- public static Test suite() {
- TestSuite suite = new TestSuite();
- suite.addTestSuite(ConcurrentRunListenerTest.class);
- suite.addTestSuite(ConfigurableParallelComputerTest.class);
- suite.addTestSuite(JUnitCoreRunListenerTest.class);
- suite.addTestSuite(MavenSurefireJUnit47RunnerTest.class);
- suite.addTestSuite(MavenSurefireJUnit48RunnerTest.class);
- suite.addTestSuite(TestMethodTest.class);
- suite.addTest(new JUnit4TestAdapter(Surefire746Test.class));
- suite.addTest(new JUnit4TestAdapter(Surefire813IncorrectResultTest.class));
- suite.addTest(new JUnit4TestAdapter(ParallelComputerUtilTest.class));
- suite.addTest(new JUnit4TestAdapter(ParallelComputerBuilderTest.class));
- suite.addTest(new JUnit4TestAdapter(SchedulingStrategiesTest.class));
- suite.addTest(new JUnit4TestAdapter(OptimizedParallelComputerTest.class));
- suite.addTest(new JUnit4TestAdapter(JUnit4Reflector481Test.class));
- suite.addTest(new JUnit4TestAdapter(JUnitCoreParametersTest.class));
- return suite;
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java
deleted file mode 100644
index f20d2e36ec..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnit4Reflector481Test.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Method;
-
-import org.apache.maven.surefire.api.util.ReflectionUtils;
-import org.apache.maven.surefire.common.junit4.JUnit4Reflector;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.Description;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-
-/**
- * Reflector Test with junit 4.8.1
- *
- * @author Kristian Rosenvold
- */
-public class JUnit4Reflector481Test {
- private static final Class[] EMPTY_CLASS_ARRAY = new Class[0];
-
- @Test
- public void testGetAnnotatedIgnore() {
- final Method testSomething2 =
- ReflectionUtils.getMethod(IgnoreWithDescription.class, "testSomething2", EMPTY_CLASS_ARRAY);
- final Annotation[] annotations = testSomething2.getAnnotations();
- Description desc =
- Description.createTestDescription(IgnoreWithDescription.class, "testSomething2", annotations);
- Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(desc);
- assertNotNull(annotatedIgnore);
- assertEquals(
- "testSomething2" + "(org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription)",
- desc.getDisplayName());
- assertEquals(
- "testSomething2" + "(org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription)",
- desc.toString());
- assertEquals(
- "org.apache.maven.surefire.junitcore.JUnit4Reflector481Test$IgnoreWithDescription",
- desc.getClassName());
- assertEquals("testSomething2", desc.getMethodName());
- assertEquals(0, desc.getChildren().size());
- assertEquals(2, desc.getAnnotations().size());
- assertSame(annotatedIgnore, desc.getAnnotation(Ignore.class));
- assertEquals(REASON, annotatedIgnore.value());
- }
-
- @Test
- public void testGetAnnotatedIgnoreWithoutClass() {
- final Method testSomething2 =
- ReflectionUtils.getMethod(IgnoreWithDescription.class, "testSomething2", EMPTY_CLASS_ARRAY);
- final Annotation[] annotations = testSomething2.getAnnotations();
- Description desc = Description.createSuiteDescription("testSomething2", annotations);
- Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(desc);
- assertNotNull(annotatedIgnore);
- assertEquals("testSomething2", desc.getDisplayName());
- assertEquals("testSomething2", desc.toString());
- assertEquals("testSomething2", desc.getClassName());
- assertNull(desc.getMethodName());
- assertEquals(0, desc.getChildren().size());
- assertEquals(2, desc.getAnnotations().size());
- assertSame(annotatedIgnore, desc.getAnnotation(Ignore.class));
- assertEquals(REASON, annotatedIgnore.value());
- }
-
- private static final String REASON = "Ignorance is bliss";
-
- /**
- *
- */
- public static class IgnoreWithDescription {
-
- @Test
- @Ignore(REASON)
- public void testSomething2() {}
- }
-
- @Test
- public void testCreatePureDescription() {
- Description description = JUnit4Reflector.createDescription("exception");
- assertEquals("exception", description.getDisplayName());
- assertEquals("exception", description.toString());
- assertEquals(0, description.getChildren().size());
- }
-
- @Test
- public void testCreateDescription() {
- Ignore ignore = JUnit4Reflector.createIgnored("error");
- Description description = JUnit4Reflector.createDescription("exception", ignore);
- assertEquals("exception", description.getDisplayName());
- assertEquals("exception", description.toString());
- assertEquals("exception", description.getClassName());
- assertEquals(0, description.getChildren().size());
- Ignore annotatedIgnore = JUnit4Reflector.getAnnotatedIgnore(description);
- assertNotNull(annotatedIgnore);
- assertEquals("error", annotatedIgnore.value());
- }
-}
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
deleted file mode 100644
index 93e1adf954..0000000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/JUnitCoreParametersTest.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.maven.surefire.junitcore;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.junit.Test;
-
-import static org.hamcrest.core.Is.is;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertThat;
-import static org.junit.Assert.assertTrue;
-
-/**
- * @author Kristian Rosenvold, kristian.rosenvold@gmail com
- */
-@SuppressWarnings("checkstyle:magicnumber")
-public class JUnitCoreParametersTest {
- @Test
- public void defaultParameters() {
- assertFalse(newTestSetDefault().isParallelismSelected());
- assertTrue(newTestSetDefault().isPerCoreThreadCount());
- assertThat(newTestSetDefault().getThreadCount(), is(0));
- assertThat(newTestSetDefault().getThreadCountMethods(), is(0));
- assertThat(newTestSetDefault().getThreadCountClasses(), is(0));
- assertThat(newTestSetDefault().getThreadCountSuites(), is(0));
- assertFalse(newTestSetDefault().isUseUnlimitedThreads());
- assertThat(newTestSetDefault().getParallelTestsTimeoutInSeconds(), is(0d));
- assertThat(newTestSetDefault().getParallelTestsTimeoutForcedInSeconds(), is(0d));
- assertTrue(newTestSetDefault().isParallelOptimization());
- assertTrue(newTestSetDefault().isEnableOutErrElements());
- assertTrue(newTestSetDefault().isEnablePropertiesElement());
- }
-
- @Test
- public void optimizationParameter() {
- assertFalse(newTestSetOptimization(false).isParallelOptimization());
- }
-
- @Test
- public void timeoutParameters() {
- JUnitCoreParameters parameters = newTestSetTimeouts(5.5d, 11.1d);
- assertThat(parameters.getParallelTestsTimeoutInSeconds(), is(5.5d));
- assertThat(parameters.getParallelTestsTimeoutForcedInSeconds(), is(11.1d));
- }
-
- @Test
- public void isParallelMethod() {
- assertFalse(newTestSetClasses().isParallelMethods());
- assertTrue(newTestSetMethods().isParallelMethods());
- assertTrue(newTestSetBoth().isParallelMethods());
- }
-
- @Test
- public void isParallelClasses() {
- assertTrue(newTestSetClasses().isParallelClasses());
- assertFalse(newTestSetMethods().isParallelClasses());
- assertTrue(newTestSetBoth().isParallelClasses());
- }
-
- @Test
- public void isParallelBoth() {
- assertFalse(isParallelMethodsAndClasses(newTestSetClasses()));
- assertFalse(isParallelMethodsAndClasses(newTestSetMethods()));
- assertTrue(isParallelMethodsAndClasses(newTestSetBoth()));
- }
-
- @Test
- public void isPerCoreThreadCount() {
- assertFalse(newTestSetClasses().isPerCoreThreadCount());
- assertFalse(newTestSetMethods().isPerCoreThreadCount());
- assertTrue(newTestSetBoth().isPerCoreThreadCount());
- }
-
- @Test
- public void getThreadCount() {
- assertFalse(newTestSetClasses().isPerCoreThreadCount());
- assertFalse(newTestSetMethods().isPerCoreThreadCount());
- assertTrue(newTestSetBoth().isPerCoreThreadCount());
- }
-
- @Test
- public void isUseUnlimitedThreads() {
- assertFalse(newTestSetClasses().isUseUnlimitedThreads());
- assertTrue(newTestSetMethods().isUseUnlimitedThreads());
- assertFalse(newTestSetBoth().isUseUnlimitedThreads());
- }
-
- @Test
- public void isNoThreading() {
- assertFalse(newTestSetClasses().isNoThreading());
- assertFalse(newTestSetMethods().isNoThreading());
- assertFalse(newTestSetBoth().isNoThreading());
- }
-
- @Test
- public void isAnyParallelismSelected() {
- assertTrue(newTestSetClasses().isParallelismSelected());
- assertTrue(newTestSetMethods().isParallelismSelected());
- assertTrue(newTestSetBoth().isParallelismSelected());
- }
-
- private Map newDefaultProperties() {
- return new HashMap<>();
- }
-
- private Map newPropertiesClasses() {
- Map props = new HashMap<>();
- props.put(JUnitCoreParameters.PARALLEL_KEY, "classes");
- props.put(JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false");
- props.put(JUnitCoreParameters.THREADCOUNT_KEY, "2");
- props.put(JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "false");
- return props;
- }
-
- private Map newPropertiesMethods() {
- Map props = new HashMap<>();
- props.put(JUnitCoreParameters.PARALLEL_KEY, "methods");
- props.put(JUnitCoreParameters.PERCORETHREADCOUNT_KEY, "false");
- props.put(JUnitCoreParameters.THREADCOUNT_KEY, "2");
- props.put(JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY, "true");
- return props;
- }
-
- private Map