Author: krosenvold
Date: Sat Jul 10 14:14:57 2010
New Revision: 962846
URL: http://svn.apache.org/viewvc?rev=962846&view=rev
Log:
[SUREFIRE-628] Console output before/after class is discarded when running
parallel
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java
(with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
(with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test1.java
- copied, changed from r957320,
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test2.java
- copied, changed from r957320,
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListener.java
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java?rev=962846&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java
Sat Jul 10 14:14:57 2010
@@ -0,0 +1,56 @@
+package org.apache.maven.surefire.its;
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+
+import org.apache.maven.it.Verifier;
+import org.apache.maven.it.util.ResourceExtractor;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * SUREFIRE-621 Asserts that console output always goes somewhere ;)
+ *
+ * @author Kristian Rosenvold
+ */
+public class Surefire628ConsoleOutputBeforeAndAfterClassIT
+ extends AbstractSurefireIntegrationTestClass
+{
+ public void testJunit3ParallelBuildResultCount()
+ throws Exception
+ {
+ File testDir = ResourceExtractor.simpleExtractResources( getClass(),
"/surefire-628-consoleoutputbeforeandafterclass" );
+
+ Verifier verifier = new Verifier( testDir.getAbsolutePath() );
+ String[] opts = { "-fn" };
+ verifier.setCliOptions( new ArrayList( Arrays.asList( opts ) ) );
+ this.executeGoal( verifier, "test" );
+ verifier.resetStreams();
+
+ verifier.verifyTextInLog( "628Test1");
+ verifier.verifyTextInLog( "Before628Test1");
+ verifier.verifyTextInLog( "After628Test1");
+ verifier.verifyTextInLog( "628Test2");
+ verifier.verifyTextInLog( "Before628Test2");
+ verifier.verifyTextInLog( "After628Test2");
+ }
+
+}
\ No newline at end of file
Propchange:
maven/surefire/trunk/surefire-integration-tests/src/test/java/org/apache/maven/surefire/its/Surefire628ConsoleOutputBeforeAndAfterClassIT.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml?rev=962846&view=auto
==============================================================================
---
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
(added)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
Sat Jul 10 14:14:57 2010
@@ -0,0 +1,46 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>mag</groupId>
+ <artifactId>junit4-test</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>junit4-test</name>
+ <url>http://maven.apache.org</url>
+ <properties>
+ <junit.version>4.8.1</junit.version>
+ <junit.parallel>methods</junit.parallel>
+ </properties>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>${junit.version}</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire.version}</version>
+ <configuration>
+ <forkMode>once</forkMode>
+ <parallel>${junit.parallel}</parallel>
+ <threadCount>5</threadCount>
+ <includes>
+ <include>**/Test*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Propchange:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/pom.xml
------------------------------------------------------------------------------
svn:executable = *
Copied:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test1.java
(from r957320,
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test1.java?p2=maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test1.java&p1=maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java&r1=957320&r2=962846&rev=962846&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test1.java
Sat Jul 10 14:14:57 2010
@@ -1,4 +1,5 @@
-package org.apache.maven.surefire.junitcore;
+package surefire628;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,43 +19,30 @@ package org.apache.maven.surefire.junitc
* under the License.
*/
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-class ConcurrentPrintStream
- extends PrintStream
-{
- private final boolean isStdout;
-
- ConcurrentPrintStream( boolean stdout )
- {
- super( new ByteArrayOutputStream() );
- isStdout = stdout;
- }
-
+import org.junit.Test;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
- public void write( byte[] buf, int off, int len )
- {
- final TestMethod threadTestMethod = TestMethod.getThreadTestMethod();
- if ( threadTestMethod != null )
- {
- threadTestMethod.getLogicalStream().write( isStdout, buf, off, len
);
- }
- else
- {
- ( (ByteArrayOutputStream) out ).write( buf, off, len );
- }
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assume.*;
+public class Test1
+{
+ @Test
+ public void test6281() {
+ System.out.println( "628Test1 on" + Thread.currentThread().getName());
}
- public void close()
- {
-
+ @BeforeClass
+ public static void testWithFailingAssumption2() {
+ System.out.println( "Before628Test1 on" +
Thread.currentThread().getName());
}
-
- public void flush()
- {
+
+ @AfterClass
+ public static void testWithFailingAssumption3() {
+ System.out.println( "After628Test1 on" +
Thread.currentThread().getName());
}
-
-}
+}
\ No newline at end of file
Copied:
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test2.java
(from r957320,
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java)
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test2.java?p2=maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test2.java&p1=maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java&r1=957320&r2=962846&rev=962846&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
(original)
+++
maven/surefire/trunk/surefire-integration-tests/src/test/resources/surefire-628-consoleoutputbeforeandafterclass/src/test/java/surefire628/Test2.java
Sat Jul 10 14:14:57 2010
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.junitcore;
+package surefire628;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,43 +18,31 @@ package org.apache.maven.surefire.junitc
* under the License.
*/
-import java.io.ByteArrayOutputStream;
-import java.io.PrintStream;
-
-class ConcurrentPrintStream
- extends PrintStream
-{
- private final boolean isStdout;
-
- ConcurrentPrintStream( boolean stdout )
- {
- super( new ByteArrayOutputStream() );
- isStdout = stdout;
- }
+import org.junit.Test;
+import org.junit.BeforeClass;
+import org.junit.AfterClass;
- public void write( byte[] buf, int off, int len )
- {
- final TestMethod threadTestMethod = TestMethod.getThreadTestMethod();
- if ( threadTestMethod != null )
- {
- threadTestMethod.getLogicalStream().write( isStdout, buf, off, len
);
- }
- else
- {
- ( (ByteArrayOutputStream) out ).write( buf, off, len );
- }
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.hamcrest.CoreMatchers.*;
+import static org.junit.Assume.*;
+public class Test2
+{
+ @Test
+ public void test6281() {
+ System.out.println( "628Test2 on" + Thread.currentThread().getName());
}
- public void close()
- {
-
+ @BeforeClass
+ public static void testWithFailingAssumption2() {
+ System.out.println( "Before628Test2 on" +
Thread.currentThread().getName());
}
- public void flush()
- {
+ @AfterClass
+ public static void testWithFailingAssumption3() {
+ System.out.println( "After628Test2 on" +
Thread.currentThread().getName());
}
-
-}
+}
\ No newline at end of file
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java?rev=962846&r1=962845&r2=962846&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentPrintStream.java
Sat Jul 10 14:14:57 2010
@@ -19,6 +19,7 @@ package org.apache.maven.surefire.junitc
*/
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
import java.io.PrintStream;
class ConcurrentPrintStream
@@ -26,6 +27,9 @@ class ConcurrentPrintStream
{
private final boolean isStdout;
+ private final LogicalStream defaultStream = new LogicalStream();
+
+
ConcurrentPrintStream( boolean stdout )
{
super( new ByteArrayOutputStream() );
@@ -43,10 +47,16 @@ class ConcurrentPrintStream
}
else
{
- ( (ByteArrayOutputStream) out ).write( buf, off, len );
+ ( (ByteArrayOutputStream) out ).write( buf, off, len );
}
}
+ public void writeTo(PrintStream printStream)
+ throws IOException
+ {
+ ( (ByteArrayOutputStream) out ).writeTo( printStream );
+ }
+
public void close()
{
Modified:
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListener.java
URL:
http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListener.java?rev=962846&r1=962845&r2=962846&view=diff
==============================================================================
---
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListener.java
(original)
+++
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReportingRunListener.java
Sat Jul 10 14:14:57 2010
@@ -46,6 +46,9 @@ public abstract class ConcurrentReportin
protected final boolean reportImmediately;
+ private final ConcurrentPrintStream out = new ConcurrentPrintStream( true
);
+ private final ConcurrentPrintStream err = new ConcurrentPrintStream( false
);
+
public ConcurrentReportingRunListener( ReporterManagerFactory
reporterFactory, boolean reportImmediately )
throws TestSetFailedException
{
@@ -54,8 +57,8 @@ public abstract class ConcurrentReportin
// Important: We must capture System.out/System.err AFTER the
reportManager captures stdout/stderr
// because we know how to demultiplex correctly. The redirection in
reporterManager is basically
// ignored/unused because we use ConcurrentPrintStream.
- System.setOut( new ConcurrentPrintStream( true ) );
- System.setErr( new ConcurrentPrintStream( false ) );
+ System.setOut( out );
+ System.setErr( err );
}
@Override
@@ -75,6 +78,9 @@ public abstract class ConcurrentReportin
}
System.setOut( orgSystemOut );
System.setErr( orgSystemErr );
+
+ out.writeTo( orgSystemOut );
+ err.writeTo( orgSystemErr );
}
protected TestMethod getTestMethod()