You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ag...@apache.org on 2014/08/26 22:30:55 UTC
git commit: [SUREFIRE-1091] Prevent IOExceptions in case a thread
tries to write to an already closed Utf8RecodingDeferredFileOutputStream
Repository: maven-surefire
Updated Branches:
refs/heads/master 11c151ced -> ad278f82d
[SUREFIRE-1091] Prevent IOExceptions in case a thread tries to write to an already closed Utf8RecodingDeferredFileOutputStream
Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/ad278f82
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/ad278f82
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/ad278f82
Branch: refs/heads/master
Commit: ad278f82da8b31e057b88b6ffe6655bc8fa1830e
Parents: 11c151c
Author: Andreas Gudian <ag...@apache.org>
Authored: Tue Aug 26 21:55:26 2014 +0200
Committer: Andreas Gudian <ag...@apache.org>
Committed: Tue Aug 26 22:30:02 2014 +0200
----------------------------------------------------------------------
.../Utf8RecodingDeferredFileOutputStream.java | 22 ++++++--
.../test/java/consoleoutput_noisy/Test1.java | 55 +++++++++++++++-----
2 files changed, 59 insertions(+), 18 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ad278f82/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Utf8RecodingDeferredFileOutputStream.java
----------------------------------------------------------------------
diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Utf8RecodingDeferredFileOutputStream.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Utf8RecodingDeferredFileOutputStream.java
index 5c7b8a3..af1682f 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Utf8RecodingDeferredFileOutputStream.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/report/Utf8RecodingDeferredFileOutputStream.java
@@ -37,6 +37,8 @@ class Utf8RecodingDeferredFileOutputStream
{
private DeferredFileOutputStream deferredFileOutputStream;
+ private boolean closed = false;
+
private static final Charset UTF8 = Charset.forName( "UTF-8" );
public Utf8RecodingDeferredFileOutputStream( String channel )
@@ -44,9 +46,14 @@ class Utf8RecodingDeferredFileOutputStream
this.deferredFileOutputStream = new DeferredFileOutputStream( 1000000, channel, "deferred", null );
}
- public void write( byte[] buf, int off, int len )
+ public synchronized void write( byte[] buf, int off, int len )
throws IOException
{
+ if ( closed )
+ {
+ return;
+ }
+
if ( !Charset.defaultCharset().equals( UTF8 ) )
{
CharBuffer decodedFromDefaultCharset = Charset.defaultCharset().decode( ByteBuffer.wrap( buf, off, len ) );
@@ -77,24 +84,29 @@ class Utf8RecodingDeferredFileOutputStream
return deferredFileOutputStream.getByteCount();
}
- public void close()
+ public synchronized void close()
throws IOException
{
+ closed = true;
deferredFileOutputStream.close();
}
- public void writeTo( OutputStream out )
+ public synchronized void writeTo( OutputStream out )
throws IOException
{
- deferredFileOutputStream.writeTo( out );
+ if ( closed )
+ {
+ deferredFileOutputStream.writeTo( out );
+ }
}
- public void free()
+ public synchronized void free()
{
if ( null != deferredFileOutputStream && null != deferredFileOutputStream.getFile() )
{
try
{
+ closed = true;
deferredFileOutputStream.close();
if ( !deferredFileOutputStream.getFile().delete() )
{
http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/ad278f82/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
----------------------------------------------------------------------
diff --git a/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java b/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
index 4b5a21f..888cd22 100644
--- a/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
+++ b/surefire-integration-tests/src/test/resources/consoleoutput-noisy/src/test/java/consoleoutput_noisy/Test1.java
@@ -19,38 +19,67 @@ package consoleoutput_noisy;
* under the License.
*/
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
public class Test1
- extends TestCase
{
public static final int thousand = Integer.parseInt( System.getProperty( "thousand", "1000" ) );
+ @Test
public void test1MillionBytes()
{
for ( int i = 0; i < ( 10 * thousand ); i++ )
{
- System.out.println(
- "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" );
+ System.out.println( "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789" );
}
}
- public static void testHundredThousand()
+ @Test
+ public void testHundredThousand()
{
- for ( int i = 0; i < thousand; i++ )
- {
- System.out.println(
- "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
- }
+ printAlot();
}
- public static void testAnotherHundredThousand()
+ private static void printAlot()
{
for ( int i = 0; i < thousand; i++ )
{
- System.out.println(
- "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
+ System.out.println( "AAAAAAAAAABBBBBBBBBBCCCCCCCCCCDDDDDDDDDDEEEEEEEEEEFFFFFFFFFFGGGGGGGGGGHHHHHHHHHHIIIIIIIIIIJJJJJJJJJJ" );
}
}
+
+ @Test
+ public void testAnotherHundredThousand()
+ {
+ printAlot();
+ }
+
+ @Before
+ public void before()
+ {
+ printAlot();
+ }
+
+ @BeforeClass
+ public static void beforeClass()
+ {
+ printAlot();
+ }
+
+ @After
+ public void after()
+ {
+ printAlot();
+ }
+
+ @AfterClass
+ public static void afterClass()
+ {
+ printAlot();
+ }
}