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/08/26 11:18:17 UTC
[maven-surefire] 01/01: logging in non-forking mode
This is an automated email from the ASF dual-hosted git repository.
tibordigana pushed a commit to branch INV1561
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git
commit 19d0be31b033727e690e1b13852d18ea42dc5a15
Author: Tibor17 <ti...@apache.org>
AuthorDate: Sun Aug 26 13:17:59 2018 +0200
logging in non-forking mode
---
.../maven/surefire/booter/ForkingRunListener.java | 30 ++++++++++++++++++++++
surefire-its/pom.xml | 3 ++-
.../test/resources/testng-parallel-suites/pom.xml | 1 +
.../java/testng/suiteXml/ShouldNotRunTest.java | 5 +---
.../test/java/testng/suiteXml/TestNGSuiteTest.java | 9 ++-----
5 files changed, 36 insertions(+), 12 deletions(-)
diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
index ce806b9..acfc7eb 100644
--- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
+++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java
@@ -21,6 +21,7 @@ package org.apache.maven.surefire.booter;
import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
import org.apache.maven.plugin.surefire.log.api.ConsoleLoggerUtils;
+import org.apache.maven.shared.utils.io.FileUtils;
import org.apache.maven.surefire.report.ConsoleOutputReceiver;
import org.apache.maven.surefire.report.ConsoleStream;
import org.apache.maven.surefire.report.ReportEntry;
@@ -31,8 +32,11 @@ import org.apache.maven.surefire.report.StackTraceWriter;
import org.apache.maven.surefire.report.TestSetReportEntry;
import org.apache.maven.surefire.util.internal.StringUtils.EncodedArray;
+import java.io.File;
+import java.io.IOException;
import java.io.PrintStream;
import java.util.Map.Entry;
+import java.util.concurrent.atomic.AtomicInteger;
import static java.lang.Integer.toHexString;
import static java.nio.charset.Charset.defaultCharset;
@@ -198,9 +202,23 @@ public class ForkingRunListener
}
}
+ private static final AtomicInteger INT = new AtomicInteger();
+
@Override
public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
{
+ try
+ {
+ File console = new File( "target/console-" + INT.getAndIncrement() );
+ //noinspection ResultOfMethodCallIgnored
+ console.createNewFile();
+ String[] msg = { new String( buf, off, len ) };
+ FileUtils.fileWriteArray( console, "UTF-8", msg );
+ }
+ catch ( IOException e )
+ {
+ // do nothing
+ }
EncodedArray encodedArray = escapeBytesToPrintable( stdout ? stdOutHeader : stdErrHeader, buf, off, len );
synchronized ( target ) // See notes about synchronization/thread safety in class javadoc
@@ -302,6 +320,18 @@ public class ForkingRunListener
private void encodeAndWriteToTarget( String string )
{
+ try
+ {
+ File console = new File( "target/console-" + INT.getAndIncrement() );
+ //noinspection ResultOfMethodCallIgnored
+ console.createNewFile();
+ String[] msg = { string };
+ FileUtils.fileWriteArray( console, "UTF-8", msg );
+ }
+ catch ( IOException e )
+ {
+ // do nothing
+ }
byte[] encodeBytes = encodeStringForForkCommunication( string );
synchronized ( target ) // See notes about synchronization/thread safety in class javadoc
{
diff --git a/surefire-its/pom.xml b/surefire-its/pom.xml
index 5ee30c9..a27a7c2 100644
--- a/surefire-its/pom.xml
+++ b/surefire-its/pom.xml
@@ -97,6 +97,7 @@
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.12.4</version> <!-- ${shadedVersion}, but resolved due to https://issues.apache.org/jira/browse/MRELEASE-799 -->
<configuration>
+ <skipTests>false</skipTests>
<jvm>${jdk.home}/bin/java</jvm>
<runOrder>alphabetical</runOrder>
<threadCount>1</threadCount>
@@ -104,7 +105,7 @@
<forkMode>once</forkMode>
<argLine>-server -Xmx64m -XX:+UseG1GC -XX:+TieredCompilation -XX:TieredStopAtLevel=1 -Djava.awt.headless=true</argLine>
<includes>
- <include>org/apache/**/*IT*.java</include>
+ <include>org/apache/**/Surefire1177TestngParallelSuitesIT.java</include>
</includes>
<!-- Pass current surefire version to the main suite so that it -->
<!-- can forward to all integration test projects. SUREFIRE-513 -->
diff --git a/surefire-its/src/test/resources/testng-parallel-suites/pom.xml b/surefire-its/src/test/resources/testng-parallel-suites/pom.xml
index e3e347b..9030974 100644
--- a/surefire-its/src/test/resources/testng-parallel-suites/pom.xml
+++ b/surefire-its/src/test/resources/testng-parallel-suites/pom.xml
@@ -63,6 +63,7 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <forkMode>once</forkMode>
<suiteXmlFiles>
<file>src/test/resources/testng1.xml</file>
<file>src/test/resources/testng2.xml</file>
diff --git a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
index 4a19e78..d2eb9ca 100644
--- a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
+++ b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/ShouldNotRunTest.java
@@ -30,9 +30,6 @@ public class ShouldNotRunTest {
@Test
public void shouldNotRun()
{
- synchronized ( System.out )
- {
- System.out.println( getClass().getSimpleName() + "#shouldNotRun()" );
- }
+ System.out.println( getClass().getSimpleName() + "#shouldNotRun()" );
}
}
\ No newline at end of file
diff --git a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
index 95fe0e2..24bc69a 100644
--- a/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
+++ b/surefire-its/src/test/resources/testng-parallel-suites/src/test/java/testng/suiteXml/TestNGSuiteTest.java
@@ -22,24 +22,19 @@ package testng.suiteXml;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
/**
* @author <a href="mailto:tibordigana@apache.org">Tibor Digana (tibor17)</a>
* @since 2.19
*/
public class TestNGSuiteTest {
- private static final AtomicInteger counter = new AtomicInteger();
@Test
public void shouldRunAndPrintItself()
throws Exception
{
- synchronized ( System.out )
- {
- System.out.println( getClass().getSimpleName() + "#shouldRunAndPrintItself() "
- + counter.incrementAndGet() + ".");
- }
+ System.out.println( getClass().getSimpleName() + "#shouldRunAndPrintItself() "
+ + counter.incrementAndGet() + ".");
TimeUnit.SECONDS.sleep( 2 );
}