maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agud...@apache.org
Subject [1/3] reformat code + IT + junit.apt.vm + fork-options-and-parllel-execution.apt.vm
Date Fri, 16 Aug 2013 08:55:19 GMT
Updated Branches:
  refs/heads/master 911d374c7 -> a9d511a03


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ParallelComputerFactoryTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ParallelComputerFactoryTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ParallelComputerFactoryTest.java
index 90d773e..c3682ae 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ParallelComputerFactoryTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/ParallelComputerFactoryTest.java
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitcore;
  * under the License.
  */
 
+import org.apache.maven.surefire.junitcore.pc.ParallelComputer;
 import org.apache.maven.surefire.testset.TestSetFailedException;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -28,9 +29,12 @@ import org.junit.experimental.theories.DataPoint;
 import org.junit.experimental.theories.Theories;
 import org.junit.experimental.theories.Theory;
 import org.junit.rules.ExpectedException;
+import org.junit.runner.JUnitCore;
+import org.junit.runner.Result;
 import org.junit.runner.RunWith;
 
 import java.util.Properties;
+import java.util.concurrent.ExecutionException;
 
 import static org.apache.maven.surefire.junitcore.ParallelComputerFactory.*;
 import static org.apache.maven.surefire.junitcore.JUnitCoreParameters.*;
@@ -42,22 +46,24 @@ import static org.junit.Assert.*;
  * allocated thread resources in ParallelComputer by given {@link JUnitCoreParameters}.
  *
  * @author Tibor Digana (tibor17)
- * @since 2.16
- *
  * @see org.apache.maven.surefire.junitcore.ParallelComputerFactory
+ * @since 2.16
  */
-@RunWith(Theories.class)
+@RunWith( Theories.class )
 public final class ParallelComputerFactoryTest
 {
-    @Rule
-    public final ExpectedException exception = ExpectedException.none();
-
     @DataPoint
     public static final int CPU_1 = 1;
 
     @DataPoint
     public static final int CPU_4 = 4;
 
+    @Rule
+    public final ExpectedException exception = ExpectedException.none();
+
+    @Rule
+    public final Stopwatch runtime = new Stopwatch();
+
     @BeforeClass
     public static void beforeClass()
     {
@@ -70,16 +76,25 @@ public final class ParallelComputerFactoryTest
         ParallelComputerFactory.setDefaultAvailableProcessors();
     }
 
+    private static Properties parallel( String parallel )
+    {
+        Properties properties = new Properties();
+        properties.setProperty( PARALLEL_KEY, parallel );
+        return properties;
+    }
+
     @Test
-    public void unknownParallel() throws TestSetFailedException
+    public void unknownParallel()
+        throws TestSetFailedException
     {
         Properties properties = new Properties();
-        exception.expect( TestSetFailedException.class  );
+        exception.expect( TestSetFailedException.class );
         resolveConcurrency( new JUnitCoreParameters( properties ) );
     }
 
     @Test
-    public void unknownThreadCountSuites() throws TestSetFailedException
+    public void unknownThreadCountSuites()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suites" ) );
         assertTrue( params.isParallelSuites() );
@@ -90,7 +105,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountClasses() throws TestSetFailedException
+    public void unknownThreadCountClasses()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "classes" ) );
         assertFalse( params.isParallelSuites() );
@@ -101,7 +117,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountMethods() throws TestSetFailedException
+    public void unknownThreadCountMethods()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "methods" ) );
         assertFalse( params.isParallelSuites() );
@@ -112,7 +129,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountBoth() throws TestSetFailedException
+    public void unknownThreadCountBoth()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "both" ) );
         assertFalse( params.isParallelSuites() );
@@ -123,7 +141,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountAll() throws TestSetFailedException
+    public void unknownThreadCountAll()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "all" ) );
         assertTrue( params.isParallelSuites() );
@@ -134,7 +153,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountSuitesAndClasses() throws TestSetFailedException
+    public void unknownThreadCountSuitesAndClasses()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suitesAndClasses" ) );
         assertTrue( params.isParallelSuites() );
@@ -145,7 +165,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountSuitesAndMethods() throws TestSetFailedException
+    public void unknownThreadCountSuitesAndMethods()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "suitesAndMethods" ) );
         assertTrue( params.isParallelSuites() );
