You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2018/09/10 00:37:06 UTC
[maven-surefire] 03/06: collection with TestMethodStats should be
thread safe
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch BUILDFIX
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 3476122b97552d1ffb53b58a864a3b1470e64c33
Author: Tibor17 <ti...@apache.org>
AuthorDate: Mon Sep 10 01:50:10 2018 +0200
collection with TestMethodStats should be thread safe
---
.../surefire/report/DefaultReporterFactory.java | 3 +-
.../plugin/surefire/report/TestSetRunListener.java | 38 +++++++++-------------
.../report/DefaultReporterFactoryTest.java | 8 +++--
3 files changed, 22 insertions(+), 27 deletions(-)
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
index 15b4306..f64ac42 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
@@ -275,8 +275,7 @@ public class DefaultReporterFactory
// Merge all the stats for tests from listeners
for ( TestSetRunListener listener : listeners )
{
- List<TestMethodStats> testMethodStats = listener.getTestMethodStats();
- for ( TestMethodStats methodStats : testMethodStats )
+ for ( TestMethodStats methodStats : listener.getTestMethodStats() )
{
List<TestMethodStats> currentMethodStats =
mergedTestHistoryResult.get( methodStats.getTestClassMethodName() );
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
index 1ed32f9..59d36f2 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/TestSetRunListener.java
@@ -20,9 +20,10 @@ package org.apache.maven.plugin.surefire.report;
*/
import java.io.IOException;
-import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.runorder.StatisticsReporter;
@@ -45,18 +46,9 @@ import static org.apache.maven.plugin.surefire.report.ReportEntryType.SUCCESS;
public class TestSetRunListener
implements RunListener, ConsoleOutputReceiver, ConsoleLogger
{
- private final TestSetStats detailsForThis;
-
- private List<TestMethodStats> testMethodStats;
+ private final Queue<TestMethodStats> testMethodStats = new ConcurrentLinkedQueue<TestMethodStats>();
- private Utf8RecodingDeferredFileOutputStream testStdOut = initDeferred( "stdout" );
-
- private Utf8RecodingDeferredFileOutputStream testStdErr = initDeferred( "stderr" );
-
- private Utf8RecodingDeferredFileOutputStream initDeferred( String channel )
- {
- return new Utf8RecodingDeferredFileOutputStream( channel );
- }
+ private final TestSetStats detailsForThis;
private final TestcycleConsoleOutputReceiver consoleOutputReceiver;
@@ -70,6 +62,10 @@ public class TestSetRunListener
private final StatisticsReporter statisticsReporter;
+ private Utf8RecodingDeferredFileOutputStream testStdOut = initDeferred( "stdout" );
+
+ private Utf8RecodingDeferredFileOutputStream testStdErr = initDeferred( "stderr" );
+
@SuppressWarnings( "checkstyle:parameternumber" )
public TestSetRunListener( ConsoleReporter consoleReporter, FileReporter fileReporter,
StatelessXmlReporter simpleXMLReporter,
@@ -84,7 +80,6 @@ public class TestSetRunListener
this.consoleOutputReceiver = consoleOutputReceiver;
this.briefOrPlainFormat = briefOrPlainFormat;
detailsForThis = new TestSetStats( trimStackTrace, isPlainFormat );
- testMethodStats = new ArrayList<TestMethodStats>();
}
@Override
@@ -152,14 +147,8 @@ public class TestSetRunListener
{
try
{
- if ( stdout )
- {
- testStdOut.write( buf, off, len );
- }
- else
- {
- testStdErr.write( buf, off, len );
- }
+ Utf8RecodingDeferredFileOutputStream os = stdout ? testStdOut : testStdErr;
+ os.write( buf, off, len );
consoleOutputReceiver.writeTestOutput( buf, off, len, stdout );
}
catch ( IOException e )
@@ -299,7 +288,7 @@ public class TestSetRunListener
}
}
- public List<TestMethodStats> getTestMethodStats()
+ public Queue<TestMethodStats> getTestMethodStats()
{
return testMethodStats;
}
@@ -314,4 +303,9 @@ public class TestSetRunListener
{
return message.endsWith( "\n" ) || message.endsWith( "\r" ) ? 1 : ( message.endsWith( "\r\n" ) ? 2 : 0 );
}
+
+ private static Utf8RecodingDeferredFileOutputStream initDeferred( String channel )
+ {
+ return new Utf8RecodingDeferredFileOutputStream( channel );
+ }
}
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
index 87d6800..dc992fe 100644
--- a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactoryTest.java
@@ -20,8 +20,10 @@ package org.apache.maven.plugin.surefire.report;
*/
import java.io.File;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.List;
+import java.util.Queue;
import junit.framework.TestCase;
@@ -73,7 +75,7 @@ public class DefaultReporterFactoryTest
DefaultReporterFactory factory = new DefaultReporterFactory( reportConfig, reporter );
// First run, four tests failed and one passed
- List<TestMethodStats> firstRunStats = new ArrayList<TestMethodStats>();
+ Queue<TestMethodStats> firstRunStats = new ArrayDeque<TestMethodStats>();
firstRunStats.add( new TestMethodStats( TEST_ONE, ReportEntryType.ERROR, new DummyStackTraceWriter( ERROR ) ) );
firstRunStats.add( new TestMethodStats( TEST_TWO, ReportEntryType.ERROR, new DummyStackTraceWriter( ERROR ) ) );
firstRunStats.add(
@@ -84,7 +86,7 @@ public class DefaultReporterFactoryTest
new TestMethodStats( TEST_FIVE, ReportEntryType.SUCCESS, null ) );
// Second run, two tests passed
- List<TestMethodStats> secondRunStats = new ArrayList<TestMethodStats>();
+ Queue<TestMethodStats> secondRunStats = new ArrayDeque<TestMethodStats>();
secondRunStats.add(
new TestMethodStats( TEST_ONE, ReportEntryType.FAILURE, new DummyStackTraceWriter( ASSERTION_FAIL ) ) );
secondRunStats.add( new TestMethodStats( TEST_TWO, ReportEntryType.SUCCESS, null ) );
@@ -93,7 +95,7 @@ public class DefaultReporterFactoryTest
secondRunStats.add( new TestMethodStats( TEST_FOUR, ReportEntryType.SUCCESS, null ) );
// Third run, another test passed
- List<TestMethodStats> thirdRunStats = new ArrayList<TestMethodStats>();
+ Queue<TestMethodStats> thirdRunStats = new ArrayDeque<TestMethodStats>();
thirdRunStats.add( new TestMethodStats( TEST_ONE, ReportEntryType.SUCCESS, null ) );
thirdRunStats.add(
new TestMethodStats( TEST_THREE, ReportEntryType.ERROR, new DummyStackTraceWriter( ERROR ) ) );