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 2016/05/29 21:59:50 UTC
maven-surefire git commit: refactoring with static imports + multiple
threads memory visibility
Repository: maven-surefire
Updated Branches:
refs/heads/master b1913455d -> 0cbebc9b4
refactoring with static imports + multiple threads memory visibility
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/0cbebc9b
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/0cbebc9b
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/0cbebc9b
Branch: refs/heads/master
Commit: 0cbebc9b45df10134bc49739f6b872b99bb0a9f2
Parents: b191345
Author: Tibor17 <ti...@lycos.com>
Authored: Sun May 29 23:59:44 2016 +0200
Committer: Tibor17 <ti...@lycos.com>
Committed: Sun May 29 23:59:44 2016 +0200
----------------------------------------------------------------------
.../surefire/booterclient/ForkStarter.java | 19 +++---
.../booterclient/output/ForkClient.java | 61 +++++++++++++-------
.../surefire/report/DefaultReporterFactory.java | 3 +-
.../surefire/runorder/StatisticsReporter.java | 6 +-
.../runorder/RunEntryStatisticsMap.java | 21 ++++---
5 files changed, 66 insertions(+), 44 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0cbebc9b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
index d43dd62..6d7fdb3 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
@@ -33,7 +33,6 @@ import org.apache.maven.plugin.surefire.booterclient.output.ThreadedStreamConsum
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
import org.apache.maven.shared.utils.cli.CommandLineCallable;
import org.apache.maven.shared.utils.cli.CommandLineException;
-import org.apache.maven.shared.utils.cli.ShutdownHookUtils;
import org.apache.maven.surefire.booter.Classpath;
import org.apache.maven.surefire.booter.ClasspathConfiguration;
import org.apache.maven.surefire.booter.KeyValueSource;
@@ -56,7 +55,6 @@ import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Queue;
@@ -80,6 +78,8 @@ import static java.lang.StrictMath.min;
import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.maven.plugin.surefire.AbstractSurefireMojo.createCopyAndReplaceForkNumPlaceholder;
+import static org.apache.maven.plugin.surefire.booterclient.ForkNumberBucket.drawNumber;
+import static org.apache.maven.plugin.surefire.booterclient.ForkNumberBucket.returnNumber;
import static org.apache.maven.plugin.surefire.booterclient.lazytestprovider.TestLessInputStream
.TestLessInputStreamBuilder;
import static org.apache.maven.shared.utils.cli.CommandLineUtils.executeCommandLineAsCallable;
@@ -151,14 +151,13 @@ public class ForkStarter
private static class CloseableCloser
implements Runnable, Closeable
{
- private final List<AtomicReference<Closeable>> testProvidingInputStream;
+ private final Queue<AtomicReference<Closeable>> testProvidingInputStream;
private final Thread inputStreamCloserHook;
public CloseableCloser( Closeable... testProvidingInputStream )
{
-
- this.testProvidingInputStream = new ArrayList<AtomicReference<Closeable>>();
+ this.testProvidingInputStream = new ConcurrentLinkedQueue<AtomicReference<Closeable>>();
for ( Closeable closeable : testProvidingInputStream )
{
if ( closeable != null )
@@ -166,10 +165,10 @@ public class ForkStarter
this.testProvidingInputStream.add( new AtomicReference<Closeable>( closeable ) );
}
}
- if ( this.testProvidingInputStream.size() > 0 )
+ if ( !this.testProvidingInputStream.isEmpty() )
{
inputStreamCloserHook = newDaemonThread( this, "closer-shutdown-hook" );
- ShutdownHookUtils.addShutDownHook( inputStreamCloserHook );
+ addShutDownHook( inputStreamCloserHook );
}
else
{
@@ -202,7 +201,7 @@ public class ForkStarter
run();
if ( inputStreamCloserHook != null )
{
- ShutdownHookUtils.removeShutdownHook( inputStreamCloserHook );
+ removeShutdownHook( inputStreamCloserHook );
}
}
}
@@ -488,7 +487,7 @@ public class ForkStarter
AbstractForkInputStream testProvidingInputStream, boolean readTestsFromInStream )
throws SurefireBooterForkException
{
- int forkNumber = ForkNumberBucket.drawNumber();
+ int forkNumber = drawNumber();
try
{
return fork( testSet, providerProperties, forkClient, effectiveSystemProperties, forkNumber,
@@ -496,7 +495,7 @@ public class ForkStarter
}
finally
{
- ForkNumberBucket.returnNumber( forkNumber );
+ returnNumber( forkNumber );
}
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0cbebc9b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
index 6b0794f..1a06c98 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ForkClient.java
@@ -33,7 +33,6 @@ import java.util.concurrent.atomic.AtomicLong;
import org.apache.maven.plugin.surefire.booterclient.lazytestprovider.NotifiableTestStream;
import org.apache.maven.plugin.surefire.report.DefaultReporterFactory;
import org.apache.maven.shared.utils.cli.StreamConsumer;
-import org.apache.maven.surefire.booter.ForkingRunListener;
import org.apache.maven.surefire.report.CategorizedReportEntry;
import org.apache.maven.surefire.report.ConsoleLogger;
import org.apache.maven.surefire.report.ConsoleOutputReceiver;
@@ -43,7 +42,25 @@ import org.apache.maven.surefire.report.RunListener;
import org.apache.maven.surefire.report.StackTraceWriter;
import org.apache.maven.surefire.util.internal.StringUtils;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_BYE;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_CONSOLE;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_ERROR;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_NEXT_TEST;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_STDERR;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_STDOUT;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_STOP_ON_NEXT_TEST;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_SYSPROPS;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_ASSUMPTIONFAILURE;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_ERROR;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_FAILED;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_SKIPPED;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_STARTING;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TEST_SUCCEEDED;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TESTSET_COMPLETED;
+import static org.apache.maven.surefire.booter.ForkingRunListener.BOOTERCODE_TESTSET_STARTING;
import static org.apache.maven.surefire.booter.Shutdown.KILL;
+import static org.apache.maven.surefire.util.internal.StringUtils.unescapeBytes;
+import static org.apache.maven.surefire.util.internal.StringUtils.unescapeString;
/**
* Knows how to reconstruct *all* the state transmitted over stdout by the forked process.
@@ -66,7 +83,7 @@ public class ForkClient
/**
* <t>testSetStartedAt</t> is set to non-zero after received
- * {@link ForkingRunListener#BOOTERCODE_TESTSET_STARTING test-set}.
+ * {@link org.apache.maven.surefire.booter.ForkingRunListener#BOOTERCODE_TESTSET_STARTING test-set}.
*/
private final AtomicLong testSetStartedAt = new AtomicLong( START_TIME_ZERO );
@@ -148,62 +165,62 @@ public class ForkClient
switch ( operationId )
{
- case ForkingRunListener.BOOTERCODE_TESTSET_STARTING:
+ case BOOTERCODE_TESTSET_STARTING:
getOrCreateReporter( channelNumber ).testSetStarting( createReportEntry( remaining ) );
setCurrentStartTime();
break;
- case ForkingRunListener.BOOTERCODE_TESTSET_COMPLETED:
+ case BOOTERCODE_TESTSET_COMPLETED:
getOrCreateReporter( channelNumber ).testSetCompleted( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_STARTING:
+ case BOOTERCODE_TEST_STARTING:
getOrCreateReporter( channelNumber ).testStarting( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_SUCCEEDED:
+ case BOOTERCODE_TEST_SUCCEEDED:
getOrCreateReporter( channelNumber ).testSucceeded( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_FAILED:
+ case BOOTERCODE_TEST_FAILED:
getOrCreateReporter( channelNumber ).testFailed( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_SKIPPED:
+ case BOOTERCODE_TEST_SKIPPED:
getOrCreateReporter( channelNumber ).testSkipped( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_ERROR:
+ case BOOTERCODE_TEST_ERROR:
getOrCreateReporter( channelNumber ).testError( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_TEST_ASSUMPTIONFAILURE:
+ case BOOTERCODE_TEST_ASSUMPTIONFAILURE:
getOrCreateReporter( channelNumber ).testAssumptionFailure( createReportEntry( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_SYSPROPS:
+ case BOOTERCODE_SYSPROPS:
int keyEnd = remaining.indexOf( "," );
StringBuilder key = new StringBuilder();
StringBuilder value = new StringBuilder();
- StringUtils.unescapeString( key, remaining.substring( 0, keyEnd ) );
- StringUtils.unescapeString( value, remaining.substring( keyEnd + 1 ) );
+ unescapeString( key, remaining.substring( 0, keyEnd ) );
+ unescapeString( value, remaining.substring( keyEnd + 1 ) );
synchronized ( testVmSystemProperties )
{
testVmSystemProperties.put( key.toString(), value.toString() );
}
break;
- case ForkingRunListener.BOOTERCODE_STDOUT:
+ case BOOTERCODE_STDOUT:
writeTestOutput( channelNumber, remaining, true );
break;
- case ForkingRunListener.BOOTERCODE_STDERR:
+ case BOOTERCODE_STDERR:
writeTestOutput( channelNumber, remaining, false );
break;
- case ForkingRunListener.BOOTERCODE_CONSOLE:
+ case BOOTERCODE_CONSOLE:
getOrCreateConsoleLogger( channelNumber ).info( createConsoleMessage( remaining ) );
break;
- case ForkingRunListener.BOOTERCODE_NEXT_TEST:
+ case BOOTERCODE_NEXT_TEST:
notifiableTestStream.provideNewTest();
break;
- case ForkingRunListener.BOOTERCODE_ERROR:
+ case BOOTERCODE_ERROR:
errorInFork = deserializeStackTraceWriter( new StringTokenizer( remaining, "," ) );
break;
- case ForkingRunListener.BOOTERCODE_BYE:
+ case BOOTERCODE_BYE:
saidGoodBye = true;
break;
- case ForkingRunListener.BOOTERCODE_STOP_ON_NEXT_TEST:
+ case BOOTERCODE_STOP_ON_NEXT_TEST:
stopOnNextTest();
break;
default:
@@ -231,7 +248,7 @@ public class ForkClient
int csNameEnd = remaining.indexOf( ',' );
String charsetName = remaining.substring( 0, csNameEnd );
String byteEncoded = remaining.substring( csNameEnd + 1 );
- ByteBuffer unescaped = StringUtils.unescapeBytes( byteEncoded, charsetName );
+ ByteBuffer unescaped = unescapeBytes( byteEncoded, charsetName );
if ( unescaped.hasArray() )
{
@@ -305,7 +322,7 @@ public class ForkClient
private String unescape( String source )
{
StringBuilder stringBuffer = new StringBuilder( source.length() );
- StringUtils.unescapeString( stringBuffer, source );
+ unescapeString( stringBuffer, source );
return stringBuffer.toString();
}
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0cbebc9b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/DefaultReporterFactory.java
----------------------------------------------------------------------
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 0a4aa54..815e4c6 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
@@ -77,7 +77,8 @@ public class DefaultReporterFactory
new TestSetRunListener( reportConfiguration.instantiateConsoleReporter(),
reportConfiguration.instantiateFileReporter(),
reportConfiguration.instantiateStatelessXmlReporter(),
- reportConfiguration.instantiateConsoleOutputFileReporter(), statisticsReporter,
+ reportConfiguration.instantiateConsoleOutputFileReporter(),
+ statisticsReporter,
reportConfiguration.isTrimStackTrace(),
PLAIN.equals( reportConfiguration.getReportFormat() ),
reportConfiguration.isBriefOrPlainFormat() );
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0cbebc9b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
index 4451d1d..ca33d67 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/runorder/StatisticsReporter.java
@@ -23,6 +23,8 @@ import java.io.File;
import java.io.FileNotFoundException;
import org.apache.maven.surefire.report.ReportEntry;
+import static org.apache.maven.plugin.surefire.runorder.RunEntryStatisticsMap.fromFile;
+
/**
* @author Kristian Rosenvold
*/
@@ -37,8 +39,8 @@ public class StatisticsReporter
public StatisticsReporter( File dataFile )
{
this.dataFile = dataFile;
- this.existing = RunEntryStatisticsMap.fromFile( this.dataFile );
- this.newResults = new RunEntryStatisticsMap();
+ existing = fromFile( dataFile );
+ newResults = new RunEntryStatisticsMap();
}
public void testSetCompleted()
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/0cbebc9b/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
----------------------------------------------------------------------
diff --git a/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java b/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
index 9c110a5..caee1b1 100644
--- a/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
+++ b/surefire-api/src/main/java/org/apache/maven/plugin/surefire/runorder/RunEntryStatisticsMap.java
@@ -31,7 +31,6 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.io.Reader;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
@@ -40,6 +39,10 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
+import static java.util.Collections.sort;
+import static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromReportEntry;
+import static org.apache.maven.plugin.surefire.runorder.RunEntryStatistics.fromString;
+
/**
* @author Kristian Rosenvold
*/
@@ -49,7 +52,7 @@ public class RunEntryStatisticsMap
public RunEntryStatisticsMap( Map<String, RunEntryStatistics> runEntryStatistics )
{
- this.runEntryStatistics = Collections.synchronizedMap( runEntryStatistics );
+ this.runEntryStatistics = new ConcurrentHashMap<String, RunEntryStatistics>( runEntryStatistics );
}
public RunEntryStatisticsMap()
@@ -69,9 +72,9 @@ public class RunEntryStatisticsMap
{
throw new RuntimeException( e );
}
- catch ( IOException e1 )
+ catch ( IOException e )
{
- throw new RuntimeException( e1 );
+ throw new RuntimeException( e );
}
}
else
@@ -90,7 +93,7 @@ public class RunEntryStatisticsMap
{
if ( !line.startsWith( "#" ) )
{
- final RunEntryStatistics stats = RunEntryStatistics.fromString( line );
+ final RunEntryStatistics stats = fromString( line );
result.put( stats.getTestName(), stats );
}
line = bufferedReader.readLine();
@@ -106,7 +109,7 @@ public class RunEntryStatisticsMap
try
{
List<RunEntryStatistics> items = new ArrayList<RunEntryStatistics>( runEntryStatistics.values() );
- Collections.sort( items, new RunCountComparator() );
+ sort( items, new RunCountComparator() );
for ( RunEntryStatistics item : items )
{
printWriter.println( item.toString() );
@@ -121,7 +124,7 @@ public class RunEntryStatisticsMap
public RunEntryStatistics findOrCreate( ReportEntry reportEntry )
{
final RunEntryStatistics item = runEntryStatistics.get( reportEntry.getName() );
- return item != null ? item : RunEntryStatistics.fromReportEntry( reportEntry );
+ return item != null ? item : fromReportEntry( reportEntry );
}
public RunEntryStatistics createNextGeneration( ReportEntry reportEntry )
@@ -187,7 +190,7 @@ public class RunEntryStatisticsMap
PrioritizedTest prioritizedTest = new PrioritizedTest( clazz, pri );
tests.add( prioritizedTest );
}
- Collections.sort( tests, new PrioritizedTestComparator() );
+ sort( tests, new PrioritizedTestComparator() );
return tests;
}
@@ -220,7 +223,7 @@ public class RunEntryStatisticsMap
}
List<Priority> items = new ArrayList<Priority>( priorities.values() );
- Collections.sort( items, priorityComparator );
+ sort( items, priorityComparator );
Map<String, Priority> result = new HashMap<String, Priority>();
int i = 0;
for ( Priority pri : items )