You are viewing a plain text version of this content. The canonical link for it is here.
Posted to surefire-commits@maven.apache.org by kr...@apache.org on 2011/03/26 08:57:40 UTC
svn commit: r1085662 - in /maven/surefire/trunk:
surefire-api/src/main/java/org/apache/maven/surefire/report/
surefire-api/src/main/java/org/apache/maven/surefire/util/
surefire-api/src/main/java/org/apache/maven/surefire/util/internal/
surefire-api/sr...
Author: krosenvold
Date: Sat Mar 26 07:57:39 2011
New Revision: 1085662
URL: http://svn.apache.org/viewvc?rev=1085662&view=rev
Log:
o Changed console output capture
Added:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java (with props)
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiver.java
- copied, changed from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiverForCurrentThread.java
- copied, changed from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java (with props)
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemConsoleOutputReceiver.java
- copied, changed from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java (with props)
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java (with props)
maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java (with props)
maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java (with props)
maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/
maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java (contents, props changed)
- copied, changed from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java (with props)
maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java (with props)
Removed:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemStreamCapturer.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java
Modified:
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestSetRunListener.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java
maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,84 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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 java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+/**
+ * Deals with system.out/err.
+ * <p/>
+ */
+public class ConsoleOutputCapture
+{
+
+ private static final PrintStream oldOut = System.out;
+
+ private static final PrintStream oldErr = System.err;
+
+ public ConsoleOutputCapture( ConsoleOutputReceiver target )
+ {
+ System.setOut( new ForwardingPrintStream( true, target ) );
+
+ System.setErr( new ForwardingPrintStream( false, target ) );
+ }
+
+ public void restoreStreams()
+ {
+ System.setOut( oldOut );
+ System.setErr( oldErr );
+ }
+
+ static class ForwardingPrintStream
+ extends PrintStream
+ {
+ private final boolean isStdout;
+
+ private final ConsoleOutputReceiver target;
+
+ ForwardingPrintStream( boolean stdout, ConsoleOutputReceiver target )
+ {
+ super( new ByteArrayOutputStream() );
+ isStdout = stdout;
+ this.target = target;
+ }
+
+ public void write( byte[] buf, int off, int len )
+ {
+ target.writeTestOutput( buf, off, len, isStdout );
+ }
+
+ public void write( byte[] b )
+ throws IOException
+ {
+ target.writeTestOutput( b, 0, b.length, isStdout );
+ }
+
+ public void close()
+ {
+ }
+
+ public void flush()
+ {
+ }
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputCapture.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiver.java (from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiver.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiver.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java&r1=1085000&r2=1085662&rev=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiver.java Sat Mar 26 07:57:39 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.util;
+package org.apache.maven.surefire.report;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,43 +19,21 @@ package org.apache.maven.surefire.util;
* under the License.
*/
-import java.io.PrintStream;
-
/**
- * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id$
+ * A receiver of stdout/sterr output from running tests. This receiver knows how to associate
+ * the output with a given testset.
*/
-public class TeeStream
- extends PrintStream
+public interface ConsoleOutputReceiver
{
- private final PrintStream tee;
-
- public TeeStream( PrintStream out1, PrintStream out2 )
- {
- super( out1 );
-
- this.tee = out2;
- }
-
- public void write( byte[] buf, int off, int len )
- {
- super.write( buf, off, len );
- tee.write( buf, off, len );
- }
+ /**
+ * Forwards process output from the running test-case into the reporting system
+ *
+ * @param buf the buffer to write
+ * @param off offset
+ * @param len len
+ * @param stdout Indicates if this is stdout
+ */
+ void writeTestOutput( byte[] buf, int off, int len, boolean stdout );
- public void close()
- {
- super.close();
-
- tee.close();
- }
-
- public void flush()
- {
- super.flush();
-
- tee.flush();
- }
}
-
Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiverForCurrentThread.java (from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiverForCurrentThread.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiverForCurrentThread.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java&r1=1085000&r2=1085662&rev=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ConsoleOutputReceiverForCurrentThread.java Sat Mar 26 07:57:39 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.util;
+package org.apache.maven.surefire.report;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,43 +19,31 @@ package org.apache.maven.surefire.util;
* under the License.
*/
-import java.io.PrintStream;
-
/**
- * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id$
+ * @author Kristian Rosenvold
*/
-public class TeeStream
- extends PrintStream
+public final class ConsoleOutputReceiverForCurrentThread
{
- private final PrintStream tee;
+ private static final ThreadLocal current = new InheritableThreadLocal();
- public TeeStream( PrintStream out1, PrintStream out2 )
+ private ConsoleOutputReceiverForCurrentThread()
{
- super( out1 );
-
- this.tee = out2;
}
- public void write( byte[] buf, int off, int len )
+ public static ConsoleOutputReceiver get()
{
- super.write( buf, off, len );
-
- tee.write( buf, off, len );
+ return (ConsoleOutputReceiver) current.get();
}
- public void close()
+ public static void set( ConsoleOutputReceiver consoleOutputReceiver )
{
- super.close();
-
- tee.close();
+ current.set( consoleOutputReceiver );
}
- public void flush()
+ public static void remove()
{
- super.flush();
-
- tee.flush();
+ current.remove();
}
+
}
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,51 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class DefaultConsoleOutputReceiver
+ implements ConsoleOutputReceiver
+{
+ private final ConsoleOutputReceiver defaultConsoleOutputReceiver;
+
+ private final boolean dumpToConsole;
+
+ public DefaultConsoleOutputReceiver( ConsoleOutputReceiver defaultConsoleOutputReceiver, boolean dumpToConsole )
+ {
+ this.defaultConsoleOutputReceiver = defaultConsoleOutputReceiver;
+ this.dumpToConsole = dumpToConsole;
+ }
+
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ final ConsoleOutputReceiver consoleOutputReceiver = ConsoleOutputReceiverForCurrentThread.get();
+ if ( consoleOutputReceiver != null )
+ {
+ consoleOutputReceiver.writeTestOutput( buf, off, len, stdout );
+ }
+ // Don't "else" this to simulate teestream; write to both streams if available
+ if ( dumpToConsole )
+ {
+ defaultConsoleOutputReceiver.writeTestOutput( buf, off, len, stdout );
+ }
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/DefaultConsoleOutputReceiver.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java?rev=1085662&r1=1085661&r2=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/ReporterManagerFactory.java Sat Mar 26 07:57:39 2011
@@ -59,16 +59,20 @@ public class ReporterManagerFactory
private final Object lock = new Object();
- private List reports;
-
- private final SystemStreamCapturer systemStreamCapturer = new SystemStreamCapturer();
+ private final ConsoleOutputCapture consoleOutputCapture;
public ReporterManagerFactory( ClassLoader surefireClassLoader, ReporterConfiguration reporterConfiguration )
{
this.reportDefinitions = reporterConfiguration.getReports();
this.surefireClassLoader = surefireClassLoader;
this.reporterConfiguration = reporterConfiguration;
- this.reports = instantiateReportsNewStyle( reportDefinitions, reporterConfiguration, surefireClassLoader );
+ SystemConsoleOutputReceiver systemConsoleOutputReceiver =
+ new SystemConsoleOutputReceiver( reporterConfiguration.getOriginalSystemOut(),
+ reporterConfiguration.getOriginalSystemErr() );
+ // todo: Fix parallel (must keep quiet on default stream?)
+ final DefaultConsoleOutputReceiver target =
+ new DefaultConsoleOutputReceiver( systemConsoleOutputReceiver, true );
+ this.consoleOutputCapture = new ConsoleOutputCapture( target );
}
public RunStatistics getGlobalRunStatistics()
@@ -78,8 +82,8 @@ public class ReporterManagerFactory
public RunListener createReporter()
{
- reports = instantiateReportsNewStyle( reportDefinitions, reporterConfiguration, surefireClassLoader );
- return setupReporter( reports );
+ return setupReporter(
+ instantiateReportsNewStyle( reportDefinitions, reporterConfiguration, surefireClassLoader ) );
}
@@ -87,8 +91,7 @@ public class ReporterManagerFactory
{
// Note, if we ever start making >1 reporter Managers, we have to aggregate run statistics
// i.e. we cannot use a single "globalRunStatistics"
- final TestSetRunListener reporterManager =
- new TestSetRunListener( reports, globalRunStatistics, systemStreamCapturer );
+ final TestSetRunListener reporterManager = new TestSetRunListener( reports, globalRunStatistics );
if ( first == null )
{
synchronized ( lock )
@@ -106,6 +109,7 @@ public class ReporterManagerFactory
public RunResult close()
{
+ consoleOutputCapture.restoreStreams();
warnIfNoTests();
synchronized ( lock )
{
@@ -165,15 +169,18 @@ public class ReporterManagerFactory
}
- public DirectConsoleReporter createConsoleReporter() {
- return new DefaultDirectConsoleReporter(reporterConfiguration.getOriginalSystemOut());
+ public DirectConsoleReporter createConsoleReporter()
+ {
+ return new DefaultDirectConsoleReporter( reporterConfiguration.getOriginalSystemOut() );
}
private void warnIfNoTests()
{
if ( getGlobalRunStatistics().getRunResult().getCompletedCount() == 0 )
{
- new MulticastingReporter( reports ).writeMessage( "There are no tests to run." );
+ final List target =
+ instantiateReportsNewStyle( reportDefinitions, reporterConfiguration, surefireClassLoader );
+ new MulticastingReporter( target ).writeMessage( "There are no tests to run." );
}
}
}
Copied: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemConsoleOutputReceiver.java (from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemConsoleOutputReceiver.java?p2=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemConsoleOutputReceiver.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java&r1=1085000&r2=1085662&rev=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/SystemConsoleOutputReceiver.java Sat Mar 26 07:57:39 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.util;
+package org.apache.maven.surefire.report;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -22,40 +22,23 @@ package org.apache.maven.surefire.util;
import java.io.PrintStream;
/**
- * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id$
+ * @author Kristian Rosenvold
*/
-public class TeeStream
- extends PrintStream
+public class SystemConsoleOutputReceiver
+ implements ConsoleOutputReceiver
{
- private final PrintStream tee;
+ private final PrintStream out;
- public TeeStream( PrintStream out1, PrintStream out2 )
- {
- super( out1 );
-
- this.tee = out2;
- }
-
- public void write( byte[] buf, int off, int len )
- {
- super.write( buf, off, len );
+ private final PrintStream err;
- tee.write( buf, off, len );
- }
-
- public void close()
+ public SystemConsoleOutputReceiver( PrintStream out, PrintStream err )
{
- super.close();
-
- tee.close();
+ this.out = out;
+ this.err = err;
}
- public void flush()
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
{
- super.flush();
-
- tee.flush();
+ ( stdout ? out : err ).write( buf, off, len );
}
}
-
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,225 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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 java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Attaches the currently executing test method to the thread, allowing
+ * test output to be directed to the proper test set.
+ *
+ * @author Kristian Rosenvold
+ */
+public abstract class TestConsoleOutputRunListener
+ implements RunListener, ConsoleOutputReceiver
+{
+ private final ReporterFactory reporterFactory;
+
+ protected TestConsoleOutputRunListener( ReporterFactory reporterFactory )
+ {
+ this.reporterFactory = reporterFactory;
+ }
+
+ public static TestConsoleOutputRunListener createInstance( ReporterFactory reporterFactory,
+ boolean oneThreadPerClass )
+ {
+ return oneThreadPerClass ? (TestConsoleOutputRunListener) new OneThreadPerClassConsoleOutputRunListener(
+ reporterFactory ) : new UnknownThreadPerClassConsoleOutputRunListener( reporterFactory );
+ }
+
+ protected abstract RunListener getTestSetRunListener( ReportEntry reportEntry );
+
+ protected abstract void clearTestSetRunListener( ReportEntry reportEntry );
+
+ protected abstract RunListener getTestMethodRunListener( ReportEntry report );
+
+ protected abstract void clearTestMethodRunListener( ReportEntry reportEntry );
+
+ protected abstract ConsoleOutputReceiver getConsoleOutputReceiver();
+
+ protected ReporterFactory getReporterFactory()
+ {
+ return reporterFactory;
+ }
+
+
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ getConsoleOutputReceiver().writeTestOutput( buf, off, len, stdout );
+ }
+
+ public void testSetStarting( ReportEntry report )
+ throws ReporterException
+ {
+ getTestSetRunListener( report ).testSetStarting( report );
+ }
+
+ public void testSetCompleted( ReportEntry report )
+ throws ReporterException
+ {
+ getTestSetRunListener( report ).testSetCompleted( report );
+ clearTestSetRunListener( report );
+ }
+
+ public void testStarting( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testStarting( report );
+ }
+
+ public void testSucceeded( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testSucceeded( report );
+ clearTestMethodRunListener( report );
+ }
+
+ public void testAssumptionFailure( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testAssumptionFailure( report );
+ clearTestMethodRunListener( report );
+ }
+
+ public void testError( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testError( report );
+ clearTestMethodRunListener( report );
+ }
+
+ public void testFailed( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testFailed( report );
+ clearTestMethodRunListener( report );
+ }
+
+ public void testSkipped( ReportEntry report )
+ {
+ getTestMethodRunListener( report ).testSkipped( report );
+ clearTestMethodRunListener( report );
+ }
+
+ public static class OneThreadPerClassConsoleOutputRunListener
+ extends TestConsoleOutputRunListener
+ {
+ private final ThreadLocal currentTestMethodListener = new InheritableThreadLocal();
+
+ public OneThreadPerClassConsoleOutputRunListener( ReporterFactory reporterFactory )
+ {
+ super( reporterFactory );
+ }
+
+ protected RunListener getTestSetRunListener( ReportEntry reportEntry )
+ {
+ return getTestMethodRunListener( reportEntry );
+ }
+
+ protected void clearTestSetRunListener( ReportEntry reportEntry )
+ {
+ currentTestMethodListener.remove();
+ }
+
+ protected void clearTestMethodRunListener( ReportEntry reportEntry )
+ {
+ // Dont clear, we do this in testset.
+ }
+
+ protected RunListener getTestMethodRunListener( ReportEntry report )
+ {
+ RunListener runListener = (RunListener) currentTestMethodListener.get();
+ if ( runListener == null )
+ {
+ runListener = getReporterFactory().createReporter();
+ currentTestMethodListener.set( runListener );
+ }
+ return runListener;
+ }
+
+ protected ConsoleOutputReceiver getConsoleOutputReceiver()
+ {
+ return (ConsoleOutputReceiver) currentTestMethodListener.get();
+ }
+
+
+ }
+
+ public static class UnknownThreadPerClassConsoleOutputRunListener
+ extends TestConsoleOutputRunListener
+ {
+ private final ThreadLocal currentTestMethodListener = new InheritableThreadLocal();
+
+ private final ThreadLocal currentTestSetListener = new InheritableThreadLocal();
+
+ private final Map testSetToRunListener = Collections.synchronizedMap( new HashMap() );
+
+ public UnknownThreadPerClassConsoleOutputRunListener( ReporterFactory reporterFactory )
+ {
+ super( reporterFactory );
+ }
+
+
+ protected RunListener getTestSetRunListener( ReportEntry reportEntry )
+ {
+ RunListener result = (RunListener) testSetToRunListener.get( reportEntry.getSourceName() );
+ if ( result == null )
+ {
+ result = getReporterFactory().createReporter();
+ testSetToRunListener.put( reportEntry.getSourceName(), result );
+ }
+ currentTestSetListener.set( result );
+ return result;
+ }
+
+ protected void clearTestSetRunListener( ReportEntry reportEntry )
+ {
+ currentTestSetListener.remove();
+ }
+
+ protected RunListener getTestMethodRunListener( ReportEntry report )
+ {
+ RunListener runListener;
+ runListener = (RunListener) testSetToRunListener.get( report.getSourceName() );
+ if ( runListener == null )
+ {
+ runListener = getReporterFactory().createReporter();
+ testSetToRunListener.put( report.getSourceName(), runListener );
+ }
+ currentTestMethodListener.set( runListener );
+ return runListener;
+ }
+
+ protected void clearTestMethodRunListener( ReportEntry reportEntry )
+ {
+ currentTestMethodListener.remove();
+ }
+
+ protected ConsoleOutputReceiver getConsoleOutputReceiver()
+ {
+ ConsoleOutputReceiver consoleOutputReceiver = (ConsoleOutputReceiver) currentTestMethodListener.get();
+ if ( consoleOutputReceiver == null )
+ {
+ consoleOutputReceiver = (ConsoleOutputReceiver) currentTestSetListener.get();
+ }
+ return consoleOutputReceiver;
+ }
+
+
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestConsoleOutputRunListener.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestSetRunListener.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestSetRunListener.java?rev=1085662&r1=1085661&r2=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestSetRunListener.java (original)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/report/TestSetRunListener.java Sat Mar 26 07:57:39 2011
@@ -19,6 +19,10 @@ package org.apache.maven.surefire.report
* under the License.
*/
+import org.apache.maven.surefire.util.internal.ByteBuffer;
+
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.Iterator;
import java.util.List;
@@ -37,18 +41,19 @@ import java.util.List;
* <p/>
*/
public class TestSetRunListener
- implements RunListener, RunReporter, Reporter
+ implements RunListener, RunReporter, Reporter, ConsoleOutputReceiver
{
private final RunStatistics runStatisticsForThis;
private final MulticastingReporter multicastingReporter;
- private final SystemStreamCapturer consoleCapturer;
+ private final List testStdOut = Collections.synchronizedList( new ArrayList() );
+
+ private final List testStdErr = Collections.synchronizedList( new ArrayList() );
+
- public TestSetRunListener( List reports, RunStatistics runStatisticsForThis,
- SystemStreamCapturer systemStreamCapturer )
+ public TestSetRunListener( List reports, RunStatistics runStatisticsForThis )
{
- this.consoleCapturer = systemStreamCapturer;
multicastingReporter = new MulticastingReporter( reports );
this.runStatisticsForThis = runStatisticsForThis;
}
@@ -58,6 +63,20 @@ public class TestSetRunListener
multicastingReporter.writeMessage( message );
}
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ ByteBuffer byteBuffer = new ByteBuffer( buf, off, len );
+ if ( stdout )
+ {
+ testStdOut.add( byteBuffer );
+ }
+ else
+ {
+ testStdErr.add( byteBuffer );
+ }
+ multicastingReporter.writeMessage( new String( buf, off, len ) );
+ }
+
public void writeDetailMessage( String message )
{
multicastingReporter.writeDetailMessage( message );
@@ -98,7 +117,6 @@ public class TestSetRunListener
}
multicastingReporter.writeFooter( runStatisticsForThis.getSummary() );
multicastingReporter.writeFooter( "" );
- consoleCapturer.restoreStreams();
}
public void writeFooter( String footer )
@@ -130,14 +148,14 @@ public class TestSetRunListener
public void testSucceeded( ReportEntry report )
{
- consoleCapturer.clearCapturedContent();
+ clearCapturedContent();
runStatisticsForThis.incrementCompletedCount();
multicastingReporter.testSucceeded( report );
}
public void testError( ReportEntry reportEntry )
{
- testError( reportEntry, consoleCapturer.getStdOutLog(), consoleCapturer.getStdErrLog() );
+ testError( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) );
}
public void testError( ReportEntry reportEntry, String stdOutLog, String stdErrLog )
@@ -146,12 +164,12 @@ public class TestSetRunListener
runStatisticsForThis.incrementErrorsCount();
runStatisticsForThis.incrementCompletedCount();
runStatisticsForThis.addErrorSource( reportEntry.getName(), reportEntry.getStackTraceWriter() );
- consoleCapturer.clearCapturedContent();
+ clearCapturedContent();
}
public void testFailed( ReportEntry reportEntry )
{
- testFailed( reportEntry, consoleCapturer.getStdOutLog(), consoleCapturer.getStdErrLog() );
+ testFailed( reportEntry, getAsString( testStdOut ), getAsString( testStdErr ) );
}
public void testFailed( ReportEntry reportEntry, String stdOutLog, String stdErrLog )
@@ -160,7 +178,7 @@ public class TestSetRunListener
runStatisticsForThis.incrementFailureCount();
runStatisticsForThis.incrementCompletedCount();
runStatisticsForThis.addFailureSource( reportEntry.getName(), reportEntry.getStackTraceWriter() );
- consoleCapturer.clearCapturedContent();
+ clearCapturedContent();
}
// ----------------------------------------------------------------------
@@ -169,7 +187,7 @@ public class TestSetRunListener
public void testSkipped( ReportEntry report )
{
- consoleCapturer.clearCapturedContent();
+ clearCapturedContent();
runStatisticsForThis.incrementSkippedCount();
runStatisticsForThis.incrementCompletedCount();
multicastingReporter.testSkipped( report );
@@ -185,4 +203,22 @@ public class TestSetRunListener
multicastingReporter.reset();
}
+ public String getAsString( List byteBufferList )
+ {
+ StringBuffer stringBuffer = new StringBuffer();
+ for ( Iterator iter = byteBufferList.iterator(); iter.hasNext(); )
+ {
+ ByteBuffer byteBuffer = (ByteBuffer) iter.next();
+ stringBuffer.append( byteBuffer.toString() );
+ }
+ return stringBuffer.toString();
+ }
+
+ public void clearCapturedContent()
+ {
+ testStdErr.clear();
+ testStdOut.clear();
+ }
+
+
}
Added: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java (added)
+++ maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,171 @@
+package org.apache.maven.surefire.util.internal;
+
+/*
+ * 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 java.io.PrintStream;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class ByteBuffer
+{
+ private final byte[] data;
+
+ private int position;
+
+ public ByteBuffer( int length )
+ {
+ this.data = new byte[length];
+ }
+
+ public ByteBuffer( byte[] buf, int off, int len )
+ {
+ this.data = new byte[len];
+ append( buf, off, len );
+ }
+
+
+ public void append( char chararcter )
+ {
+ data[position++] = (byte) chararcter;
+ }
+
+ public void append( byte chararcter )
+ {
+ data[position++] = chararcter;
+ }
+
+ static final byte comma = (byte) ',';
+
+ public void comma()
+ {
+ data[position++] = comma;
+ }
+
+
+ public void advance( int i )
+ { // Oooh nice break of encapsulation
+ position += i;
+ }
+
+ public void append( Integer integer )
+ {
+ toHex( integer.intValue() );
+ }
+
+ /**
+ * Convert the integer to an unsigned number.
+ */
+ private void toHex( int i )
+ {
+ byte[] buf = new byte[32];
+ int charPos = 32;
+ int radix = 1 << 4;
+ int mask = radix - 1;
+ do
+ {
+ buf[--charPos] = (byte) digits[i & mask];
+ i >>>= 4;
+ }
+ while ( i != 0 );
+
+ append( buf, charPos, ( 32 - charPos ) );
+ }
+
+ final static char[] digits =
+ { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
+ 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' };
+
+
+ public byte[] getData()
+ {
+ return data;
+ }
+
+ public int getlength()
+ {
+ return position;
+ }
+
+ public String toString()
+ {
+ return new String( data, 0, position );
+ }
+
+ public void append( ByteBuffer other )
+ {
+ byte[] src = other.getData();
+ final int length = src.length;
+ for ( int i = 0; i < length; i++ )
+ {
+ data[position++] = src[i];
+ }
+ }
+
+ public static byte[] copy( byte[] src1, int off1, int len1 )
+ {
+ byte[] combined = new byte[len1];
+ int pos = 0;
+ for ( int i = off1; i < off1 + len1; i++ )
+ {
+ combined[pos++] = src1[i];
+ }
+ return combined;
+ }
+
+ public void append( byte[] src1, int off1, int len1 )
+ {
+ for ( int i = off1; i < off1 + len1; i++ )
+ {
+ data[position++] = src1[i];
+ }
+ }
+
+ public static byte[] join( byte[] src1, int off1, int len1, byte[] src2, int off2, int len2 )
+ {
+ byte[] combined = new byte[len1 + len2];
+ int pos = 0;
+ for ( int i = off1; i < off1 + len1; i++ )
+ {
+ combined[pos++] = src1[i];
+ }
+ for ( int i = off2; i < off2 + len2; i++ )
+ {
+ combined[pos++] = src2[i];
+ }
+ return combined;
+ }
+
+ public void print( PrintStream printStream )
+ {
+ printStream.write( data, 0, position );
+ }
+
+ public static char[] toChar( byte[] b, int off, int len )
+ {
+ char[] result = new char[len];
+ int pos = 0;
+ for ( int i = off; i < off + len; i++ )
+ {
+ result[pos++] = (char) b[i];
+ }
+ return result;
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/internal/ByteBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java (added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,189 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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 java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * Internal use only
+ */
+public class MockReporter
+ implements RunListener, DirectConsoleReporter
+{
+ private final List events = new ArrayList();
+
+ private final List data = new ArrayList();
+
+ public static final String SET_STARTING = "SET_STARTED";
+
+ public static final String SET_COMPLETED = "SET_COMPLETED";
+
+ public static final String TEST_STARTING = "TEST_STARTED";
+
+ public static final String TEST_SUCCEEDED = "TEST_COMPLETED";
+
+ public static final String TEST_FAILED = "TEST_FAILED";
+
+ public static final String TEST_ERROR = "TEST_ERROR";
+
+ public static final String TEST_SKIPPED = "TEST_SKIPPED";
+
+ public static final String TEST_ASSUMPTION_FAIL = "TEST_ASSUMPTION_SKIPPED";
+
+ public static final String CONSOLE_OUTPUT = "CONSOLE_OUTPUT";
+
+ public static final String STDOUT = "STDOUT";
+
+ public static final String STDERR = "STDERR";
+
+ private final AtomicInteger testSucceeded = new AtomicInteger();
+
+ private final AtomicInteger testIgnored = new AtomicInteger();
+
+ private final AtomicInteger testFailed = new AtomicInteger();
+
+ private final AtomicInteger testError = new AtomicInteger();
+
+ public MockReporter()
+ {
+ }
+
+ public MockReporter( ReporterConfiguration reporterConfiguration )
+ {
+
+ }
+
+ public void testSetStarting( ReportEntry report )
+ {
+ events.add( SET_STARTING );
+ data.add( report );
+ }
+
+ public void testSetCompleted( ReportEntry report )
+ {
+ events.add( SET_COMPLETED );
+ data.add( report );
+ }
+
+ public void testStarting( ReportEntry report )
+ {
+ events.add( TEST_STARTING );
+ data.add( report );
+ }
+
+ public void testSucceeded( ReportEntry report )
+ {
+ events.add( TEST_SUCCEEDED );
+ testSucceeded.incrementAndGet();
+ data.add( report );
+ }
+
+ public void testError( ReportEntry report )
+ {
+ events.add( TEST_ERROR );
+ data.add( report );
+ testFailed.incrementAndGet();
+ }
+
+ public void testFailed( ReportEntry report )
+ {
+ events.add( TEST_FAILED );
+ data.add( report );
+ testFailed.incrementAndGet();
+ }
+
+
+ public void testSkipped( ReportEntry report )
+ {
+ events.add( TEST_SKIPPED );
+ data.add( report );
+ testIgnored.incrementAndGet();
+ }
+
+
+ public List getEvents()
+ {
+ return events;
+ }
+
+ public List getData()
+ {
+ return data;
+ }
+
+ public String getFirstEvent()
+ {
+ return (String) events.get( 0 );
+ }
+
+ public ReportEntry getFirstData()
+ {
+ return (ReportEntry) data.get( 0 );
+ }
+
+ public String getFirstStringData()
+ {
+ return (String) data.get( 0 );
+ }
+
+ public int getTestSucceeded()
+ {
+ return testSucceeded.get();
+ }
+
+ public int getTestIgnored()
+ {
+ return testIgnored.get();
+ }
+
+ public int getTestFailed()
+ {
+ return testFailed.get();
+ }
+
+
+ public void testAssumptionFailure( ReportEntry report )
+ {
+ events.add( TEST_ASSUMPTION_FAIL );
+ data.add( report );
+ testIgnored.incrementAndGet();
+
+ }
+
+ public void writeTestOutput( String output, boolean stdout )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void writeMessage( String message )
+ {
+ events.add( CONSOLE_OUTPUT );
+ data.add( message );
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ events.add( stdout ? STDOUT : STDERR );
+ data.add( new String( buf, off, len ) );
+ }
+}
Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/MockReporter.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java (added)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,61 @@
+package org.apache.maven.surefire.report;
+
+/*
+ * 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 java.util.Arrays;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Kristian Rosenvold
+ */
+public class TestConsoleOutputRunListenerTest
+ extends TestCase
+{
+ public void testGetCurrentReportEntry()
+ throws Exception
+ {
+ MockReporter mockReporter = new MockReporter();
+ ReporterFactory reporterFactory = createReporterFactory();
+ TestConsoleOutputRunListener testConsoleOutputRunListener =
+ TestConsoleOutputRunListener.createInstance( reporterFactory, true );
+
+/* assertNull( TestConsoleOutputRunListener.getCurrentReportEntry() );
+ ReportEntry reportEntry = new SimpleReportEntry( "srcClass", "testName" );
+ testConsoleOutputRunListener.testStarting( reportEntry );
+ assertEquals( reportEntry, TestConsoleOutputRunListener.getCurrentReportEntry() );
+ testConsoleOutputRunListener.testSucceeded( reportEntry );
+ assertNull( TestConsoleOutputRunListener.getCurrentReportEntry() );
+ */
+ }
+
+ private ReporterFactory createReporterFactory()
+ {
+ ReporterConfiguration reporterConfiguration = getTestReporterConfiguration();
+ return new ReporterManagerFactory( this.getClass().getClassLoader(), reporterConfiguration );
+ }
+
+ public static ReporterConfiguration getTestReporterConfiguration()
+ {
+ return new ReporterConfiguration( Arrays.asList( new Object[]{ ConsoleReporter.class.getName() } ), null,
+ Boolean.TRUE, null );
+ }
+
+}
Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/report/TestConsoleOutputRunListenerTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java (from r1085000, maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java)
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java?p2=maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java&p1=maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java&r1=1085000&r2=1085662&rev=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-api/src/main/java/org/apache/maven/surefire/util/TeeStream.java (original)
+++ maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java Sat Mar 26 07:57:39 2011
@@ -1,4 +1,4 @@
-package org.apache.maven.surefire.util;
+package org.apache.maven.surefire.util.internal;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -19,43 +19,30 @@ package org.apache.maven.surefire.util;
* under the License.
*/
-import java.io.PrintStream;
+import junit.framework.TestCase;
/**
- * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
- * @version $Id$
+ * @author Kristian Rosenvold
*/
-public class TeeStream
- extends PrintStream
+public class ByteBufferTest
+ extends TestCase
{
- private final PrintStream tee;
-
- public TeeStream( PrintStream out1, PrintStream out2 )
- {
- super( out1 );
-
- this.tee = out2;
- }
-
- public void write( byte[] buf, int off, int len )
+ public void testAppend()
+ throws Exception
{
- super.write( buf, off, len );
+ ByteBuffer byteBuffer = new ByteBuffer( 30 );
+ byteBuffer.append( 'C' );
+ byteBuffer.append( (byte) 'D' );
+ assertEquals( "CD", byteBuffer.toString() );
- tee.write( buf, off, len );
}
- public void close()
- {
- super.close();
-
- tee.close();
- }
- public void flush()
+ public void testJoin()
{
- super.flush();
-
- tee.flush();
+ byte[] b1 = "ABC".getBytes();
+ byte[] b2 = "DE".getBytes();
+ final byte[] join = ByteBuffer.join( b1, 0, 3, b2, 0, 2 );
+ assertEquals( 5, join.length );
}
}
-
Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/surefire/trunk/surefire-api/src/test/java/org/apache/maven/surefire/util/internal/ByteBufferTest.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml Sat Mar 26 07:57:39 2011
@@ -0,0 +1,63 @@
+<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>org.apache.maven.plugins.surefire</groupId>
+ <artifactId>fork-consoleOutput</artifactId>
+ <packaging>jar</packaging>
+ <version>1.0-SNAPSHOT</version>
+ <name>consoleOutput-noisy</name>
+ <url>http://maven.apache.org</url>
+
+ <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>${forkMode}</forkMode>
+ <printSummary>${printSummary}</printSummary>
+ <useFile>${useFile}</useFile>
+ <parallel>${parallel}</parallel>
+ <threadCount>${threadCount}</threadCount>
+ <reportFormat>${reportFormat}</reportFormat>
+ <redirectTestOutputToFile>${redirect.to.file}</redirectTestOutputToFile>
+ <trimStackTrace>${trimStackTrace}</trimStackTrace>
+ <!-- argLine>-agentpath:/opt/yjp-9.5.4/bin/linux-x86-64/libyjpagent.so=tracing,monitors,onexit=snapshot</argLine -->
+ <includes>
+ <include>**/Test*.java</include>
+ </includes>
+ </configuration>
+ </plugin>
+ </plugins>
+
+ </build>
+
+ <properties>
+ <useFile>true</useFile>
+ <junit.version>4.8.1</junit.version>
+ <redirect.to.file>true</redirect.to.file>
+ <forkMode>once</forkMode>
+ <printSummary>true</printSummary>
+ <parallel></parallel>
+ <reportFormat>brief</reportFormat>
+ <trimStackTrace>true</trimStackTrace>
+ <threadCount>4</threadCount>
+ </properties>
+
+</project>
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/pom.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,55 @@
+package consoleoutput_noisy;
+
+/*
+ * 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 junit.framework.TestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class Test1
+ extends TestCase
+{
+ public void test1MillionBytes()
+ {
+ for ( int i = 0; i < 10000; i++ )
+ {
+ System.out.println(
+ "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" );
+ }
+ }
+
+ public static void testHundredThousand()
+ {
+ for ( int i = 0; i < 1000; i++ )
+ {
+ System.out.println(
+ "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
+ }
+ }
+
+ public static void testAnotherHundredThousand()
+ {
+ for ( int i = 0; i < 1000; i++ )
+ {
+ System.out.println(
+ "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
+ }
+ }
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java?rev=1085662&view=auto
==============================================================================
--- maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java (added)
+++ maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java Sat Mar 26 07:57:39 2011
@@ -0,0 +1,55 @@
+package consoleoutput_noisy;
+
+/*
+ * 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 junit.framework.TestCase;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class Test2
+ extends TestCase
+{
+ public void test2MillionBytes()
+ {
+ for ( int i = 0; i < 10000; i++ )
+ {
+ System.out.println(
+ "0-2-3-6-8-012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" );
+ }
+ }
+
+ public static void testHundredThousand()
+ {
+ for ( int i = 0; i < 1000; i++ )
+ {
+ System.out.println(
+ "A-A-3-A-A-BBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
+ }
+ }
+
+ public static void testAnotherHundredThousand()
+ {
+ for ( int i = 0; i < 1000; i++ )
+ {
+ System.out.println(
+ "A-A-A-3-3-ABBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
+ }
+ }
+}
Propchange: maven/surefire/trunk/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test2.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java?rev=1085662&r1=1085661&r2=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/ConcurrentReporterManager.java Sat Mar 26 07:57:39 2011
@@ -50,8 +50,7 @@ public abstract class ConcurrentReporter
private final ReporterFactory reporterFactory;
ConcurrentReporterManager( ReporterFactory reporterFactory, boolean reportImmediately,
- ReporterConfiguration reporterConfiguration,
- Map<String, TestSet> classMethodCounts )
+ ReporterConfiguration reporterConfiguration, Map<String, TestSet> classMethodCounts )
throws TestSetFailedException
{
this.reportImmediately = reportImmediately;
@@ -117,7 +116,9 @@ public abstract class ConcurrentReporter
public void testStarting( ReportEntry description )
{
TestSet testSet = getTestSet( description );
- testSet.createTestMethod( description ).attachToThread();
+ final TestMethod testMethod = testSet.createTestMethod( description );
+ testMethod.attachToThread();
+
checkIfTestSetCanBeReported( testSet );
testSet.attachToThread();
}
Modified: maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java
URL: http://svn.apache.org/viewvc/maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java?rev=1085662&r1=1085661&r2=1085662&view=diff
==============================================================================
--- maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java (original)
+++ maven/surefire/trunk/surefire-providers/surefire-junit47/src/main/java/org/apache/maven/surefire/junitcore/TestMethod.java Sat Mar 26 07:57:39 2011
@@ -19,8 +19,10 @@ package org.apache.maven.surefire.junitc
* under the License.
*/
-import org.apache.maven.surefire.report.Reporter;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.apache.maven.surefire.report.ConsoleOutputReceiverForCurrentThread;
import org.apache.maven.surefire.report.ReportEntry;
+import org.apache.maven.surefire.report.Reporter;
/**
* Represents the test-state of a single test method that is run.
@@ -29,6 +31,7 @@ import org.apache.maven.surefire.report.
* without any actual parallel access
*/
class TestMethod
+ implements ConsoleOutputReceiver
{
private final ReportEntry description;
@@ -123,11 +126,14 @@ class TestMethod
public void attachToThread()
{
TEST_METHOD.set( this );
+ ConsoleOutputReceiverForCurrentThread.set( this );
+
}
public static void detachFromCurrentThread()
{
TEST_METHOD.remove();
+ ConsoleOutputReceiverForCurrentThread.remove();
}
public static TestMethod getThreadTestMethod()
@@ -144,6 +150,10 @@ class TestMethod
return output;
}
+ public void writeTestOutput( byte[] buf, int off, int len, boolean stdout )
+ {
+ getLogicalStream().write( stdout, buf, off, len );
+ }
private String getStdout()
{