You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2013/08/16 10:55:20 UTC
[2/3] reformat code + IT + junit.apt.vm +
fork-options-and-parllel-execution.apt.vm
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ParallelComputerFactory.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ParallelComputerFactory.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ParallelComputerFactory.java
index 3937cd4..d7fe2d1 100644
--- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ParallelComputerFactory.java
+++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ParallelComputerFactory.java
@@ -23,27 +23,24 @@ import org.apache.maven.surefire.junitcore.pc.ParallelComputer;
import org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder;
import org.apache.maven.surefire.testset.TestSetFailedException;
+import java.util.concurrent.TimeUnit;
+
/**
- * An algorithm which configures {@link ParallelComputer} with allocated thread resources by given {@link JUnitCoreParameters}.
+ * An algorithm which configures {@link ParallelComputer} with allocated thread resources by given
+ * {@link JUnitCoreParameters}.
* The <code>AbstractSurefireMojo</code> has to provide correct combinations of thread-counts and <em>parallel</em>.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see org.apache.maven.surefire.junitcore.pc.ParallelComputerBuilder
+ * @since 2.16
*/
final class ParallelComputerFactory
{
private static int availableProcessors = Runtime.getRuntime().availableProcessors();
- static class Concurrency
- {
- int suites, classes, methods, capacity;
- }
-
private ParallelComputerFactory()
{
- throw new IllegalStateException("Suppresses calling constructor, ensuring non-instantiability.");
+ throw new IllegalStateException( "Suppresses calling constructor, ensuring non-instantiability." );
}
/*
@@ -62,7 +59,8 @@ final class ParallelComputerFactory
ParallelComputerFactory.availableProcessors = Runtime.getRuntime().availableProcessors();
}
- static ParallelComputer createParallelComputer( JUnitCoreParameters params ) throws TestSetFailedException
+ static ParallelComputer createParallelComputer( JUnitCoreParameters params )
+ throws TestSetFailedException
{
Concurrency concurrency = resolveConcurrency( params );
ParallelComputerBuilder builder = new ParallelComputerBuilder();
@@ -82,11 +80,14 @@ final class ParallelComputerFactory
resolveMethodsConcurrency( builder, concurrency.methods );
}
+ long timeout = secondsToNanos( params.getParallelTestsTimeoutInSeconds() );
+ long timeoutForced = secondsToNanos( params.getParallelTestsTimeoutForcedInSeconds() );
resolveCapacity( builder, concurrency.capacity );
- return builder.buildComputer();
+ return builder.buildComputer( timeout, timeoutForced, TimeUnit.NANOSECONDS );
}
- static Concurrency resolveConcurrency( JUnitCoreParameters params ) throws TestSetFailedException
+ static Concurrency resolveConcurrency( JUnitCoreParameters params )
+ throws TestSetFailedException
{
if ( !params.isAnyParallelitySelected() )
{
@@ -96,9 +97,11 @@ final class ParallelComputerFactory
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 + ".");
+ "See the parameters " + JUnitCoreParameters.USEUNLIMITEDTHREADS_KEY
+ + ", " + JUnitCoreParameters.THREADCOUNT_KEY + ", "
+ + JUnitCoreParameters.THREADCOUNTSUITES_KEY + ", "
+ + JUnitCoreParameters.THREADCOUNTCLASSES_KEY + ", "
+ + JUnitCoreParameters.THREADCOUNTMETHODS_KEY + "." );
}
if ( params.isUseUnlimitedThreads() )
@@ -111,9 +114,9 @@ final class ParallelComputerFactory
{
if ( hasThreadCounts( params ) )
{
- return isLeafUnspecified( params ) ?
- concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params ) :
- concurrencyFromAllThreadCounts( params );
+ return isLeafUnspecified( params )
+ ? concurrencyFromAllThreadCountsButUnspecifiedLeafCount( params )
+ : concurrencyFromAllThreadCounts( params );
}
else
{
@@ -127,6 +130,12 @@ final class ParallelComputerFactory
}
}
+ private static long secondsToNanos( double seconds )
+ {
+ double nanos = seconds > 0 ? seconds * 1E9 : 0;
+ return Double.isInfinite( nanos ) || nanos >= Long.MAX_VALUE ? 0 : (long) nanos;
+ }
+
private static void resolveSuitesConcurrency( ParallelComputerBuilder builder, int concurrency )
{
if ( concurrency > 0 )
@@ -242,14 +251,14 @@ final class ParallelComputerFactory
concurrency.capacity = params.getThreadCount();
double all = sumThreadCounts( concurrency );
- concurrency.suites = params.isParallelSuites() ?
- multiplyByCoreCount( params, concurrency.capacity * ( concurrency.suites / all ) ) : 0;
+ 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.classes = params.isParallelClasses() ? multiplyByCoreCount( params, concurrency.capacity * (
+ concurrency.classes / all ) ) : 0;
- concurrency.methods = params.isParallelMethod() ?
- multiplyByCoreCount( params, concurrency.capacity * ( concurrency.methods / all ) ) : 0;
+ concurrency.methods = params.isParallelMethod() ? multiplyByCoreCount( params, concurrency.capacity * (
+ concurrency.methods / all ) ) : 0;
concurrency.capacity = multiplyByCoreCount( params, concurrency.capacity );
adjustPrecisionInLeaf( params, concurrency );
@@ -261,7 +270,7 @@ final class ParallelComputerFactory
Concurrency concurrency = new Concurrency();
concurrency.suites = params.isParallelSuites() ? threadCountSuites( params ) : 0;
concurrency.classes = params.isParallelClasses() ? threadCountClasses( params ) : 0;
- concurrency.methods = params.isParallelMethod() ? threadCountMethods( params ) : 0 ;
+ concurrency.methods = params.isParallelMethod() ? threadCountMethods( params ) : 0;
concurrency.capacity = (int) Math.min( sumThreadCounts( concurrency ), Integer.MAX_VALUE );
return concurrency;
}
@@ -269,9 +278,20 @@ final class ParallelComputerFactory
private static int countParallelEntities( JUnitCoreParameters params )
{
int count = 0;
- if ( params.isParallelSuites() ) count++;
- if ( params.isParallelClasses() ) count++;
- if ( params.isParallelMethod() ) count++;
+ if ( params.isParallelSuites() )
+ {
+ count++;
+ }
+
+ if ( params.isParallelClasses() )
+ {
+ count++;
+ }
+
+ if ( params.isParallelMethod() )
+ {
+ count++;
+ }
return count;
}
@@ -301,14 +321,23 @@ final class ParallelComputerFactory
private static void setLeafInfinite( JUnitCoreParameters params, Concurrency concurrency )
{
- if ( params.isParallelMethod() ) concurrency.methods = Integer.MAX_VALUE;
- else if ( params.isParallelClasses() ) concurrency.classes = Integer.MAX_VALUE;
- else if ( params.isParallelSuites() ) concurrency.suites = Integer.MAX_VALUE;
+ if ( params.isParallelMethod() )
+ {
+ 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;
+ int maskOfParallel = params.isParallelSuites() ? 4 : 0;
maskOfParallel |= params.isParallelClasses() ? 2 : 0;
maskOfParallel |= params.isParallelMethod() ? 1 : 0;
@@ -333,11 +362,11 @@ final class ParallelComputerFactory
private static boolean hasThreadCounts( JUnitCoreParameters jUnitCoreParameters )
{
return jUnitCoreParameters.getThreadCountSuites() > 0 ||
- jUnitCoreParameters.getThreadCountClasses() > 0 ||
- jUnitCoreParameters.getThreadCountMethods() > 0;
+ jUnitCoreParameters.getThreadCountClasses() > 0 ||
+ jUnitCoreParameters.getThreadCountMethods() > 0;
}
- private static boolean hasThreadCount ( JUnitCoreParameters jUnitCoreParameters )
+ private static boolean hasThreadCount( JUnitCoreParameters jUnitCoreParameters )
{
return jUnitCoreParameters.getThreadCount() > 0;
}
@@ -360,9 +389,13 @@ final class ParallelComputerFactory
private static int multiplyByCoreCount( JUnitCoreParameters jUnitCoreParameters, double threadsPerCore )
{
double numberOfThreads =
- jUnitCoreParameters.isPerCoreThreadCount() ?
- threadsPerCore * (double) availableProcessors : threadsPerCore;
+ jUnitCoreParameters.isPerCoreThreadCount() ? threadsPerCore * (double) availableProcessors : threadsPerCore;
return numberOfThreads > 0 ? (int) Math.min( numberOfThreads, Integer.MAX_VALUE ) : Integer.MAX_VALUE;
}
+
+ static class Concurrency
+ {
+ int suites, classes, methods, capacity;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/AbstractThreadPoolStrategy.java
----------------------------------------------------------------------
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
index fea0701..56621d5 100644
--- 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
@@ -31,81 +31,103 @@ import java.util.concurrent.atomic.AtomicBoolean;
* depending if the thread pool is shared with other strategies or not.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see SchedulingStrategy
* @see SharedThreadPoolStrategy
* @see NonSharedThreadPoolStrategy
+ * @since 2.16
*/
-abstract class AbstractThreadPoolStrategy extends SchedulingStrategy {
+abstract class AbstractThreadPoolStrategy
+ extends SchedulingStrategy
+{
private final ExecutorService threadPool;
+
private final Collection<Future<?>> futureResults;
- private final AtomicBoolean canSchedule = new AtomicBoolean(true);
- AbstractThreadPoolStrategy(ExecutorService threadPool) {
- this(threadPool, null);
+ private final AtomicBoolean canSchedule = new AtomicBoolean( true );
+
+ AbstractThreadPoolStrategy( ExecutorService threadPool )
+ {
+ this( threadPool, null );
}
- AbstractThreadPoolStrategy(ExecutorService threadPool, Collection<Future<?>> futureResults) {
+ AbstractThreadPoolStrategy( ExecutorService threadPool, Collection<Future<?>> futureResults )
+ {
this.threadPool = threadPool;
this.futureResults = futureResults;
}
- protected final ExecutorService getThreadPool() {
+ protected final ExecutorService getThreadPool()
+ {
return threadPool;
}
- protected final Collection<Future<?>> getFutureResults() {
+ protected final Collection<Future<?>> getFutureResults()
+ {
return futureResults;
}
- protected final void disable() {
- canSchedule.set(false);
+ protected final void disable()
+ {
+ canSchedule.set( false );
}
@Override
- public void schedule(Runnable task) {
- if (canSchedule()) {
- Future<?> futureResult = threadPool.submit(task);
- if (futureResults != null) {
- futureResults.add(futureResult);
+ public void schedule( Runnable task )
+ {
+ if ( canSchedule() )
+ {
+ Future<?> futureResult = threadPool.submit( task );
+ if ( futureResults != null )
+ {
+ futureResults.add( futureResult );
}
}
}
@Override
- protected boolean stop() {
- boolean wasRunning = canSchedule.getAndSet(false);
- if (threadPool.isShutdown()) {
+ protected boolean stop()
+ {
+ boolean wasRunning = canSchedule.getAndSet( false );
+ if ( threadPool.isShutdown() )
+ {
wasRunning = false;
- } else {
+ }
+ else
+ {
threadPool.shutdown();
}
return wasRunning;
}
@Override
- protected boolean stopNow() {
- boolean wasRunning = canSchedule.getAndSet(false);
- if (threadPool.isShutdown()) {
+ protected boolean stopNow()
+ {
+ boolean wasRunning = canSchedule.getAndSet( false );
+ if ( threadPool.isShutdown() )
+ {
wasRunning = false;
- } else {
+ }
+ else
+ {
threadPool.shutdownNow();
}
return wasRunning;
}
@Override
- protected void setDefaultShutdownHandler(Scheduler.ShutdownHandler handler) {
- if (threadPool instanceof ThreadPoolExecutor) {
+ protected void setDefaultShutdownHandler( Scheduler.ShutdownHandler handler )
+ {
+ if ( threadPool instanceof ThreadPoolExecutor )
+ {
ThreadPoolExecutor pool = (ThreadPoolExecutor) threadPool;
- handler.setRejectedExecutionHandler(pool.getRejectedExecutionHandler());
- pool.setRejectedExecutionHandler(handler);
+ handler.setRejectedExecutionHandler( pool.getRejectedExecutionHandler() );
+ pool.setRejectedExecutionHandler( handler );
}
}
@Override
- public final boolean canSchedule() {
+ public final boolean canSchedule()
+ {
return canSchedule.get();
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Balancer.java
----------------------------------------------------------------------
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
index 1b28309..2277bd4 100644
--- 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
@@ -22,7 +22,7 @@ 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.
- * <p>
+ * <p/>
* 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.
@@ -30,7 +30,8 @@ package org.apache.maven.surefire.junitcore.pc;
* @author Tibor Digana (tibor17)
* @since 2.16
*/
-public interface Balancer {
+public interface Balancer
+{
/**
* Acquires a permit from this balancer, blocking until one is available.
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/BalancerFactory.java
----------------------------------------------------------------------
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
index e7db197..e4c36e3 100644
--- 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
@@ -21,11 +21,11 @@ package org.apache.maven.surefire.junitcore.pc;
/**
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see Balancer
+ * @since 2.16
*/
-public class BalancerFactory {
+public class BalancerFactory
+{
private BalancerFactory()
{
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/InvokerStrategy.java
----------------------------------------------------------------------
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
index dc1e5b3..29a6624 100644
--- 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
@@ -25,37 +25,45 @@ import java.util.concurrent.atomic.AtomicBoolean;
* The sequentially executing strategy in private package.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see SchedulingStrategy
+ * @since 2.16
*/
-final class InvokerStrategy extends SchedulingStrategy {
- private final AtomicBoolean canSchedule = new AtomicBoolean(true);
+final class InvokerStrategy
+ extends SchedulingStrategy
+{
+ private final AtomicBoolean canSchedule = new AtomicBoolean( true );
@Override
- public void schedule(Runnable task) {
- if (canSchedule()) {
+ public void schedule( Runnable task )
+ {
+ if ( canSchedule() )
+ {
task.run();
}
}
@Override
- protected boolean stop() {
- return canSchedule.getAndSet(false);
+ protected boolean stop()
+ {
+ return canSchedule.getAndSet( false );
}
@Override
- public boolean hasSharedThreadPool() {
+ public boolean hasSharedThreadPool()
+ {
return false;
}
@Override
- public boolean canSchedule() {
+ public boolean canSchedule()
+ {
return canSchedule.get();
}
@Override
- public boolean finished() throws InterruptedException {
+ public boolean finished()
+ throws InterruptedException
+ {
return stop();
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NonSharedThreadPoolStrategy.java
----------------------------------------------------------------------
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
index b463605..df80ad9 100644
--- 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
@@ -26,28 +26,36 @@ import java.util.concurrent.TimeUnit;
* Parallel strategy for non-shared thread pool in private package.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see AbstractThreadPoolStrategy
+ * @since 2.16
*/
-final class NonSharedThreadPoolStrategy extends AbstractThreadPoolStrategy {
- NonSharedThreadPoolStrategy(ExecutorService threadPool) {
- super(threadPool);
+final class NonSharedThreadPoolStrategy
+ extends AbstractThreadPoolStrategy
+{
+ NonSharedThreadPoolStrategy( ExecutorService threadPool )
+ {
+ super( threadPool );
}
@Override
- public boolean hasSharedThreadPool() {
+ public boolean hasSharedThreadPool()
+ {
return false;
}
@Override
- public boolean finished() throws InterruptedException {
+ public boolean finished()
+ throws InterruptedException
+ {
boolean wasRunning = canSchedule();
getThreadPool().shutdown();
- try {
- getThreadPool().awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
+ try
+ {
+ getThreadPool().awaitTermination( Long.MAX_VALUE, TimeUnit.NANOSECONDS );
return wasRunning;
- } finally {
+ }
+ finally
+ {
disable();
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/NullBalancer.java
----------------------------------------------------------------------
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
index eec3759..56b9522 100644
--- 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
@@ -23,11 +23,11 @@ package org.apache.maven.surefire.junitcore.pc;
* This balancer implements {@link Balancer} and does not do anything -no blocking operation.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see Balancer
+ * @since 2.16
*/
-final class NullBalancer implements Balancer
+final class NullBalancer
+ implements Balancer
{
public boolean acquirePermit()
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputer.java
----------------------------------------------------------------------
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
index ef4fc94..242df2e 100644
--- 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
@@ -19,10 +19,13 @@ package org.apache.maven.surefire.junitcore.pc;
* under the License.
*/
+import org.apache.maven.surefire.testset.TestSetFailedException;
import org.junit.runner.Computer;
import org.junit.runner.Description;
import java.util.Collection;
+import java.util.Collections;
+import java.util.TreeSet;
import java.util.concurrent.Callable;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -33,16 +36,77 @@ import java.util.concurrent.TimeUnit;
* ParallelComputer extends JUnit {@link Computer} and has a shutdown functionality.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see ParallelComputerBuilder
+ * @since 2.16
*/
-public abstract class ParallelComputer extends Computer
+public abstract class ParallelComputer
+ extends Computer
{
+ private final long timeoutNanos;
+
+ private final long timeoutForcedNanos;
+
private ScheduledExecutorService shutdownScheduler;
+ private Future<Collection<Description>> testsBeforeShutdown;
+
+ private Future<Collection<Description>> testsBeforeForcedShutdown;
+
+ public ParallelComputer( long timeout, long timeoutForced, TimeUnit timeoutUnit )
+ {
+ this.timeoutNanos = timeoutUnit.toNanos( timeout );
+ this.timeoutForcedNanos = timeoutUnit.toNanos( timeoutForced );
+ }
+
+ 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 Collection<String> printShutdownHook( Future<Collection<Description>> future )
+ throws TestSetFailedException
+ {
+ if ( !future.isCancelled() && future.isDone() )
+ {
+ try
+ {
+ TreeSet<String> executedTests = new TreeSet<String>();
+ for ( Description executedTest : future.get() )
+ {
+ if ( executedTest != null && executedTest.getDisplayName() != null )
+ {
+ executedTests.add( executedTest.getDisplayName() );
+ }
+ }
+ return executedTests;
+ }
+ catch ( Exception e )
+ {
+ throw new TestSetFailedException( e );
+ }
+ }
+ return Collections.emptySet();
+ }
+
public abstract Collection<Description> shutdown( boolean shutdownNow );
+ protected final void beforeRunQuietly()
+ {
+ testsBeforeShutdown = timeoutNanos > 0 ? scheduleShutdown() : null;
+ testsBeforeForcedShutdown = timeoutForcedNanos > 0 ? scheduleForcedShutdown() : null;
+ }
+
protected final void afterRunQuietly()
{
if ( shutdownScheduler != null )
@@ -51,14 +115,43 @@ public abstract class ParallelComputer extends Computer
}
}
- public Future<Collection<Description>> scheduleShutdown( int timeout, TimeUnit unit )
+ public String describeElapsedTimeout()
+ throws TestSetFailedException
{
- return getShutdownScheduler().schedule( createShutdownTask( false ), timeout, unit );
+ TreeSet<String> executedTests = new TreeSet<String>();
+ if ( testsBeforeShutdown != null )
+ {
+ executedTests.addAll( printShutdownHook( testsBeforeShutdown ) );
+ }
+
+ if ( testsBeforeForcedShutdown != null )
+ {
+ executedTests.addAll( printShutdownHook( testsBeforeForcedShutdown ) );
+ }
+
+ StringBuilder msg = new StringBuilder();
+ if ( !executedTests.isEmpty() )
+ {
+ msg.append( "The test run has finished abruptly after timeout of " );
+ msg.append( nanosToSeconds( minTimeout( timeoutNanos, timeoutForcedNanos ) ) );
+ msg.append( " seconds.\n" );
+ msg.append( "These tests were executed in prior of the shutdown operation:\n" );
+ for ( String executedTest : executedTests )
+ {
+ msg.append( executedTest ).append( '\n' );
+ }
+ }
+ return msg.toString();
}
- public Future<Collection<Description>> scheduleForcedShutdown( int timeout, TimeUnit unit )
+ private Future<Collection<Description>> scheduleShutdown()
{
- return getShutdownScheduler().schedule( createShutdownTask( true ), timeout, unit );
+ return getShutdownScheduler().schedule( createShutdownTask( false ), timeoutNanos, TimeUnit.NANOSECONDS );
+ }
+
+ private Future<Collection<Description>> scheduleForcedShutdown()
+ {
+ return getShutdownScheduler().schedule( createShutdownTask( true ), timeoutForcedNanos, TimeUnit.NANOSECONDS );
}
private ScheduledExecutorService getShutdownScheduler()
@@ -74,10 +167,16 @@ public abstract class ParallelComputer extends Computer
{
return new Callable<Collection<Description>>()
{
- public Collection<Description> call() throws Exception
+ public Collection<Description> call()
+ throws Exception
{
- return shutdown( isForced );
+ return ParallelComputer.this.shutdown( isForced );
}
};
}
+
+ private double nanosToSeconds( long nanos )
+ {
+ return (double) nanos / 1E9;
+ }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilder.java
----------------------------------------------------------------------
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
index ef2c05e..8e7f5b0 100644
--- 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
@@ -39,6 +39,7 @@ import java.util.LinkedHashSet;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
/**
* Executing suites, classes and methods with defined concurrency. In this example the threads which completed
@@ -51,9 +52,11 @@ import java.util.concurrent.Executors;
* new JUnitCore().run(computer, tests);
* </pre>
* 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.
- * <p>
- * The Computer can be shutdown in a separate thread. Pending tests will be interrupted if the argument is <tt>true</tt>.
+ * {@link ParallelComputerBuilder#useOnePool(int)} must be greater than the number of concurrent suites and classes
+ * altogether.
+ * <p/>
+ * The Computer can be shutdown in a separate thread. Pending tests will be interrupted if the argument is
+ * <tt>true</tt>.
* <pre>
* computer.shutdown(true);
* </pre>
@@ -61,33 +64,36 @@ import java.util.concurrent.Executors;
* @author Tibor Digana (tibor17)
* @since 2.16
*/
-public class ParallelComputerBuilder {
- private static enum Type {
- SUITES, CLASSES, METHODS
- }
-
+public class ParallelComputerBuilder
+{
static final int TOTAL_POOL_SIZE_UNDEFINED = 0;
- private final Map<Type, Integer> parallelGroups = new HashMap<Type, Integer>(3);
+
+ private final Map<Type, Integer> parallelGroups = new HashMap<Type, Integer>( 3 );
+
private boolean useSeparatePools;
+
private int totalPoolSize;
/**
* Calling {@link #useSeparatePools()}.
*/
- public ParallelComputerBuilder() {
+ public ParallelComputerBuilder()
+ {
useSeparatePools();
- parallelGroups.put(Type.SUITES, 0);
- parallelGroups.put(Type.CLASSES, 0);
- parallelGroups.put(Type.METHODS, 0);
+ parallelGroups.put( Type.SUITES, 0 );
+ parallelGroups.put( Type.CLASSES, 0 );
+ parallelGroups.put( Type.METHODS, 0 );
}
- public ParallelComputerBuilder useSeparatePools() {
+ public ParallelComputerBuilder useSeparatePools()
+ {
totalPoolSize = TOTAL_POOL_SIZE_UNDEFINED;
useSeparatePools = true;
return this;
}
- public ParallelComputerBuilder useOnePool() {
+ public ParallelComputerBuilder useOnePool()
+ {
totalPoolSize = TOTAL_POOL_SIZE_UNDEFINED;
useSeparatePools = false;
return this;
@@ -95,99 +101,140 @@ public class ParallelComputerBuilder {
/**
* @param totalPoolSize Pool size where suites, classes and methods are executed in parallel.
- * If the <tt>totalPoolSize</tt> is {@link Integer#MAX_VALUE}, the pool capacity is not limited.
+ * If the <tt>totalPoolSize</tt> is {@link Integer#MAX_VALUE}, the pool capacity is not
+ * limited.
* @throws IllegalArgumentException If <tt>totalPoolSize</tt> is < 1.
*/
- public ParallelComputerBuilder useOnePool(int totalPoolSize) {
- if (totalPoolSize < 1) {
- throw new IllegalArgumentException("Size of common pool is less than 1.");
+ public 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;
}
- public ParallelComputerBuilder parallelSuites() {
- return parallel(Type.SUITES);
+ public ParallelComputerBuilder parallelSuites()
+ {
+ return parallel( Type.SUITES );
}
- public ParallelComputerBuilder parallelSuites(int nThreads) {
- return parallel(nThreads, Type.SUITES);
+ public ParallelComputerBuilder parallelSuites( int nThreads )
+ {
+ return parallel( nThreads, Type.SUITES );
}
- public ParallelComputerBuilder parallelClasses() {
- return parallel(Type.CLASSES);
+ public ParallelComputerBuilder parallelClasses()
+ {
+ return parallel( Type.CLASSES );
}
- public ParallelComputerBuilder parallelClasses(int nThreads) {
- return parallel(nThreads, Type.CLASSES);
+ public ParallelComputerBuilder parallelClasses( int nThreads )
+ {
+ return parallel( nThreads, Type.CLASSES );
}
- public ParallelComputerBuilder parallelMethods() {
- return parallel(Type.METHODS);
+ public ParallelComputerBuilder parallelMethods()
+ {
+ return parallel( Type.METHODS );
}
- public ParallelComputerBuilder parallelMethods(int nThreads) {
- return parallel(nThreads, Type.METHODS);
+ public ParallelComputerBuilder parallelMethods( int nThreads )
+ {
+ return parallel( nThreads, Type.METHODS );
}
- private ParallelComputerBuilder parallel(int nThreads, Type parallelType) {
- if (nThreads < 0) {
- throw new IllegalArgumentException("negative nThreads " + nThreads);
+ private ParallelComputerBuilder parallel( int nThreads, Type parallelType )
+ {
+ if ( nThreads < 0 )
+ {
+ throw new IllegalArgumentException( "negative nThreads " + nThreads );
}
- if (parallelType == null) {
- throw new NullPointerException("null parallelType");
+ if ( parallelType == null )
+ {
+ throw new NullPointerException( "null parallelType" );
}
- parallelGroups.put(parallelType, nThreads);
+ parallelGroups.put( parallelType, nThreads );
return this;
}
- private ParallelComputerBuilder parallel(Type parallelType) {
- return parallel(Integer.MAX_VALUE, parallelType);
+ private ParallelComputerBuilder parallel( Type parallelType )
+ {
+ return parallel( Integer.MAX_VALUE, parallelType );
+ }
+
+ public ParallelComputer buildComputer()
+ {
+ return buildComputer( 0, 0, TimeUnit.NANOSECONDS );
}
- public ParallelComputer buildComputer() {
- return new PC();
+ public ParallelComputer buildComputer( long timeout, long timeoutForced, TimeUnit timeUnit )
+ {
+ return new PC( timeout, timeoutForced, timeUnit );
}
- final class PC extends ParallelComputer
+ private static enum Type
+ {
+ SUITES,
+ CLASSES,
+ METHODS
+ }
+
+ final class PC
+ extends ParallelComputer
{
final Collection<ParentRunner> suites = new LinkedHashSet<ParentRunner>();
+
final Collection<ParentRunner> nestedSuites = new LinkedHashSet<ParentRunner>();
+
final Collection<ParentRunner> classes = new LinkedHashSet<ParentRunner>();
+
final Collection<ParentRunner> nestedClasses = new LinkedHashSet<ParentRunner>();
+
final Collection<Runner> unscheduledRunners = new LinkedHashSet<Runner>();
+
final int poolCapacity;
+
final boolean splitPool;
+
private final Map<Type, Integer> allGroups;
+
private volatile Scheduler master;
- private PC() {
- allGroups = new HashMap<Type, Integer>(ParallelComputerBuilder.this.parallelGroups);
+ private PC( long timeout, long timeoutForced, TimeUnit timeoutUnit )
+ {
+ super( timeout, timeoutForced, timeoutUnit );
+ allGroups = new HashMap<Type, Integer>( ParallelComputerBuilder.this.parallelGroups );
poolCapacity = ParallelComputerBuilder.this.totalPoolSize;
splitPool = ParallelComputerBuilder.this.useSeparatePools;
}
@Override
- public Collection<Description> shutdown(boolean shutdownNow) {
+ public Collection<Description> shutdown( boolean shutdownNow )
+ {
final Scheduler master = this.master;
- return master == null ? Collections.<Description>emptyList() : master.shutdown(shutdownNow);
+ return master == null ? Collections.<Description>emptyList() : master.shutdown( shutdownNow );
}
@Override
- public Runner getSuite(RunnerBuilder builder, Class<?>[] cls) throws InitializationError {
- super.getSuite(builder, cls);
+ public Runner getSuite( RunnerBuilder builder, Class<?>[] cls )
+ throws InitializationError
+ {
+ super.getSuite( builder, cls );
populateChildrenFromSuites();
return setSchedulers();
}
@Override
- protected Runner getRunner( RunnerBuilder builder, Class<?> testClass ) throws Throwable
+ protected Runner getRunner( RunnerBuilder builder, Class<?> testClass )
+ throws Throwable
{
Runner runner = super.getRunner( builder, testClass );
- if ( canSchedule(runner) )
+ if ( canSchedule( runner ) )
{
if ( runner instanceof Suite )
{
@@ -205,29 +252,9 @@ public class ParallelComputerBuilder {
return runner;
}
- private class SuiteFilter extends Filter {
- @Override
- public boolean shouldRun(Description description) {
- return true;
- }
-
- @Override
- public void apply(Object child) throws NoTestsRemainException {
- super.apply(child);
- if (child instanceof Suite) {
- nestedSuites.add((Suite) child);
- } else if (child instanceof ParentRunner) {
- nestedClasses.add((ParentRunner) child);
- }
- }
-
- @Override
- public String describe() {
- return "";
- }
- }
-
- private <T extends Runner> ParentRunner wrapRunners( Collection<T> runners ) throws InitializationError {
+ private <T extends Runner> ParentRunner wrapRunners( Collection<T> runners )
+ throws InitializationError
+ {
ArrayList<Runner> runs = new ArrayList<Runner>();
for ( T runner : runners )
{
@@ -237,7 +264,9 @@ public class ParallelComputerBuilder {
}
}
- return runs.isEmpty() ? null : new Suite( null, runs ) {};
+ return runs.isEmpty() ? null : new Suite( null, runs )
+ {
+ };
}
private boolean hasChildren( Runner runner )
@@ -247,59 +276,83 @@ public class ParallelComputerBuilder {
return children != null && !children.isEmpty();
}
- private ExecutorService createPool(int poolSize) {
- return poolSize < Integer.MAX_VALUE ? Executors.newFixedThreadPool(poolSize) : Executors.newCachedThreadPool();
+ private ExecutorService createPool( int poolSize )
+ {
+ return poolSize < Integer.MAX_VALUE
+ ? Executors.newFixedThreadPool( poolSize )
+ : Executors.newCachedThreadPool();
}
- private Scheduler createMaster(ExecutorService pool, int poolSize) {
- if (!areSuitesAndClassesParallel() || poolSize <= 1) {
- return new Scheduler(null, new InvokerStrategy());
- } else if (pool != null && poolSize == Integer.MAX_VALUE) {
- return new Scheduler(null, new SharedThreadPoolStrategy(pool));
- } else {
- return new Scheduler(null, SchedulingStrategies.createParallelStrategy(2));
+ private Scheduler createMaster( ExecutorService pool, int poolSize )
+ {
+ if ( !areSuitesAndClassesParallel() || poolSize <= 1 )
+ {
+ return new Scheduler( null, new InvokerStrategy() );
+ }
+ else if ( pool != null && poolSize == Integer.MAX_VALUE )
+ {
+ return new Scheduler( null, new SharedThreadPoolStrategy( pool ) );
+ }
+ else
+ {
+ return new Scheduler( null, SchedulingStrategies.createParallelStrategy( 2 ) );
}
}
- private boolean areSuitesAndClassesParallel() {
- return !suites.isEmpty() && allGroups.get(Type.SUITES) > 0 && !classes.isEmpty() && allGroups.get(Type.CLASSES) > 0;
+ private boolean areSuitesAndClassesParallel()
+ {
+ return !suites.isEmpty() && allGroups.get( Type.SUITES ) > 0 && !classes.isEmpty()
+ && allGroups.get( Type.CLASSES ) > 0;
}
- private void populateChildrenFromSuites() {
+ private void populateChildrenFromSuites()
+ {
Filter filter = new SuiteFilter();
- for (Iterator<ParentRunner> it = suites.iterator(); it.hasNext();) {
+ for ( Iterator<ParentRunner> it = suites.iterator(); it.hasNext(); )
+ {
ParentRunner suite = it.next();
- try {
- suite.filter(filter);
- } catch (NoTestsRemainException e) {
+ try
+ {
+ suite.filter( filter );
+ }
+ catch ( NoTestsRemainException e )
+ {
it.remove();
}
}
}
- private int totalPoolSize() {
- if (poolCapacity == TOTAL_POOL_SIZE_UNDEFINED) {
+ private int totalPoolSize()
+ {
+ if ( poolCapacity == TOTAL_POOL_SIZE_UNDEFINED )
+ {
int total = 0;
- for (int nThreads : allGroups.values()) {
+ for ( int nThreads : allGroups.values() )
+ {
total += nThreads;
- if (total < 0) {
+ if ( total < 0 )
+ {
total = Integer.MAX_VALUE;
break;
}
}
return total;
- } else {
+ }
+ else
+ {
return poolCapacity;
}
}
- private Runner setSchedulers() throws InitializationError {
- int parallelSuites = allGroups.get(Type.SUITES);
- int parallelClasses = allGroups.get(Type.CLASSES);
- int parallelMethods = allGroups.get(Type.METHODS);
+ private Runner setSchedulers()
+ throws InitializationError
+ {
+ int parallelSuites = allGroups.get( Type.SUITES );
+ int parallelClasses = allGroups.get( Type.CLASSES );
+ int parallelMethods = allGroups.get( Type.METHODS );
int poolSize = totalPoolSize();
- ExecutorService commonPool = splitPool || poolSize == 0 ? null : createPool(poolSize);
- master = createMaster(commonPool, poolSize);
+ ExecutorService commonPool = splitPool || poolSize == 0 ? null : createPool( poolSize );
+ master = createMaster( commonPool, poolSize );
ParentRunner suiteSuites = wrapRunners( suites );
if ( suiteSuites != null )
@@ -343,7 +396,8 @@ public class ParallelComputerBuilder {
return all;
}
- private ParentRunner createFinalRunner( Runner... runners ) throws InitializationError
+ private ParentRunner createFinalRunner( Runner... runners )
+ throws InitializationError
{
ArrayList<Runner> all = new ArrayList<Runner>( unscheduledRunners );
for ( Runner runner : runners )
@@ -361,6 +415,7 @@ public class ParallelComputerBuilder {
{
try
{
+ beforeRunQuietly();
super.run( notifier );
}
finally
@@ -371,46 +426,96 @@ public class ParallelComputerBuilder {
};
}
- private void setSchedulers(Iterable<? extends ParentRunner> runners, int poolSize, ExecutorService commonPool) {
- if (commonPool != null) {
- Balancer concurrencyLimit = BalancerFactory.createBalancerWithFairness(poolSize);
+ 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));
+ for ( ParentRunner runner : runners )
+ {
+ runner.setScheduler(
+ createScheduler( runner.getDescription(), commonPool, doParallel, concurrencyLimit ) );
}
- } else {
+ }
+ else
+ {
ExecutorService pool = null;
- if (poolSize == Integer.MAX_VALUE) {
+ if ( poolSize == Integer.MAX_VALUE )
+ {
pool = Executors.newCachedThreadPool();
- } else if (poolSize > 0) {
- pool = Executors.newFixedThreadPool(poolSize);
+ }
+ else if ( poolSize > 0 )
+ {
+ pool = Executors.newFixedThreadPool( poolSize );
}
boolean doParallel = pool != null;
- for (ParentRunner runner : runners) {
- runner.setScheduler(createScheduler(runner.getDescription(), pool, doParallel,
- BalancerFactory.createInfinitePermitsBalancer()));
+ for ( ParentRunner runner : runners )
+ {
+ runner.setScheduler( createScheduler( runner.getDescription(), pool, doParallel,
+ BalancerFactory.createInfinitePermitsBalancer() ) );
}
}
}
- private Scheduler createScheduler(Description desc, ExecutorService pool, boolean doParallel, Balancer concurrency) {
+ private Scheduler createScheduler( Description desc, ExecutorService pool, boolean doParallel,
+ Balancer concurrency )
+ {
doParallel &= pool != null;
- SchedulingStrategy strategy = doParallel ? new SharedThreadPoolStrategy(pool) : new InvokerStrategy();
- return new Scheduler(desc, master, strategy, concurrency);
+ SchedulingStrategy strategy = doParallel ? new SharedThreadPoolStrategy( pool ) : new InvokerStrategy();
+ return new Scheduler( desc, master, strategy, concurrency );
}
- private Scheduler createScheduler(int poolSize) {
- if (poolSize == Integer.MAX_VALUE) {
- return new Scheduler(null, master, SchedulingStrategies.createParallelStrategyUnbounded());
- } else if (poolSize == 0) {
- return new Scheduler(null, master, new InvokerStrategy());
- } else {
- return new Scheduler(null, master, SchedulingStrategies.createParallelStrategy(poolSize));
+ private Scheduler createScheduler( int poolSize )
+ {
+ if ( poolSize == Integer.MAX_VALUE )
+ {
+ return new Scheduler( null, master, SchedulingStrategies.createParallelStrategyUnbounded() );
+ }
+ else if ( poolSize == 0 )
+ {
+ return new Scheduler( null, master, new InvokerStrategy() );
+ }
+ else
+ {
+ return new Scheduler( null, master, SchedulingStrategies.createParallelStrategy( poolSize ) );
}
}
- private boolean canSchedule(Runner runner) {
- return !(runner instanceof ErrorReportingRunner) && runner instanceof ParentRunner;
+ private boolean canSchedule( Runner runner )
+ {
+ return !( runner instanceof ErrorReportingRunner ) && runner instanceof ParentRunner;
+ }
+
+ private class SuiteFilter
+ extends Filter
+ {
+ @Override
+ public boolean shouldRun( Description description )
+ {
+ return true;
+ }
+
+ @Override
+ public void apply( Object child )
+ throws NoTestsRemainException
+ {
+ super.apply( child );
+ if ( child instanceof Suite )
+ {
+ nestedSuites.add( (Suite) child );
+ }
+ else if ( child instanceof ParentRunner )
+ {
+ nestedClasses.add( (ParentRunner) child );
+ }
+ }
+
+ @Override
+ public String describe()
+ {
+ return "";
+ }
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/Scheduler.java
----------------------------------------------------------------------
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
index 7b287e5..d3c4133 100644
--- 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
@@ -31,87 +31,100 @@ import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;
/**
- *
* Schedules tests, controls thread resources, awaiting tests and other schedulers finished, and
* a master scheduler can shutdown slaves.
- * <p>
+ * <p/>
* The scheduler objects should be first created (and wired) and set in runners
* {@link org.junit.runners.ParentRunner#setScheduler(org.junit.runners.model.RunnerScheduler)}.
- * <p>
+ * <p/>
* 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 {
+public class Scheduler
+ implements RunnerScheduler
+{
private final Balancer balancer;
+
private final SchedulingStrategy strategy;
+
private final Set<Controller> slaves = new CopyOnWriteArraySet<Controller>();
+
private final Description description;
+
private volatile boolean shutdown = false;
+
private volatile boolean started = false;
+
private volatile Controller masterController;
/**
* Use e.g. parallel classes have own non-shared thread pool, and methods another pool.
- * <p>
+ * <p/>
* You can use it with one infinite thread pool shared in strategies across all
* suites, class runners, etc.
*/
- public Scheduler(Description description, SchedulingStrategy strategy) {
- this(description, strategy, -1);
+ public Scheduler( Description description, SchedulingStrategy strategy )
+ {
+ this( description, strategy, -1 );
}
/**
* Should be used if schedulers in parallel children and parent use one instance of bounded thread pool.
- * <p>
+ * <p/>
* Set this scheduler in a e.g. one suite of classes, then every individual class runner should reference
* {@link #Scheduler(org.junit.runner.Description, Scheduler, SchedulingStrategy)}
* or {@link #Scheduler(org.junit.runner.Description, Scheduler, SchedulingStrategy, int)}.
*
* @param description description of current runner
- * @param strategy scheduling strategy with a shared thread pool
+ * @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 <tt>strategy</tt>
*/
- public Scheduler(Description description, SchedulingStrategy strategy, int concurrency) {
- this(description, strategy, BalancerFactory.createBalancer(concurrency));
+ public Scheduler( Description description, SchedulingStrategy strategy, int concurrency )
+ {
+ this( description, strategy, BalancerFactory.createBalancer( concurrency ) );
}
/**
* New instances should be used by schedulers with limited concurrency by <tt>balancer</tt>
* against other groups of schedulers. The schedulers share one pool.
- * <p>
+ * <p/>
* Unlike in {@link #Scheduler(org.junit.runner.Description, SchedulingStrategy, int)} which was limiting
* the <tt>concurrency</tt> of children of a runner where this scheduler was set, <em>this</em> <tt>balancer</tt>
* is limiting the concurrency of all children in runners having schedulers created by this constructor.
*
* @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)}
+ * @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 <tt>strategy</tt> or <tt>balancer</tt>
*/
- public Scheduler(Description description, SchedulingStrategy strategy, Balancer balancer) {
- strategy.setDefaultShutdownHandler(newShutdownHandler());
+ public Scheduler( Description description, SchedulingStrategy strategy, Balancer balancer )
+ {
+ strategy.setDefaultShutdownHandler( newShutdownHandler() );
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 description description of current runner
+ * @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)}
+ * @param strategy scheduling strategy for this scheduler
+ * @param balancer determines maximum concurrent children scheduled a time via {@link #schedule(Runnable)}
* @throws NullPointerException if null <tt>masterScheduler</tt>, <tt>strategy</tt> or <tt>balancer</tt>
*/
- public Scheduler(Description description, Scheduler masterScheduler, SchedulingStrategy strategy, Balancer balancer) {
- this(description, strategy, balancer);
- strategy.setDefaultShutdownHandler(newShutdownHandler());
- masterScheduler.register(this);
+ public Scheduler( Description description, Scheduler masterScheduler, SchedulingStrategy strategy,
+ Balancer balancer )
+ {
+ this( description, strategy, balancer );
+ strategy.setDefaultShutdownHandler( newShutdownHandler() );
+ masterScheduler.register( this );
}
/**
@@ -120,25 +133,29 @@ public class Scheduler implements RunnerScheduler {
* @see #Scheduler(org.junit.runner.Description, SchedulingStrategy)
* @see #Scheduler(org.junit.runner.Description, SchedulingStrategy, int)
*/
- public Scheduler(Description description, Scheduler masterScheduler, SchedulingStrategy strategy, int concurrency) {
- this(description, strategy, concurrency);
- strategy.setDefaultShutdownHandler(newShutdownHandler());
- masterScheduler.register(this);
+ public Scheduler( Description description, Scheduler masterScheduler, SchedulingStrategy strategy, int concurrency )
+ {
+ this( 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()}.
- * <p>
+ * <p/>
* Cached thread pool is infinite and can be always shared.
*/
- public Scheduler(Description description, Scheduler masterScheduler, SchedulingStrategy strategy) {
- this(description, masterScheduler, strategy, 0);
+ public Scheduler( Description description, Scheduler masterScheduler, SchedulingStrategy strategy )
+ {
+ this( description, masterScheduler, strategy, 0 );
}
- private void setController(Controller masterController) {
- if (masterController == null) {
- throw new NullPointerException("null ExecutionController");
+ private void setController( Controller masterController )
+ {
+ if ( masterController == null )
+ {
+ throw new NullPointerException( "null ExecutionController" );
}
this.masterController = masterController;
}
@@ -147,14 +164,17 @@ public class Scheduler implements RunnerScheduler {
* @param slave a slave scheduler to register
* @return <tt>true</tt> if successfully registered the <tt>slave</tt>.
*/
- private boolean register(Scheduler 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);
+ if ( canRegister )
+ {
+ Controller controller = new Controller( slave );
+ canRegister = !slaves.contains( controller );
+ if ( canRegister )
+ {
+ slaves.add( controller );
+ slave.setController( controller );
}
}
return canRegister;
@@ -163,50 +183,65 @@ public class Scheduler implements RunnerScheduler {
/**
* @return <tt>true</tt> if new tasks can be scheduled.
*/
- private boolean canSchedule() {
- return !shutdown && (masterController == null || masterController.canSchedule());
+ private boolean canSchedule()
+ {
+ return !shutdown && ( masterController == null || masterController.canSchedule() );
}
- protected void logQuietly(Throwable t) {
- t.printStackTrace(System.err);
+ protected void logQuietly( Throwable t )
+ {
+ t.printStackTrace( System.err );
}
- protected void logQuietly(String msg) {
- System.err.println(msg);
+ protected void logQuietly( String msg )
+ {
+ System.err.println( 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.
- * <p>
+ * <p/>
* This scheduler and other registered schedulers will shutdown, see {@link #register(Scheduler)}.
* If <tt>shutdownNow</tt> is set, waiting methods will be interrupted via {@link Thread#interrupt}.
*
* @param shutdownNow if <tt>true</tt> interrupts waiting methods
* @return collection of descriptions started before shutting down
*/
- public Collection<Description> shutdown(boolean shutdownNow) {
+ public Collection<Description> shutdown( boolean shutdownNow )
+ {
shutdown = true;
ArrayList<Description> activeChildren = new ArrayList<Description>();
- if (started && description != null) {
- activeChildren.add(description);
+ if ( started && description != null )
+ {
+ activeChildren.add( description );
}
- for (Controller slave : slaves) {
- try {
- activeChildren.addAll(slave.shutdown(shutdownNow));
- } catch (Throwable t) {
- logQuietly(t);
+ for ( Controller slave : slaves )
+ {
+ try
+ {
+ activeChildren.addAll( slave.shutdown( shutdownNow ) );
+ }
+ catch ( Throwable t )
+ {
+ logQuietly( t );
}
}
- try {
+ try
+ {
balancer.releaseAllPermits();
- } finally {
- if (shutdownNow) {
+ }
+ finally
+ {
+ if ( shutdownNow )
+ {
strategy.stopNow();
- } else {
+ }
+ else
+ {
strategy.stop();
}
}
@@ -214,52 +249,82 @@ public class Scheduler implements RunnerScheduler {
return activeChildren;
}
- protected void beforeExecute() {
+ protected void beforeExecute()
+ {
}
- protected void afterExecute() {
+ protected void afterExecute()
+ {
}
- public void schedule(Runnable childStatement) {
- if (childStatement == null) {
- logQuietly("cannot schedule null");
- } else if (canSchedule() && strategy.canSchedule()) {
- try {
- balancer.acquirePermit();
- Runnable task = wrapTask(childStatement);
- strategy.schedule(task);
- started = true;
- } catch (RejectedExecutionException e) {
- shutdown(false);
- } catch (Throwable t) {
+ 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 )
+ {
+ shutdown( false );
+ }
+ catch ( Throwable t )
+ {
balancer.releasePermit();
- logQuietly(t);
+ logQuietly( t );
}
}
}
- public void finished() {
- try {
+ public void finished()
+ {
+ try
+ {
strategy.finished();
- } catch (InterruptedException e) {
- logQuietly(e);
- } finally {
- for (Controller slave : slaves) {
+ }
+ catch ( InterruptedException e )
+ {
+ logQuietly( e );
+ }
+ finally
+ {
+ for ( Controller slave : slaves )
+ {
slave.awaitFinishedQuietly();
}
}
}
- private Runnable wrapTask(final Runnable task) {
- return new Runnable() {
- public void run() {
- try {
+ private Runnable wrapTask( final Runnable task )
+ {
+ return new Runnable()
+ {
+ public void run()
+ {
+ try
+ {
beforeExecute();
task.run();
- } finally {
- try {
+ }
+ finally
+ {
+ try
+ {
afterExecute();
- } finally {
+ }
+ finally
+ {
balancer.releasePermit();
}
}
@@ -267,68 +332,86 @@ public class Scheduler implements RunnerScheduler {
};
}
- protected ShutdownHandler newShutdownHandler() {
+ 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 class Controller
+ {
private final Scheduler slave;
- private Controller(Scheduler slave) {
+ private Controller( Scheduler slave )
+ {
this.slave = slave;
}
/**
* @return <tt>true</tt> if new children can be scheduled.
*/
- boolean canSchedule() {
+ boolean canSchedule()
+ {
return Scheduler.this.canSchedule();
}
- void awaitFinishedQuietly() {
- try {
+ void awaitFinishedQuietly()
+ {
+ try
+ {
slave.finished();
- } catch(Throwable t) {
- slave.logQuietly(t);
+ }
+ catch ( Throwable t )
+ {
+ slave.logQuietly( t );
}
}
- Collection<Description> shutdown(boolean shutdownNow) {
- return slave.shutdown(shutdownNow);
+ Collection<Description> shutdown( boolean shutdownNow )
+ {
+ return slave.shutdown( shutdownNow );
}
@Override
- public int hashCode() {
+ public int hashCode()
+ {
return slave.hashCode();
}
@Override
- public boolean equals(Object o) {
- return o == this || (o instanceof Controller) && slave.equals(((Controller) o).slave);
+ public boolean equals( Object o )
+ {
+ return o == this || ( o instanceof Controller ) && slave.equals( ( (Controller) o ).slave );
}
}
- public class ShutdownHandler implements RejectedExecutionHandler {
+ public class ShutdownHandler
+ implements RejectedExecutionHandler
+ {
private volatile RejectedExecutionHandler poolHandler;
- protected ShutdownHandler() {
+ protected ShutdownHandler()
+ {
poolHandler = null;
}
- public void setRejectedExecutionHandler(RejectedExecutionHandler poolHandler) {
+ public void setRejectedExecutionHandler( RejectedExecutionHandler poolHandler )
+ {
this.poolHandler = poolHandler;
}
- public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
- if (executor.isShutdown()) {
- shutdown(false);
+ public void rejectedExecution( Runnable r, ThreadPoolExecutor executor )
+ {
+ if ( executor.isShutdown() )
+ {
+ shutdown( false );
}
final RejectedExecutionHandler poolHandler = this.poolHandler;
- if (poolHandler != null) {
- poolHandler.rejectedExecution(r, executor);
+ if ( poolHandler != null )
+ {
+ poolHandler.rejectedExecution( r, executor );
}
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategies.java
----------------------------------------------------------------------
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
index 4d3c6a6..475f4c0 100644
--- 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
@@ -28,12 +28,14 @@ import java.util.concurrent.Executors;
* @author Tibor Digana (tibor17)
* @since 2.16
*/
-public class SchedulingStrategies {
+public class SchedulingStrategies
+{
/**
* @return sequentially executing strategy
*/
- public static SchedulingStrategy createInvokerStrategy() {
+ public static SchedulingStrategy createInvokerStrategy()
+ {
return new InvokerStrategy();
}
@@ -41,20 +43,22 @@ public class SchedulingStrategies {
* @param nThreads fixed pool capacity
* @return parallel scheduling strategy
*/
- public static SchedulingStrategy createParallelStrategy(int nThreads) {
- return new NonSharedThreadPoolStrategy(Executors.newFixedThreadPool(nThreads));
+ public static SchedulingStrategy createParallelStrategy( int nThreads )
+ {
+ return new NonSharedThreadPoolStrategy( Executors.newFixedThreadPool( nThreads ) );
}
/**
* @return parallel scheduling strategy with unbounded capacity
*/
- public static SchedulingStrategy createParallelStrategyUnbounded() {
- return new NonSharedThreadPoolStrategy(Executors.newCachedThreadPool());
+ public static SchedulingStrategy createParallelStrategyUnbounded()
+ {
+ return new NonSharedThreadPoolStrategy( Executors.newCachedThreadPool() );
}
/**
* The <tt>threadPool</tt> passed to this strategy can be shared in other strategies.
- * <p>
+ * <p/>
* 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
@@ -64,10 +68,12 @@ public class SchedulingStrategies {
* @return parallel strategy with shared thread pool
* @throws NullPointerException if <tt>threadPool</tt> is null
*/
- public static SchedulingStrategy createParallelSharedStrategy(ExecutorService threadPool) {
- if (threadPool == null) {
- throw new NullPointerException("null threadPool in #createParallelSharedStrategy");
+ public static SchedulingStrategy createParallelSharedStrategy( ExecutorService threadPool )
+ {
+ if ( threadPool == null )
+ {
+ throw new NullPointerException( "null threadPool in #createParallelSharedStrategy" );
}
- return new SharedThreadPoolStrategy(threadPool);
+ return new SharedThreadPoolStrategy( threadPool );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategy.java
----------------------------------------------------------------------
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
index c9da764..f419cb7 100644
--- 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
@@ -35,19 +35,20 @@ import java.util.concurrent.RejectedExecutionException;
* @author Tibor Digana (tibor17)
* @since 2.16
*/
-public abstract class SchedulingStrategy {
+public abstract class SchedulingStrategy
+{
/**
* Schedules tasks if {@link #canSchedule()}.
*
* @param task runnable to schedule in a thread pool or invoke
* @throws RejectedExecutionException if <tt>task</tt>
- * cannot be scheduled for execution
- * @throws NullPointerException if <tt>task</tt> is <tt>null</tt>
+ * cannot be scheduled for execution
+ * @throws NullPointerException if <tt>task</tt> is <tt>null</tt>
* @see RunnerScheduler#schedule(Runnable)
* @see java.util.concurrent.Executor#execute(Runnable)
*/
- protected abstract void schedule(Runnable task);
+ protected abstract void schedule( Runnable task );
/**
* Waiting for scheduled tasks to finish.
@@ -57,10 +58,11 @@ public abstract class SchedulingStrategy {
* <tt>false</tt> if already stopped (a <em>shared</em> thread
* pool was shutdown externally).
* @throws InterruptedException if interrupted while waiting
- * for scheduled tasks to finish
+ * for scheduled tasks to finish
* @see RunnerScheduler#finished()
*/
- protected abstract boolean finished() throws InterruptedException;
+ protected abstract boolean finished()
+ throws InterruptedException;
/**
* Stops scheduling new tasks (e.g. by {@link java.util.concurrent.ExecutorService#shutdown()}
@@ -77,7 +79,7 @@ public abstract class SchedulingStrategy {
* Stops scheduling new tasks and <em>interrupts</em> running tasks
* (e.g. by {@link java.util.concurrent.ExecutorService#shutdownNow()} on a private thread pool
* which cannot be <em>shared</em> with other strategy).
- * <p>
+ * <p/>
* This method calls {@link #stop()} by default.
*
* @return <tt>true</tt> if successfully stopped the scheduler, else
@@ -85,16 +87,18 @@ public abstract class SchedulingStrategy {
* pool was shutdown externally).
* @see java.util.concurrent.ExecutorService#shutdownNow()
*/
- protected boolean stopNow() {
+ protected boolean stopNow()
+ {
return stop();
}
- protected void setDefaultShutdownHandler(Scheduler.ShutdownHandler handler) {
+ protected void setDefaultShutdownHandler( Scheduler.ShutdownHandler handler )
+ {
}
/**
* @return <tt>true</tt> if a thread pool associated with this strategy
- * can be shared with other strategies.
+ * can be shared with other strategies.
*/
protected abstract boolean hasSharedThreadPool();
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/SharedThreadPoolStrategy.java
----------------------------------------------------------------------
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
index 53082c4..88907e6 100644
--- 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
@@ -29,33 +29,46 @@ import java.util.concurrent.Future;
* Parallel strategy for shared thread pool in private package.
*
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see AbstractThreadPoolStrategy
+ * @since 2.16
*/
-final class SharedThreadPoolStrategy extends AbstractThreadPoolStrategy {
- SharedThreadPoolStrategy(ExecutorService threadPool) {
- super(threadPool, new ConcurrentLinkedQueue<Future<?>>());
+final class SharedThreadPoolStrategy
+ extends AbstractThreadPoolStrategy
+{
+ SharedThreadPoolStrategy( ExecutorService threadPool )
+ {
+ super( threadPool, new ConcurrentLinkedQueue<Future<?>>() );
}
@Override
- public boolean hasSharedThreadPool() {
+ public boolean hasSharedThreadPool()
+ {
return true;
}
@Override
- public boolean finished() throws InterruptedException {
+ public boolean finished()
+ throws InterruptedException
+ {
boolean wasRunningAll = canSchedule();
- for (Future<?> futureResult : getFutureResults()) {
- try {
+ for ( Future<?> futureResult : getFutureResults() )
+ {
+ try
+ {
futureResult.get();
- } catch (InterruptedException e) {
+ }
+ catch ( InterruptedException e )
+ {
// after called external ExecutorService#shutdownNow()
// or ExecutorService#shutdown()
wasRunningAll = false;
- } catch (ExecutionException e) {
+ }
+ catch ( ExecutionException e )
+ {
// test throws exception
- } catch (CancellationException e) {
+ }
+ catch ( CancellationException e )
+ {
// cannot happen because not calling Future#cancel()
}
}
@@ -64,19 +77,23 @@ final class SharedThreadPoolStrategy extends AbstractThreadPoolStrategy {
}
@Override
- protected final boolean stop() {
- return stop(false);
+ protected final boolean stop()
+ {
+ return stop( false );
}
@Override
- protected final boolean stopNow() {
- return stop(true);
+ protected final boolean stopNow()
+ {
+ return stop( true );
}
- private boolean stop(boolean interrupt) {
+ private boolean stop( boolean interrupt )
+ {
final boolean wasRunning = canSchedule();
- for (Future<?> futureResult : getFutureResults()) {
- futureResult.cancel(interrupt);
+ for ( Future<?> futureResult : getFutureResults() )
+ {
+ futureResult.cancel( interrupt );
}
disable();
return wasRunning;
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/pc/ThreadResourcesBalancer.java
----------------------------------------------------------------------
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
index 80d116d..322d443 100644
--- 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
@@ -23,13 +23,14 @@ import java.util.concurrent.Semaphore;
/**
* @author Tibor Digana (tibor17)
- * @since 2.16
- *
* @see Balancer
+ * @since 2.16
*/
-final class ThreadResourcesBalancer implements Balancer
+final class ThreadResourcesBalancer
+ implements Balancer
{
private final Semaphore balancer;
+
private final int numPermits;
/**
@@ -37,7 +38,6 @@ final class ThreadResourcesBalancer implements Balancer
*
* @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 )
@@ -48,7 +48,7 @@ final class ThreadResourcesBalancer implements Balancer
/**
* @param numPermits number of permits to acquire when maintaining concurrency on tests.
* Must be >0 and < {@link Integer#MAX_VALUE}.
- * @param fair <tt>true</tt> guarantees the waiting schedulers to wake up in order they acquired a permit
+ * @param fair <tt>true</tt> guarantees the waiting schedulers to wake up in order they acquired a permit
*/
ThreadResourcesBalancer( int numPermits, boolean fair )
{