Updated Branches: refs/heads/master 318f8a9a4 -> ab0cc7a84
o Simplified concurrent code to try to isolate intermittent problem Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/ab0cc7a8 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/ab0cc7a8 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/ab0cc7a8 Branch: refs/heads/master Commit: ab0cc7a8477d2c8428882e58153c4486f8a23eb9 Parents: 318f8a9 Author: Kristian Rosenvold <krosenv...@apache.org> Authored: Mon Dec 17 17:22:48 2012 +0100 Committer: Kristian Rosenvold <krosenv...@apache.org> Committed: Mon Dec 17 17:26:14 2012 +0100 ---------------------------------------------------------------------- .../junitcore/ConcurrentReporterManager.java | 55 +++++++-------- .../maven/surefire/junitcore/TestMethod.java | 11 +++- .../apache/maven/surefire/junitcore/TestSet.java | 5 +- .../maven/surefire/junitcore/TestMethodTest.java | 4 +- 4 files changed, 41 insertions(+), 34 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ab0cc7a8/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java index 777f50b..69367f5 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java @@ -42,7 +42,7 @@ public abstract class ConcurrentReporterManager { private final Map<String, TestSet> classMethodCounts; - private final ThreadLocal<RunListener> reporterManagerThreadLocal = new ThreadLocal<RunListener>(); + private final ThreadLocal<RunListener> reporterManagerThreadLocal; // = new ThreadLocal<RunListener>(); private final boolean reportImmediately; @@ -58,6 +58,15 @@ public abstract class ConcurrentReporterManager this.reporterFactory = reporterFactory; this.classMethodCounts = classMethodCounts; this.consoleLogger = consoleLogger; + + this.reporterManagerThreadLocal = new ThreadLocal<RunListener>() + { + @Override + protected RunListener initialValue() + { + return ConcurrentReporterManager.this.reporterFactory.createReporter(); + } + }; } public void testSetStarting( ReportEntry description ) @@ -71,54 +80,52 @@ public abstract class ConcurrentReporterManager { testSet.replay( reporterManager ); } - detachTestMethodFromThread(); reporterManagerThreadLocal.remove(); } public void testFailed( ReportEntry failure ) { - final TestMethod testMethod = getOrCreateTestMethod( failure ); + final TestMethod testMethod = getOrCreateThreadAttachedTestMethod( failure ); if ( testMethod != null ) { testMethod.testFailure( failure ); + testMethod.detachFromCurrentThread(); } - detachTestMethodFromThread(); } public void testError( ReportEntry failure ) { - final TestMethod testMethod = getOrCreateTestMethod( failure ); + final TestMethod testMethod = getOrCreateThreadAttachedTestMethod( failure ); if ( testMethod != null ) { testMethod.testError( failure ); + testMethod.detachFromCurrentThread(); } - detachTestMethodFromThread(); } public void testSkipped( ReportEntry description ) { TestSet testSet = getTestSet( description ); - TestMethod testMethod = getTestSet( description ).createTestMethod( description ); + TestMethod testMethod = testSet.createThreadAttachedTestMethod( description ); testMethod.testIgnored( description ); testSet.incrementFinishedTests( getRunListener(), reportImmediately ); - detachTestMethodFromThread(); + testMethod.detachFromCurrentThread(); } public void testAssumptionFailure( ReportEntry failure ) { - final TestMethod testMethod = getOrCreateTestMethod( failure ); + final TestMethod testMethod = getOrCreateThreadAttachedTestMethod( failure ); if ( testMethod != null ) { testMethod.testIgnored( failure ); + testMethod.detachFromCurrentThread(); } - detachTestMethodFromThread(); } public void testStarting( ReportEntry description ) { TestSet testSet = getTestSet( description ); - final TestMethod testMethod = testSet.createTestMethod( description ); - testMethod.attachToThread(); + testSet.createThreadAttachedTestMethod( description ); checkIfTestSetCanBeReported( testSet ); testSet.attachToThread(); @@ -126,12 +133,13 @@ public abstract class ConcurrentReporterManager public void testSucceeded( ReportEntry report ) { - getTestMethod().testFinished(); - TestSet.getThreadTestSet().incrementFinishedTests( getRunListener(), reportImmediately ); - detachTestMethodFromThread(); + TestMethod testMethod = getTestMethod(); + testMethod.testFinished(); + testMethod.getTestSet().incrementFinishedTests( getRunListener(), reportImmediately ); + testMethod.detachFromCurrentThread(); } - private TestMethod getOrCreateTestMethod( ReportEntry description ) + private TestMethod getOrCreateThreadAttachedTestMethod( ReportEntry description ) { TestMethod threadTestMethod = TestMethod.getThreadTestMethod(); if ( threadTestMethod != null ) @@ -147,7 +155,7 @@ public abstract class ConcurrentReporterManager } else { - return testSet.createTestMethod( description ); + return testSet.createThreadAttachedTestMethod( description ); } } @@ -158,11 +166,6 @@ public abstract class ConcurrentReporterManager return TestMethod.getThreadTestMethod(); } - void detachTestMethodFromThread() - { - TestMethod.detachFromCurrentThread(); - } - TestSet getTestSet( ReportEntry description ) { return classMethodCounts.get( description.getSourceName() ); @@ -170,13 +173,7 @@ public abstract class ConcurrentReporterManager RunListener getRunListener() { - RunListener runListener = reporterManagerThreadLocal.get(); - if ( runListener == null ) - { - runListener = reporterFactory.createReporter(); - reporterManagerThreadLocal.set( runListener ); - } - return runListener; + return reporterManagerThreadLocal.get(); } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ab0cc7a8/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java index 3ade771..041db34 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java @@ -36,6 +36,8 @@ class TestMethod { private final ReportEntry description; + private final TestSet testSet; + private final long startTime; private long endTime; @@ -50,9 +52,10 @@ class TestMethod private volatile LogicalStream output; - public TestMethod( ReportEntry description ) + public TestMethod( ReportEntry description, TestSet testSet ) { this.description = description; + this.testSet = testSet; startTime = System.currentTimeMillis(); } @@ -133,7 +136,7 @@ class TestMethod } - public static void detachFromCurrentThread() + public void detachFromCurrentThread() { TEST_METHOD.remove(); ConsoleOutputReceiverForCurrentThread.remove(); @@ -158,4 +161,8 @@ class TestMethod getLogicalStream().write( stdout, buf, off, len ); } + public TestSet getTestSet() + { + return testSet; + } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ab0cc7a8/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java index 33f36ed..462fe12 100644 --- a/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java +++ b/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestSet.java @@ -105,10 +105,11 @@ public class TestSet } } - public TestMethod createTestMethod( ReportEntry description ) + public TestMethod createThreadAttachedTestMethod( ReportEntry description ) { - TestMethod testMethod = new TestMethod( description ); + TestMethod testMethod = new TestMethod( description, this ); addTestMethod( testMethod ); + testMethod.attachToThread(); return testMethod; } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ab0cc7a8/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestMethodTest.java ---------------------------------------------------------------------- diff --git a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestMethodTest.java b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestMethodTest.java index a1b549f..efb40b3 100644 --- a/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestMethodTest.java +++ b/surefire-providers/surefire-junit47/src/test/java/org/apache/maven/surefire/junitcore/TestMethodTest.java @@ -23,6 +23,7 @@ import org.apache.maven.surefire.report.ReportEntry; import org.apache.maven.surefire.report.SimpleReportEntry; import junit.framework.TestCase; +import org.junit.runner.Description; /** * @author Kristian Rosenvold @@ -34,7 +35,8 @@ public class TestMethodTest throws Exception { ReportEntry reportEntry = new SimpleReportEntry( "a", "b" ); - TestMethod testMethod = new TestMethod( reportEntry ); + TestMethod testMethod = new TestMethod( reportEntry, new TestSet( + Description.createTestDescription( TestMethodTest.class, "testeEthodTest" ) ) ); testMethod.testFailure( reportEntry ); final int elapsed = testMethod.getElapsed(); assertTrue( elapsed >= 0 );