@@ -156,7 +177,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Test
-    public void unknownThreadCountClassesAndMethods() throws TestSetFailedException
+    public void unknownThreadCountClassesAndMethods()
+        throws TestSetFailedException
     {
         JUnitCoreParameters params = new JUnitCoreParameters( parallel( "classesAndMethods" ) );
         assertFalse( params.isParallelSuites() );
@@ -167,7 +189,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void useUnlimitedThreadsSuites( int cpu ) throws TestSetFailedException
+    public void useUnlimitedThreadsSuites( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -196,7 +219,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void useUnlimitedThreadsClasses( int cpu ) throws TestSetFailedException
+    public void useUnlimitedThreadsClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -225,7 +249,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void unlimitedThreadsMethods( int cpu ) throws TestSetFailedException
+    public void unlimitedThreadsMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -254,7 +279,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void unlimitedThreadsSuitesAndClasses( int cpu ) throws TestSetFailedException
+    public void unlimitedThreadsSuitesAndClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -284,7 +310,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void unlimitedThreadsSuitesAndMethods( int cpu ) throws TestSetFailedException
+    public void unlimitedThreadsSuitesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -314,7 +341,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void unlimitedThreadsClassesAndMethods( int cpu ) throws TestSetFailedException
+    public void unlimitedThreadsClassesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -344,7 +372,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void unlimitedThreadsAll( int cpu ) throws TestSetFailedException
+    public void unlimitedThreadsAll( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -375,7 +404,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountSuites( int cpu ) throws TestSetFailedException
+    public void threadCountSuites( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -393,7 +423,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountClasses( int cpu ) throws TestSetFailedException
+    public void threadCountClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -411,7 +442,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountMethods( int cpu ) throws TestSetFailedException
+    public void threadCountMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -429,7 +461,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountBoth( int cpu ) throws TestSetFailedException
+    public void threadCountBoth( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -447,7 +480,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountClassesAndMethods( int cpu ) throws TestSetFailedException
+    public void threadCountClassesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -465,7 +499,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountSuitesAndMethods( int cpu ) throws TestSetFailedException
+    public void threadCountSuitesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -483,7 +518,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountSuitesAndClasses( int cpu ) throws TestSetFailedException
+    public void threadCountSuitesAndClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -501,7 +537,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void threadCountAll( int cpu ) throws TestSetFailedException
+    public void threadCountAll( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -519,7 +556,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void everyThreadCountSuitesAndClasses( int cpu ) throws TestSetFailedException
+    public void everyThreadCountSuitesAndClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -533,7 +571,7 @@ public final class ParallelComputerFactoryTest
         assertTrue( params.isParallelSuites() );
         assertTrue( params.isParallelClasses() );
         assertFalse( params.isParallelMethod() );
-        assertThat( concurrency.capacity, is(3 * cpu) );
+        assertThat( concurrency.capacity, is( 3 * cpu ) );
         int concurrentSuites = (int) ( 0.34d * concurrency.capacity );
         assertThat( concurrency.suites, is( concurrentSuites ) );
         assertThat( concurrency.classes, is( concurrency.capacity - concurrentSuites ) );
@@ -541,7 +579,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void everyThreadCountSuitesAndMethods( int cpu ) throws TestSetFailedException
+    public void everyThreadCountSuitesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -563,7 +602,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void everyThreadCountClassesAndMethods( int cpu ) throws TestSetFailedException
+    public void everyThreadCountClassesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -585,7 +625,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void everyThreadCountAll( int cpu ) throws TestSetFailedException
+    public void everyThreadCountAll( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -609,7 +650,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void reusableThreadCountSuitesAndClasses( int cpu ) throws TestSetFailedException
+    public void reusableThreadCountSuitesAndClasses( int cpu )
+        throws TestSetFailedException
     {
         // 4 * cpu to 5 * cpu threads to run test classes
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
@@ -629,7 +671,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void reusableThreadCountSuitesAndMethods( int cpu ) throws TestSetFailedException
+    public void reusableThreadCountSuitesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         // 4 * cpu to 5 * cpu threads to run test methods
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
@@ -649,7 +692,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void reusableThreadCountClassesAndMethods( int cpu ) throws TestSetFailedException
+    public void reusableThreadCountClassesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         // 4 * cpu to 5 * cpu threads to run test methods
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
@@ -669,7 +713,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void reusableThreadCountAll( int cpu ) throws TestSetFailedException
+    public void reusableThreadCountAll( int cpu )
+        throws TestSetFailedException
     {
         // 8 * cpu to 13 * cpu threads to run test methods
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
@@ -690,7 +735,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void suites( int cpu ) throws TestSetFailedException
+    public void suites( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -708,7 +754,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void classes( int cpu ) throws TestSetFailedException
+    public void classes( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -726,7 +773,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void methods( int cpu ) throws TestSetFailedException
+    public void methods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -744,7 +792,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void suitesAndClasses( int cpu ) throws TestSetFailedException
+    public void suitesAndClasses( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -779,7 +828,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void suitesAndMethods( int cpu ) throws TestSetFailedException
+    public void suitesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -814,7 +864,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void classesAndMethods( int cpu ) throws TestSetFailedException
+    public void classesAndMethods( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -849,7 +900,8 @@ public final class ParallelComputerFactoryTest
     }
 
     @Theory
-    public void all( int cpu ) throws TestSetFailedException
+    public void all( int cpu )
+        throws TestSetFailedException
     {
         ParallelComputerFactory.overrideAvailableProcessors( cpu );
         Properties properties = new Properties();
@@ -898,10 +950,114 @@ public final class ParallelComputerFactoryTest
         assertThat( concurrency.methods, is( Integer.MAX_VALUE ) );
     }
 
-    private static Properties parallel( String parallel )
+    @Test
+    public void withoutShutdown()
+        throws TestSetFailedException, ExecutionException, InterruptedException
     {
         Properties properties = new Properties();
-        properties.setProperty( PARALLEL_KEY, parallel );
-        return properties;
+        properties.setProperty( PARALLEL_KEY, "methods" );
+        properties.setProperty( THREADCOUNTMETHODS_KEY, "2" );
+        JUnitCoreParameters params = new JUnitCoreParameters( properties );
+        ParallelComputer pc = createParallelComputer( params );
+
+        Result result = new JUnitCore().run( pc, TestClass.class );
+        long timeSpent = runtime.stop();
+        long deltaTime = 500L;
+
+        assertTrue( result.wasSuccessful() );
+        assertThat( result.getRunCount(), is( 3 ) );
+        assertThat( result.getFailureCount(), is( 0 ) );
+        assertThat( result.getIgnoreCount(), is( 0 ) );
+        assertEquals( 10000L, timeSpent, deltaTime );
+    }
+
+    @Test
+    public void shutdown()
+        throws TestSetFailedException, ExecutionException, InterruptedException
+    {
+        // The JUnitCore returns after 2.5s.
+        // The test-methods in TestClass are NOT interrupted, and return normally after 5s.
+        Properties properties = new Properties();
+        properties.setProperty( PARALLEL_KEY, "methods" );
+        properties.setProperty( THREADCOUNTMETHODS_KEY, "2" );
+        properties.setProperty( PARALLEL_TIMEOUT_KEY, Double.toString( 2.5d ) );
+        JUnitCoreParameters params = new JUnitCoreParameters( properties );
+        ParallelComputer pc = createParallelComputer( params );
+
+        new JUnitCore().run( pc, TestClass.class );
+        long timeSpent = runtime.stop();
+        long deltaTime = 500L;
+
+        assertEquals( 2500L, timeSpent, deltaTime );
+        assertTrue( pc.describeElapsedTimeout().contains(
+            "The test run has finished abruptly after timeout of 2.5 seconds." ) );
+        assertTrue( pc.describeElapsedTimeout().contains( TestClass.class.getName() ) );
+    }
+
+    @Test
+    public void forcedShutdown()
+        throws TestSetFailedException, ExecutionException, InterruptedException
+    {
+        // The JUnitCore returns after 2.5s, and the test-methods in TestClass are interrupted.
+        Properties properties = new Properties();
+        properties.setProperty( PARALLEL_KEY, "methods" );
+        properties.setProperty( THREADCOUNTMETHODS_KEY, "2" );
+        properties.setProperty( PARALLEL_TIMEOUTFORCED_KEY, Double.toString( 2.5d ) );
+        JUnitCoreParameters params = new JUnitCoreParameters( properties );
+        ParallelComputer pc = createParallelComputer( params );
+
+        new JUnitCore().run( pc, TestClass.class );
+        long timeSpent = runtime.stop();
+        long deltaTime = 500L;
+
+        assertEquals( 2500L, timeSpent, deltaTime );
+        assertTrue( pc.describeElapsedTimeout().contains(
+            "The test run has finished abruptly after timeout of 2.5 seconds." ) );
+        assertTrue( pc.describeElapsedTimeout().contains( TestClass.class.getName() ) );
+    }
+
+    public static class TestClass
+    {
+        @Test
+        public void a()
+            throws InterruptedException
+        {
+            long t1 = System.currentTimeMillis();
+            try{
+                Thread.sleep( 5000L );
+            }
+            finally
+            {
+                System.out.println( getClass().getSimpleName() + "#a() spent " + ( System.currentTimeMillis() - t1 ) );
+            }
+        }
+
+        @Test
+        public void b()
+            throws InterruptedException
+        {
+            long t1 = System.currentTimeMillis();
+            try{
+                Thread.sleep( 5000L );
+            }
+            finally
+            {
+                System.out.println( getClass().getSimpleName() + "#b() spent " + ( System.currentTimeMillis() - t1 ) );
+            }
+        }
+
+        @Test
+        public void c()
+            throws InterruptedException
+        {
+            long t1 = System.currentTimeMillis();
+            try{
+                Thread.sleep( 5000L );
+            }
+            finally
+            {
+                System.out.println( getClass().getSimpleName() + "#c() spent " + ( System.currentTimeMillis() - t1 ) );
+            }
+        }
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Stopwatch.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Stopwatch.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Stopwatch.java
new file mode 100644
index 0000000..558fc06
--- /dev/null
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/Stopwatch.java
@@ -0,0 +1,46 @@
+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.
+ */
+
+import org.junit.rules.TestWatchman;
+import org.junit.runners.model.FrameworkMethod;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Tibor Digana (tibor17)
+ * @since 2.16
+ */
+public final class Stopwatch
+    extends TestWatchman
+{
+    private long startNanos;
+
+    public long stop()
+    {
+        return TimeUnit.MILLISECONDS.convert( System.nanoTime() - startNanos, TimeUnit.NANOSECONDS );
+    }
+
+    @Override
+    public void starting( FrameworkMethod method )
+    {
+        startNanos = System.nanoTime();
+    }
+}

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
index c34056a..4dda465 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/ParallelComputerBuilderTest.java
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitcore.pc;
  * under the License.
  */
 
+import org.apache.maven.surefire.junitcore.Stopwatch;
 import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -48,97 +49,132 @@ import static org.apache.maven.surefire.junitcore.pc.RangeMatcher.between;
  * @author Tibor Digana (tibor17)
  * @since 2.16
  */
-public class ParallelComputerBuilderTest {
+public class ParallelComputerBuilderTest
+{
+    private static volatile boolean beforeShutdown;
+
+    private static volatile Runnable shutdownTask;
+
     @Rule
     public final Stopwatch runtime = new Stopwatch();
 
+    private static void testKeepBeforeAfter( ParallelComputerBuilder builder, Class<?>... classes )
+    {
+        JUnitCore core = new JUnitCore();
+        for ( int round = 0; round < 5; round++ )
+        {
+            NothingDoingTest1.methods.clear();
+            Result result = core.run( builder.buildComputer(), classes );
+            assertTrue( result.wasSuccessful() );
+            Iterator<String> methods = NothingDoingTest1.methods.iterator();
+            for ( Class<?> clazz : classes )
+            {
+                String a = clazz.getName() + "#a()";
+                String b = clazz.getName() + "#b()";
+                assertThat( methods.next(), is( "init" ) );
+                assertThat( methods.next(), anyOf( is( a ), is( b ) ) );
+                assertThat( methods.next(), anyOf( is( a ), is( b ) ) );
+                assertThat( methods.next(), is( "deinit" ) );
+            }
+        }
+    }
+
     @Before
-    public void beforeTest() {
+    public void beforeTest()
+    {
         Class1.maxConcurrentMethods = 0;
         Class1.concurrentMethods = 0;
         shutdownTask = null;
     }
 
     @Test
-    public void parallelMethodsReuseOneOrTwoThreads() {
+    public void parallelMethodsReuseOneOrTwoThreads()
+    {
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.useOnePool(4);
+        parallelComputerBuilder.useOnePool( 4 );
 
         // One thread because one suite: TestSuite, however the capacity is 5.
-        parallelComputerBuilder.parallelSuites(5);
+        parallelComputerBuilder.parallelSuites( 5 );
 
         // Two threads because TestSuite has two classes, however the capacity is 5.
-        parallelComputerBuilder.parallelClasses(5);
+        parallelComputerBuilder.parallelClasses( 5 );
 
         // One or two threads because one threads comes from '#useOnePool(4)'
         // and next thread may be reused from finished class, however the capacity is 3.
-        parallelComputerBuilder.parallelMethods(3);
+        parallelComputerBuilder.parallelMethods( 3 );
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(0));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertFalse(computer.splitPool);
-        assertThat(computer.poolCapacity, is(4));
-        assertTrue(result.wasSuccessful());
-        if (Class1.maxConcurrentMethods == 1) {
-            assertThat(timeSpent, between(1950, 2250));
-        } else if (Class1.maxConcurrentMethods == 2) {
-            assertThat(timeSpent, between(1450, 1750));
-        } else {
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 0 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertFalse( computer.splitPool );
+        assertThat( computer.poolCapacity, is( 4 ) );
+        assertTrue( result.wasSuccessful() );
+        if ( Class1.maxConcurrentMethods == 1 )
+        {
+            assertThat( timeSpent, between( 1950, 2250 ) );
+        }
+        else if ( Class1.maxConcurrentMethods == 2 )
+        {
+            assertThat( timeSpent, between( 1450, 1750 ) );
+        }
+        else
+        {
             fail();
         }
     }
 
     @Test
-    public void suiteAndClassInOnePool() {
+    public void suiteAndClassInOnePool()
+    {
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.useOnePool(5);
-        parallelComputerBuilder.parallelSuites(5);
-        parallelComputerBuilder.parallelClasses(5);
-        parallelComputerBuilder.parallelMethods(3);
+        parallelComputerBuilder.useOnePool( 5 );
+        parallelComputerBuilder.parallelSuites( 5 );
+        parallelComputerBuilder.parallelClasses( 5 );
+        parallelComputerBuilder.parallelMethods( 3 );
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class, Class1.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(1));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertFalse(computer.splitPool);
-        assertThat(computer.poolCapacity, is(5));
-        assertTrue(result.wasSuccessful());
-        assertThat(Class1.maxConcurrentMethods, is(2));
-        assertThat(timeSpent, anyOf(between(1450, 1750), between(1950, 2250), between(2450, 2750)));
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 1 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertFalse( computer.splitPool );
+        assertThat( computer.poolCapacity, is( 5 ) );
+        assertTrue( result.wasSuccessful() );
+        assertThat( Class1.maxConcurrentMethods, is( 2 ) );
+        assertThat( timeSpent, anyOf( between( 1450, 1750 ), between( 1950, 2250 ), between( 2450, 2750 ) ) );
     }
 
     @Test
-    public void onePoolWithUnlimitedParallelMethods() {
+    public void onePoolWithUnlimitedParallelMethods()
+    {
         // see ParallelComputerBuilder Javadoc
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.useOnePool(8);
-        parallelComputerBuilder.parallelSuites(2);
-        parallelComputerBuilder.parallelClasses(4);
+        parallelComputerBuilder.useOnePool( 8 );
+        parallelComputerBuilder.parallelSuites( 2 );
+        parallelComputerBuilder.parallelClasses( 4 );
         parallelComputerBuilder.parallelMethods();
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class, Class1.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(1));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertFalse(computer.splitPool);
-        assertThat(computer.poolCapacity, is(8));
-        assertTrue(result.wasSuccessful());
-        assertThat(Class1.maxConcurrentMethods, is(4));
-        assertThat(timeSpent, between(950, 1250));
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 1 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertFalse( computer.splitPool );
+        assertThat( computer.poolCapacity, is( 8 ) );
+        assertTrue( result.wasSuccessful() );
+        assertThat( Class1.maxConcurrentMethods, is( 4 ) );
+        assertThat( timeSpent, between( 950, 1250 ) );
     }
 
     @Test
@@ -156,7 +192,7 @@ public class ParallelComputerBuilderTest {
         // One thread remains from '#useOnePool(3)'.
         parallelComputerBuilder.parallelMethods( 3 );
 
-        ParallelComputerBuilder.PC computer = ( ParallelComputerBuilder.PC ) parallelComputerBuilder.buildComputer();
+        ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
         Result result = new JUnitCore().run( computer, TestSuite.class );
         long timeSpent = runtime.stop();
 
@@ -172,265 +208,283 @@ public class ParallelComputerBuilderTest {
     }
 
     @Test
-    public void separatePoolsWithSuite() {
+    public void separatePoolsWithSuite()
+    {
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.parallelSuites(5);
-        parallelComputerBuilder.parallelClasses(5);
-        parallelComputerBuilder.parallelMethods(3);
+        parallelComputerBuilder.parallelSuites( 5 );
+        parallelComputerBuilder.parallelClasses( 5 );
+        parallelComputerBuilder.parallelMethods( 3 );
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(0));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertTrue(computer.splitPool);
-        assertThat(computer.poolCapacity, is(ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED));
-        assertTrue(result.wasSuccessful());
-        assertThat(Class1.maxConcurrentMethods, is(3));
-        assertThat(timeSpent, between(950, 1250));
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 0 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertTrue( computer.splitPool );
+        assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+        assertTrue( result.wasSuccessful() );
+        assertThat( Class1.maxConcurrentMethods, is( 3 ) );
+        assertThat( timeSpent, between( 950, 1250 ) );
     }
 
     @Test
-    public void separatePoolsWithSuiteAndClass() {
+    public void separatePoolsWithSuiteAndClass()
+    {
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.parallelSuites(5);
-        parallelComputerBuilder.parallelClasses(5);
-        parallelComputerBuilder.parallelMethods(3);
+        parallelComputerBuilder.parallelSuites( 5 );
+        parallelComputerBuilder.parallelClasses( 5 );
+        parallelComputerBuilder.parallelMethods( 3 );
 
         // 6 methods altogether.
         // 2 groups with 3 threads.
         // Each group takes 0.5s.
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class, Class1.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(1));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertTrue(computer.splitPool);
-        assertThat(computer.poolCapacity, is(ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED));
-        assertTrue(result.wasSuccessful());
-        assertThat(Class1.maxConcurrentMethods, is(3));
-        assertThat(timeSpent, between(950, 1250));
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 1 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertTrue( computer.splitPool );
+        assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+        assertTrue( result.wasSuccessful() );
+        assertThat( Class1.maxConcurrentMethods, is( 3 ) );
+        assertThat( timeSpent, between( 950, 1250 ) );
     }
 
     @Test
-    public void separatePoolsWithSuiteAndSequentialClasses() {
+    public void separatePoolsWithSuiteAndSequentialClasses()
+    {
         ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder();
-        parallelComputerBuilder.parallelSuites(5);
-        parallelComputerBuilder.parallelClasses(1);
-        parallelComputerBuilder.parallelMethods(3);
+        parallelComputerBuilder.parallelSuites( 5 );
+        parallelComputerBuilder.parallelClasses( 1 );
+        parallelComputerBuilder.parallelMethods( 3 );
 
         ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-        Result result = new JUnitCore().run(computer, TestSuite.class, Class1.class);
+        Result result = new JUnitCore().run( computer, TestSuite.class, Class1.class );
         long timeSpent = runtime.stop();
 
-        assertThat(computer.suites.size(), is(1));
-        assertThat(computer.classes.size(), is(1));
-        assertThat(computer.nestedClasses.size(), is(2));
-        assertThat(computer.nestedSuites.size(), is(0));
-        assertTrue(computer.splitPool);
-        assertThat(computer.poolCapacity, is(ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED));
-        assertTrue(result.wasSuccessful());
-        assertThat(Class1.maxConcurrentMethods, is(2));
-        assertThat(timeSpent, between(1450, 1750));
-    }
-
-    private static class ShutdownTest {
-        Result run(final boolean useInterrupt) {
-            ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder().useOnePool(8);
-            parallelComputerBuilder.parallelSuites(2);
-            parallelComputerBuilder.parallelClasses(3);
-            parallelComputerBuilder.parallelMethods(3);
-
-            final ParallelComputerBuilder.PC computer = (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
-            shutdownTask = new Runnable() {
-                public void run() {
-                    Collection<org.junit.runner.Description> startedTests = computer.shutdown(useInterrupt);
-                    assertThat(startedTests.size(), is(not(0)));
-                }
-            };
-            return new JUnitCore().run(computer, TestSuite.class, Class2.class, Class3.class);
-        }
+        assertThat( computer.suites.size(), is( 1 ) );
+        assertThat( computer.classes.size(), is( 1 ) );
+        assertThat( computer.nestedClasses.size(), is( 2 ) );
+        assertThat( computer.nestedSuites.size(), is( 0 ) );
+        assertTrue( computer.splitPool );
+        assertThat( computer.poolCapacity, is( ParallelComputerBuilder.TOTAL_POOL_SIZE_UNDEFINED ) );
+        assertTrue( result.wasSuccessful() );
+        assertThat( Class1.maxConcurrentMethods, is( 2 ) );
+        assertThat( timeSpent, between( 1450, 1750 ) );
     }
 
-    @Test(timeout = 2000)
-    public void shutdown() {
-        Result result = new ShutdownTest().run(false);
+    @Test( timeout = 2000 )
+    public void shutdown()
+    {
+        Result result = new ShutdownTest().run( false );
         long timeSpent = runtime.stop();
-        assertTrue(result.wasSuccessful());
-        assertTrue(beforeShutdown);
-        assertThat(timeSpent, between(450, 1250));
+        assertTrue( result.wasSuccessful() );
+        assertTrue( beforeShutdown );
+        assertThat( timeSpent, between( 450, 1250 ) );
     }
 
-    @Test(timeout = 2000)
-    public void shutdownWithInterrupt() {
-        new ShutdownTest().run(true);
+    @Test( timeout = 2000 )
+    public void shutdownWithInterrupt()
+    {
+        new ShutdownTest().run( true );
         long timeSpent = runtime.stop();
-        assertTrue(beforeShutdown);
-        assertThat(timeSpent, between(450, 1250));
+        assertTrue( beforeShutdown );
+        assertThat( timeSpent, between( 450, 1250 ) );
     }
 
     @Test
-    public void nothingParallel() {
+    public void nothingParallel()
+    {
         JUnitCore core = new JUnitCore();
         ParallelComputerBuilder builder = new ParallelComputerBuilder();
 
-        Result result = core.run(builder.buildComputer(), NothingDoingTest1.class, NothingDoingTest2.class);
-        assertTrue(result.wasSuccessful());
-
-        result = core.run(builder.buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class);
-        assertTrue(result.wasSuccessful());
+        Result result = core.run( builder.buildComputer(), NothingDoingTest1.class, NothingDoingTest2.class );
+        assertTrue( result.wasSuccessful() );
 
-        result = core.run(builder.useOnePool(1).buildComputer(), NothingDoingTest1.class, NothingDoingTest2.class);
-        assertTrue(result.wasSuccessful());
+        result = core.run( builder.buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class );
+        assertTrue( result.wasSuccessful() );
 
-        result = core.run(builder.useOnePool(1).buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class);
-        assertTrue(result.wasSuccessful());
+        result = core.run( builder.useOnePool( 1 ).buildComputer(), NothingDoingTest1.class, NothingDoingTest2.class );
+        assertTrue( result.wasSuccessful() );
 
-        result = core.run(builder.useOnePool(2).buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class);
-        assertTrue(result.wasSuccessful());
+        result = core.run( builder.useOnePool( 1 ).buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class );
+        assertTrue( result.wasSuccessful() );
 
-        Class<?>[] classes = {NothingDoingTest1.class, NothingDoingSuite.class};
+        result = core.run( builder.useOnePool( 2 ).buildComputer(), NothingDoingTest1.class, NothingDoingSuite.class );
+        assertTrue( result.wasSuccessful() );
 
-        result = core.run(builder.useOnePool(2).parallelSuites(1).parallelClasses(1).buildComputer(), classes);
-        assertTrue(result.wasSuccessful());
+        Class<?>[] classes = { NothingDoingTest1.class, NothingDoingSuite.class };
 
-        result = core.run(builder.useOnePool(2).parallelSuites(1).parallelClasses().buildComputer(), classes);
-        assertTrue(result.wasSuccessful());
+        result = core.run( builder.useOnePool( 2 ).parallelSuites( 1 ).parallelClasses( 1 ).buildComputer(), classes );
+        assertTrue( result.wasSuccessful() );
 
-        classes = new Class<?>[]{NothingDoingSuite.class, NothingDoingSuite.class,
-                NothingDoingTest1.class, NothingDoingTest2.class, NothingDoingTest3.class};
+        result = core.run( builder.useOnePool( 2 ).parallelSuites( 1 ).parallelClasses().buildComputer(), classes );
+        assertTrue( result.wasSuccessful() );
 
-        result = core.run(builder.useOnePool(2).parallelSuites(1).parallelClasses(1).buildComputer(), classes);
-        assertTrue(result.wasSuccessful());
+        classes = new Class<?>[]{ NothingDoingSuite.class, NothingDoingSuite.class, NothingDoingTest1.class,
+            NothingDoingTest2.class, NothingDoingTest3.class };
 
-        result = core.run(builder.useOnePool(2).parallelSuites(1).parallelClasses().buildComputer(), classes);
-        assertTrue(result.wasSuccessful());
-    }
+        result = core.run( builder.useOnePool( 2 ).parallelSuites( 1 ).parallelClasses( 1 ).buildComputer(), classes );
+        assertTrue( result.wasSuccessful() );
 
-    private static void testKeepBeforeAfter(ParallelComputerBuilder builder, Class<?>... classes) {
-        JUnitCore core = new JUnitCore();
-        for (int round = 0; round < 5; round++) {
-            NothingDoingTest1.methods.clear();
-            Result result = core.run(builder.buildComputer(), classes);
-            assertTrue(result.wasSuccessful());
-            Iterator<String> methods = NothingDoingTest1.methods.iterator();
-            for (Class<?> clazz : classes) {
-                String a = clazz.getName() + "#a()";
-                String b = clazz.getName() + "#b()";
-                assertThat(methods.next(), is("init"));
-                assertThat(methods.next(), anyOf(is(a), is(b)));
-                assertThat(methods.next(), anyOf(is(a), is(b)));
-                assertThat(methods.next(), is("deinit"));
-            }
-        }
+        result = core.run( builder.useOnePool( 2 ).parallelSuites( 1 ).parallelClasses().buildComputer(), classes );
+        assertTrue( result.wasSuccessful() );
     }
 
     @Test
-    public void keepBeforeAfterOneClass() {
+    public void keepBeforeAfterOneClass()
+    {
         ParallelComputerBuilder builder = new ParallelComputerBuilder();
         builder.parallelMethods();
-        testKeepBeforeAfter(builder, NothingDoingTest1.class);
+        testKeepBeforeAfter( builder, NothingDoingTest1.class );
     }
 
     @Test
-    public void keepBeforeAfterTwoClasses() {
+    public void keepBeforeAfterTwoClasses()
+    {
         ParallelComputerBuilder builder = new ParallelComputerBuilder();
-        builder.useOnePool(5).parallelClasses(1).parallelMethods(2);
-        testKeepBeforeAfter(builder, NothingDoingTest1.class, NothingDoingTest2.class);
+        builder.useOnePool( 5 ).parallelClasses( 1 ).parallelMethods( 2 );
+        testKeepBeforeAfter( builder, NothingDoingTest1.class, NothingDoingTest2.class );
     }
 
     @Test
-    public void keepBeforeAfterTwoParallelClasses() {
+    public void keepBeforeAfterTwoParallelClasses()
+    {
         ParallelComputerBuilder builder = new ParallelComputerBuilder();
-        builder.useOnePool(8).parallelClasses(2).parallelMethods(2);
+        builder.useOnePool( 8 ).parallelClasses( 2 ).parallelMethods( 2 );
         JUnitCore core = new JUnitCore();
         NothingDoingTest1.methods.clear();
-        Class<?>[] classes = {NothingDoingTest1.class, NothingDoingTest2.class, NothingDoingTest3.class};
-        Result result = core.run(builder.buildComputer(), classes);
-        assertTrue(result.wasSuccessful());
-        ArrayList<String> methods = new ArrayList<String>(NothingDoingTest1.methods);
-        assertThat(methods.size(), is(12));
-        assertThat(methods.subList(9, 12), is(not(Arrays.asList("deinit", "deinit", "deinit"))));
+        Class<?>[] classes = { NothingDoingTest1.class, NothingDoingTest2.class, NothingDoingTest3.class };
+        Result result = core.run( builder.buildComputer(), classes );
+        assertTrue( result.wasSuccessful() );
+        ArrayList<String> methods = new ArrayList<String>( NothingDoingTest1.methods );
+        assertThat( methods.size(), is( 12 ) );
+        assertThat( methods.subList( 9, 12 ), is( not( Arrays.asList( "deinit", "deinit", "deinit" ) ) ) );
     }
 
-    private static volatile boolean beforeShutdown;
-    private static volatile Runnable shutdownTask;
+    private static class ShutdownTest
+    {
+        Result run( final boolean useInterrupt )
+        {
+            ParallelComputerBuilder parallelComputerBuilder = new ParallelComputerBuilder().useOnePool( 8 );
+            parallelComputerBuilder.parallelSuites( 2 );
+            parallelComputerBuilder.parallelClasses( 3 );
+            parallelComputerBuilder.parallelMethods( 3 );
+
+            final ParallelComputerBuilder.PC computer =
+                (ParallelComputerBuilder.PC) parallelComputerBuilder.buildComputer();
+            shutdownTask = new Runnable()
+            {
+                public void run()
+                {
+                    Collection<org.junit.runner.Description> startedTests = computer.shutdown( useInterrupt );
+                    assertThat( startedTests.size(), is( not( 0 ) ) );
+                }
+            };
+            return new JUnitCore().run( computer, TestSuite.class, Class2.class, Class3.class );
+        }
+    }
 
-    public static class Class1 {
+    public static class Class1
+    {
         static volatile int concurrentMethods = 0;
+
         static volatile int maxConcurrentMethods = 0;
 
         @Test
-        public void test1() throws InterruptedException {
-            synchronized (Class1.class) {
+        public void test1()
+            throws InterruptedException
+        {
+            synchronized ( Class1.class )
+            {
                 ++concurrentMethods;
-                Class1.class.wait(500);
-                maxConcurrentMethods = Math.max(maxConcurrentMethods, concurrentMethods--);
+                Class1.class.wait( 500 );
+                maxConcurrentMethods = Math.max( maxConcurrentMethods, concurrentMethods-- );
             }
         }
 
         @Test
-        public void test2() throws InterruptedException {
+        public void test2()
+            throws InterruptedException
+        {
             test1();
             Runnable shutdownTask = ParallelComputerBuilderTest.shutdownTask;
-            if (shutdownTask != null) {
+            if ( shutdownTask != null )
+            {
                 beforeShutdown = true;
                 shutdownTask.run();
             }
         }
     }
 
-    public static class Class2 extends Class1 {
-    }
-
-    public static class Class3 extends Class1 {
+    public static class Class2
+        extends Class1
+    {
     }
 
-    @RunWith(Suite.class)
-    @Suite.SuiteClasses({Class2.class, Class1.class})
-    public class TestSuite {
+    public static class Class3
+        extends Class1
+    {
     }
 
-    public static class NothingDoingTest1 {
+    public static class NothingDoingTest1
+    {
         static final Collection<String> methods = new ConcurrentLinkedQueue<String>();
 
         @BeforeClass
-        public static void init() {
-            methods.add("init");
+        public static void init()
+        {
+            methods.add( "init" );
         }
 
-        @Test
-        public void a() throws InterruptedException {
-            Thread.sleep(5);
-            methods.add(getClass().getName() + "#a()");
+        @AfterClass
+        public static void deinit()
+        {
+            methods.add( "deinit" );
         }
 
         @Test
-        public void b() throws InterruptedException {
-            Thread.sleep(5);
-            methods.add(getClass().getName() + "#b()");
+        public void a()
+            throws InterruptedException
+        {
+            Thread.sleep( 5 );
+            methods.add( getClass().getName() + "#a()" );
         }
 
-        @AfterClass
-        public static void deinit() {
-            methods.add("deinit");
+        @Test
+        public void b()
+            throws InterruptedException
+        {
+            Thread.sleep( 5 );
+            methods.add( getClass().getName() + "#b()" );
         }
     }
 
-    public static class NothingDoingTest2 extends NothingDoingTest1 {
+    public static class NothingDoingTest2
+        extends NothingDoingTest1
+    {
     }
 
-    public static class NothingDoingTest3 extends NothingDoingTest1 {
+    public static class NothingDoingTest3
+        extends NothingDoingTest1
+    {
     }
 
-    @RunWith(Suite.class)
-    @Suite.SuiteClasses({NothingDoingTest1.class, NothingDoingTest2.class})
-    public static class NothingDoingSuite {
+    @RunWith( Suite.class )
+    @Suite.SuiteClasses( { NothingDoingTest1.class, NothingDoingTest2.class } )
+    public static class NothingDoingSuite
+    {
+    }
+
+    @RunWith( Suite.class )
+    @Suite.SuiteClasses( { Class2.class, Class1.class } )
+    public class TestSuite
+    {
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/RangeMatcher.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/RangeMatcher.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/RangeMatcher.java
index ad04d6b..a71d853 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/RangeMatcher.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/RangeMatcher.java
@@ -27,9 +27,11 @@ import org.hamcrest.Matcher;
  * @author Tibor Digana (tibor17)
  * @since 2.16
  */
-final class RangeMatcher extends BaseMatcher<Long>
+final class RangeMatcher
+    extends BaseMatcher<Long>
 {
     private final long from;
+
     private final long to;
 
     private RangeMatcher( long from, long to )
@@ -38,14 +40,14 @@ final class RangeMatcher extends BaseMatcher<Long>
         this.to = to;
     }
 
-    public void describeTo( Description description )
+    public static Matcher<Long> between( long from, long to )
     {
-        description.appendValueList( "between ", " and ", "", from, to );
+        return new RangeMatcher( from, to );
     }
 
-    public static Matcher<Long> between( long from, long to )
+    public void describeTo( Description description )
     {
-        return new RangeMatcher( from, to );
+        description.appendValueList( "between ", " and ", "", from, to );
     }
 
     public boolean matches( Object o )

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategiesTest.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategiesTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategiesTest.java
index 485b63c..d8d5d33 100644
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategiesTest.java
+++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/SchedulingStrategiesTest.java
@@ -29,7 +29,7 @@ import static org.junit.Assert.assertTrue;
 
 /**
  * Tests the factories in SchedulingStrategy.
- *
+ * <p/>
  * Th point of these tests is to check {@link Task#result} if changed
  * from <code>false</code> to <code>true</code> after all scheduled tasks
  * have finished.
@@ -38,118 +38,130 @@ import static org.junit.Assert.assertTrue;
  * Then {@link Task#result} should be asserted that is <code>true</code>.
  *
  * @author Tibor Digana (tibor17)
- * @since 2.16
- *
  * @see SchedulingStrategy
+ * @since 2.16
  */
-public class SchedulingStrategiesTest {
-    static class Task implements Runnable {
-        volatile boolean result = false;
-
-        public void run() {
-            result = true;
-        }
-    }
-
+public class SchedulingStrategiesTest
+{
     @Test
-    public void invokerStrategy() throws InterruptedException {
+    public void invokerStrategy()
+        throws InterruptedException
+    {
         SchedulingStrategy strategy = SchedulingStrategies.createInvokerStrategy();
-        assertFalse(strategy.hasSharedThreadPool());
-        assertTrue(strategy.canSchedule());
+        assertFalse( strategy.hasSharedThreadPool() );
+        assertTrue( strategy.canSchedule() );
 
         Task task = new Task();
 
-        strategy.schedule(task);
+        strategy.schedule( task );
 
-        assertTrue(strategy.canSchedule());
+        assertTrue( strategy.canSchedule() );
 
-        assertTrue(task.result);
+        assertTrue( task.result );
 
-        assertTrue(strategy.finished());
-        assertFalse(strategy.canSchedule());
+        assertTrue( strategy.finished() );
+        assertFalse( strategy.canSchedule() );
     }
 
     @Test
-    public void nonSharedPoolStrategy() throws InterruptedException {
-        SchedulingStrategy strategy = SchedulingStrategies.createParallelStrategy(2);
-        assertFalse(strategy.hasSharedThreadPool());
-        assertTrue(strategy.canSchedule());
+    public void nonSharedPoolStrategy()
+        throws InterruptedException
+    {
+        SchedulingStrategy strategy = SchedulingStrategies.createParallelStrategy( 2 );
+        assertFalse( strategy.hasSharedThreadPool() );
+        assertTrue( strategy.canSchedule() );
 
         Task task1 = new Task();
         Task task2 = new Task();
 
-        strategy.schedule(task1);
-        strategy.schedule(task2);
+        strategy.schedule( task1 );
+        strategy.schedule( task2 );
 
-        assertTrue(strategy.canSchedule());
+        assertTrue( strategy.canSchedule() );
 
-        assertTrue(strategy.finished());
-        assertFalse(strategy.canSchedule());
+        assertTrue( strategy.finished() );
+        assertFalse( strategy.canSchedule() );
 
-        assertTrue(task1.result);
-        assertTrue(task2.result);
+        assertTrue( task1.result );
+        assertTrue( task2.result );
     }
 
     @Test(expected = NullPointerException.class)
-    public void sharedPoolStrategyNullPool() {
-        SchedulingStrategies.createParallelSharedStrategy(null);
+    public void sharedPoolStrategyNullPool()
+    {
+        SchedulingStrategies.createParallelSharedStrategy( null );
     }
 
     @Test
-    public void sharedPoolStrategy() throws InterruptedException {
+    public void sharedPoolStrategy()
+        throws InterruptedException
+    {
         ExecutorService sharedPool = Executors.newCachedThreadPool();
 
-        SchedulingStrategy strategy1 = SchedulingStrategies.createParallelSharedStrategy(sharedPool);
-        assertTrue(strategy1.hasSharedThreadPool());
-        assertTrue(strategy1.canSchedule());
+        SchedulingStrategy strategy1 = SchedulingStrategies.createParallelSharedStrategy( sharedPool );
+        assertTrue( strategy1.hasSharedThreadPool() );
+        assertTrue( strategy1.canSchedule() );
 
-        SchedulingStrategy strategy2 = SchedulingStrategies.createParallelSharedStrategy(sharedPool);
-        assertTrue(strategy2.hasSharedThreadPool());
-        assertTrue(strategy2.canSchedule());
+        SchedulingStrategy strategy2 = SchedulingStrategies.createParallelSharedStrategy( sharedPool );
+        assertTrue( strategy2.hasSharedThreadPool() );
+        assertTrue( strategy2.canSchedule() );
 
         Task task1 = new Task();
         Task task2 = new Task();
         Task task3 = new Task();
         Task task4 = new Task();
 
-        strategy1.schedule(task1);
-        strategy2.schedule(task2);
-        strategy1.schedule(task3);
-        strategy2.schedule(task4);
+        strategy1.schedule( task1 );
+        strategy2.schedule( task2 );
+        strategy1.schedule( task3 );
+        strategy2.schedule( task4 );
 
-        assertTrue(strategy1.canSchedule());
-        assertTrue(strategy2.canSchedule());
+        assertTrue( strategy1.canSchedule() );
+        assertTrue( strategy2.canSchedule() );
 
-        assertTrue(strategy1.finished());
-        assertFalse(strategy1.canSchedule());
+        assertTrue( strategy1.finished() );
+        assertFalse( strategy1.canSchedule() );
 
-        assertTrue(strategy2.finished());
-        assertFalse(strategy2.canSchedule());
+        assertTrue( strategy2.finished() );
+        assertFalse( strategy2.canSchedule() );
 
-        assertTrue(task1.result);
-        assertTrue(task2.result);
-        assertTrue(task3.result);
-        assertTrue(task4.result);
+        assertTrue( task1.result );
+        assertTrue( task2.result );
+        assertTrue( task3.result );
+        assertTrue( task4.result );
     }
 
     @Test
-    public void infinitePoolStrategy() throws InterruptedException {
+    public void infinitePoolStrategy()
+        throws InterruptedException
+    {
         SchedulingStrategy strategy = SchedulingStrategies.createParallelStrategyUnbounded();
-        assertFalse(strategy.hasSharedThreadPool());
-        assertTrue(strategy.canSchedule());
+        assertFalse( strategy.hasSharedThreadPool() );
+        assertTrue( strategy.canSchedule() );
 
         Task task1 = new Task();
         Task task2 = new Task();
 
-        strategy.schedule(task1);
-        strategy.schedule(task2);
+        strategy.schedule( task1 );
+        strategy.schedule( task2 );
+
+        assertTrue( strategy.canSchedule() );
+
+        assertTrue( strategy.finished() );
+        assertFalse( strategy.canSchedule() );
 
-        assertTrue(strategy.canSchedule());
+        assertTrue( task1.result );
+        assertTrue( task2.result );
+    }
 
-        assertTrue(strategy.finished());
-        assertFalse(strategy.canSchedule());
+    static class Task
+        implements Runnable
+    {
+        volatile boolean result = false;
 
-        assertTrue(task1.result);
-        assertTrue(task2.result);
+        public void run()
+        {
+            result = true;
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/a9d511a0/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
----------------------------------------------------------------------
diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
deleted file mode 100644
index 32b056c..0000000
--- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/pc/Stopwatch.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.maven.surefire.junitcore.pc;
-
-/*
- * 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.
- */
-
-import org.junit.rules.TestWatchman;
-import org.junit.runners.model.FrameworkMethod;
-
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Tibor Digana (tibor17)
- * @since 2.16
- */
-final class Stopwatch extends TestWatchman
-{
-    private long startNanos;
-
-    long stop()
-    {
-        return TimeUnit.MILLISECONDS.convert(System.nanoTime() - startNanos, TimeUnit.NANOSECONDS);
-    }
-
-    @Override
-    public void starting(FrameworkMethod method)
-    {
-        startNanos = System.nanoTime();
-    }
-}


Mime
View raw message