Return-Path: Delivered-To: apmail-maven-surefire-commits-archive@www.apache.org Received: (qmail 64248 invoked from network); 16 Dec 2010 09:32:46 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 16 Dec 2010 09:32:46 -0000 Received: (qmail 77335 invoked by uid 500); 16 Dec 2010 09:32:46 -0000 Delivered-To: apmail-maven-surefire-commits-archive@maven.apache.org Received: (qmail 77283 invoked by uid 500); 16 Dec 2010 09:32:45 -0000 Mailing-List: contact surefire-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: surefire-dev@maven.apache.org Delivered-To: mailing list surefire-commits@maven.apache.org Received: (qmail 77276 invoked by uid 99); 16 Dec 2010 09:32:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Dec 2010 09:32:45 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Dec 2010 09:32:41 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id C569E2388A33; Thu, 16 Dec 2010 09:32:19 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1049843 - in /maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient: ForkStarter.java output/FileOutputConsumerProxy.java output/SynchronizedOutputConsumer.java Date: Thu, 16 Dec 2010 09:32:19 -0000 To: surefire-commits@maven.apache.org From: krosenvold@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101216093219.C569E2388A33@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: krosenvold Date: Thu Dec 16 09:32:19 2010 New Revision: 1049843 URL: http://svn.apache.org/viewvc?rev=1049843&view=rev Log: [SUREFIRE-665] Intermittent failure of logging test output to file Changed solution. Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java (with props) Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java?rev=1049843&r1=1049842&r2=1049843&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java Thu Dec 16 09:32:19 2010 @@ -24,6 +24,7 @@ import org.apache.maven.plugin.surefire. import org.apache.maven.plugin.surefire.booterclient.output.StandardOutputConsumer; import org.apache.maven.plugin.surefire.booterclient.output.SupressFooterOutputConsumerProxy; import org.apache.maven.plugin.surefire.booterclient.output.SupressHeaderOutputConsumerProxy; +import org.apache.maven.plugin.surefire.booterclient.output.SynchronizedOutputConsumer; import org.apache.maven.surefire.booter.Classpath; import org.apache.maven.surefire.booter.ProviderConfiguration; import org.apache.maven.surefire.booter.ProviderFactory; @@ -170,8 +171,7 @@ public class ForkStarter { BooterSerializer booterSerializer = new BooterSerializer( forkConfiguration, properties ); - surefireProperties = - booterSerializer.serialize( providerConfiguration, startupConfiguration, testSet ); + surefireProperties = booterSerializer.serialize( providerConfiguration, startupConfiguration, testSet ); if ( forkConfiguration.getSystemProperties() != null ) { @@ -205,11 +205,13 @@ public class ForkStarter final boolean willBeSharingConsumer = startupConfiguration.isRedirectTestOutputToFile(); ForkingStreamConsumer out = - getForkingStreamConsumer( showHeading, showFooter, startupConfiguration.isRedirectTestOutputToFile() ); + getForkingStreamConsumer( showHeading, showFooter, startupConfiguration.isRedirectTestOutputToFile(), + willBeSharingConsumer ); StreamConsumer err = willBeSharingConsumer ? out - : getForkingStreamConsumer( showHeading, showFooter, startupConfiguration.isRedirectTestOutputToFile() ); + : getForkingStreamConsumer( showHeading, showFooter, startupConfiguration.isRedirectTestOutputToFile(), + false ); if ( forkConfiguration.isDebug() ) { @@ -267,7 +269,7 @@ public class ForkStarter } private ForkingStreamConsumer getForkingStreamConsumer( boolean showHeading, boolean showFooter, - boolean redirectTestOutputToFile ) + boolean redirectTestOutputToFile, boolean mustBeThreadSafe ) { OutputConsumer outputConsumer = new StandardOutputConsumer(); @@ -286,6 +288,11 @@ public class ForkStarter outputConsumer = new SupressFooterOutputConsumerProxy( outputConsumer ); } + if ( mustBeThreadSafe ) + { + outputConsumer = new SynchronizedOutputConsumer( outputConsumer ); + } + return new ForkingStreamConsumer( outputConsumer ); } } Modified: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java?rev=1049843&r1=1049842&r2=1049843&view=diff ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java (original) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/FileOutputConsumerProxy.java Thu Dec 16 09:32:19 2010 @@ -31,6 +31,9 @@ import java.io.PrintWriter; /** * Surefire output consumer proxy that writes test output to a {@link File} for each test suite. * + * This class is not threadsafe, but can be encapsulated with a SynchronizedOutputConsumer. It may still be + * accessed from different threads (serially). + * * @author Carlos Sanchez * @version $Id$ * @since 2.1 @@ -84,7 +87,7 @@ public class FileOutputConsumerProxy super.testSetStarting( reportEntry ); } - public synchronized void testSetCompleted() + public void testSetCompleted() { if ( printWriter == null ) { @@ -104,9 +107,8 @@ public class FileOutputConsumerProxy /** * Write the output to the current test file *

- * This method may be called from multiple threads */ - public synchronized void consumeOutputLine( String line ) + public void consumeOutputLine( String line ) { if ( printWriter == null ) { Added: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java URL: http://svn.apache.org/viewvc/maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java?rev=1049843&view=auto ============================================================================== --- maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java (added) +++ maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java Thu Dec 16 09:32:19 2010 @@ -0,0 +1,69 @@ +package org.apache.maven.plugin.surefire.booterclient.output; + +/* + * 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.surefire.report.ReportEntry; + +/** + * Imposes synchronization on a non-thredsafe OutputConsumer + * + * @author Kristian Rosenvold + */ +public class SynchronizedOutputConsumer + implements OutputConsumer +{ + + final OutputConsumer target; + + public SynchronizedOutputConsumer( OutputConsumer target ) + { + this.target = target; + } + + public synchronized void consumeHeaderLine( String line ) + { + target.consumeHeaderLine( line ); + } + + public synchronized void consumeMessageLine( String line ) + { + target.consumeMessageLine( line ); + } + + public synchronized void consumeFooterLine( String line ) + { + target.consumeFooterLine( line ); + } + + public synchronized void consumeOutputLine( String line ) + { + target.consumeOutputLine( line ); + } + + public synchronized void testSetStarting( ReportEntry reportEntry ) + { + target.testSetStarting( reportEntry ); + } + + public synchronized void testSetCompleted() + { + target.testSetCompleted(); + } +} Propchange: maven/surefire/trunk/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/SynchronizedOutputConsumer.java ------------------------------------------------------------------------------ svn:eol-style = native