Updated Branches: refs/heads/master 38f1c75f9 -> 435ef473b
[SUREFIRE-933] repair parallel=classes Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/435ef473 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/435ef473 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/435ef473 Branch: refs/heads/master Commit: 435ef473be35f69dbb0c3187ecf7b54e3f87f49a Parents: 38f1c75 Author: agudian <andreas.gud...@gmail.com> Authored: Sat Dec 15 21:42:09 2012 +0100 Committer: Kristian Rosenvold <krosenv...@apache.org> Committed: Sun Dec 16 17:55:00 2012 +0100 ---------------------------------------------------------------------- .../apache/maven/surefire/util/LazyTestsToRun.java | 7 ++ .../org/apache/maven/surefire/util/TestsToRun.java | 9 ++ .../maven/surefire/junitcore/JUnitCoreWrapper.java | 79 +++++++++------ .../surefire/testng/TestNGDirectoryTestSuite.java | 2 +- 4 files changed, 67 insertions(+), 30 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/435ef473/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java index 3a6dba7..996797c 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/LazyTestsToRun.java @@ -173,4 +173,11 @@ public class LazyTestsToRun return sb.toString(); } + /* (non-Javadoc) + * @see org.apache.maven.surefire.util.TestsToRun#allowEagerReading() + */ + public boolean allowEagerReading() { + return false; + } + } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/435ef473/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java b/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java index 86e43d9..02224ab 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/util/TestsToRun.java @@ -116,4 +116,13 @@ public class TestsToRun return containsAtLeast( it, items ) && !it.hasNext(); } + /** + * @return {@code true}, if the classes may be read eagerly. {@code false}, + * if the classes must only be read lazy. + */ + public boolean allowEagerReading() + { + return true; + } + } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/435ef473/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java index 0608ab4..c834e6f 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/JUnitCoreWrapper.java @@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitcore; * under the License. */ +import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.ExecutionException; @@ -26,7 +27,6 @@ import java.util.concurrent.ExecutionException; import org.apache.maven.surefire.common.junit4.JUnit4RunListener; import org.apache.maven.surefire.testset.TestSetFailedException; import org.apache.maven.surefire.util.TestsToRun; - import org.junit.runner.Computer; import org.junit.runner.JUnitCore; import org.junit.runner.Request; @@ -77,39 +77,18 @@ class JUnitCoreWrapper Computer computer = getComputer( jUnitCoreParameters ); JUnitCore junitCore = createJUnitCore( listeners ); - /* - Request req = Request.classes( computer, testsToRun.getLocatedClasses() ); - if ( filter != null ) - { - req = req.filterWith( filter ); - } - - try - { - final Result run = junitCore.run( req ); - JUnit4RunListener.rethrowAnyTestMechanismFailures( run ); - } - */ try { - // in order to support LazyTestsToRun, the iterator must be used - Iterator classIter = testsToRun.iterator(); - while ( classIter.hasNext() ) + if ( testsToRun.allowEagerReading() ) { - Request req = Request.classes( computer, new Class[]{ (Class) classIter.next() } ); - if ( filter != null ) - { - req = new FilteringRequest( req, filter ); - if ( req.getRunner() == null ) - { - continue; - } - } - - final Result run = junitCore.run( req ); - JUnit4RunListener.rethrowAnyTestMechanismFailures( run ); + executeEager( testsToRun, filter, computer, junitCore ); } + else + { + exeuteLazy( testsToRun, filter, computer, junitCore ); + } + } finally { @@ -121,6 +100,48 @@ class JUnitCoreWrapper } } + private static void executeEager(TestsToRun testsToRun, Filter filter, Computer computer, JUnitCore junitCore) + throws TestSetFailedException + { + List<Class<?>> testList = new ArrayList<Class<?>>(500); + Iterator<?> classIter = testsToRun.iterator(); + + while ( classIter.hasNext() ) + { + testList.add((Class<?>) classIter.next()); + } + createReqestAndRun( filter, computer, junitCore, testList.toArray( new Class[ testList.size() ] ) ); + } + + private static void exeuteLazy(TestsToRun testsToRun, Filter filter, Computer computer, JUnitCore junitCore) + throws TestSetFailedException + { + // in order to support LazyTestsToRun, the iterator must be used + Iterator<?> classIter = testsToRun.iterator(); + while ( classIter.hasNext() ) + { + createReqestAndRun( filter, computer, junitCore, new Class[]{ (Class<?>) classIter.next() } ); + } + } + + private static void createReqestAndRun( Filter filter, Computer computer, JUnitCore junitCore, Class<?>[] classesToRun ) + throws TestSetFailedException + { + Request req = Request.classes( computer, classesToRun ); + if ( filter != null ) + { + req = new FilteringRequest( req, filter ); + if ( req.getRunner() == null ) + { + // nothing to run + return; + } + } + + final Result run = junitCore.run( req ); + JUnit4RunListener.rethrowAnyTestMechanismFailures( run ); + } + private static void closeIfConfigurable( Computer computer ) throws TestSetFailedException { http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/435ef473/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java index f4fc9f9..d04e77c 100644 --- a/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java +++ b/surefire-providers/surefire-testng/src/main/java/org/apache/maven/surefire/testng/TestNGDirectoryTestSuite.java @@ -96,7 +96,7 @@ public class TestNGDirectoryTestSuite throws ReporterException, TestSetFailedException { - if ( testsToRun instanceof LazyTestsToRun ) + if ( !testsToRun.allowEagerReading() ) { executeLazy( testsToRun, reporterManagerFactory ); }