Repository: maven-surefire Updated Branches: refs/heads/2.19.2-experimental 5b103a724 -> 4f9536010
removed FileDescriptor Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/4f953601 Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/4f953601 Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/4f953601 Branch: refs/heads/2.19.2-experimental Commit: 4f9536010473051fa38080cc323e69cb8a2fdc2d Parents: 5b103a7 Author: Tibor17 <tibo...@lycos.com> Authored: Mon Mar 6 23:49:17 2017 +0100 Committer: Tibor17 <tibo...@lycos.com> Committed: Mon Mar 6 23:49:17 2017 +0100 ---------------------------------------------------------------------- .../maven/surefire/booter/CommandReader.java | 16 ++-------- .../surefire/booter/ForkingRunListener.java | 33 +++++++------------- .../maven/surefire/booter/ForkedBooter.java | 16 +++------- 3 files changed, 19 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4f953601/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java index 7e42c8e..d7fd900 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/CommandReader.java @@ -25,8 +25,6 @@ import org.apache.maven.surefire.testset.TestSetFailedException; import java.io.DataInputStream; import java.io.EOFException; -import java.io.FileDescriptor; -import java.io.FileOutputStream; import java.io.IOException; import java.io.PrintStream; import java.util.Iterator; @@ -338,18 +336,10 @@ public final class CommandReader private void requestNextTest() { byte[] encoded = encodeStringForForkCommunication( ( (char) BOOTERCODE_NEXT_TEST ) + ",0,want more!\n" ); - synchronized ( FileDescriptor.out ) + synchronized ( originalOutStream ) { - FileOutputStream out = new FileOutputStream( FileDescriptor.out ); - try - { - out.write( encoded, 0, encoded.length ); - out.getFD().sync(); - } - catch ( IOException e ) - { - // - } + originalOutStream.write( encoded, 0, encoded.length ); + originalOutStream.flush(); } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4f953601/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java ---------------------------------------------------------------------- diff --git a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java index 84ca644..7856dac 100644 --- a/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java +++ b/surefire-api/src/main/java/org/apache/maven/surefire/booter/ForkingRunListener.java @@ -19,9 +19,6 @@ package org.apache.maven.surefire.booter; * under the License. */ -import java.io.FileDescriptor; -import java.io.FileOutputStream; -import java.io.IOException; import java.io.PrintStream; import java.util.Enumeration; import java.util.Properties; @@ -115,6 +112,8 @@ public class ForkingRunListener public static final byte BOOTERCODE_WARNING = (byte) 'W'; + private final PrintStream target; + private final int testSetChannelId; private final boolean trimStackTraces; @@ -125,6 +124,7 @@ public class ForkingRunListener public ForkingRunListener( PrintStream target, int testSetChannelId, boolean trimStackTraces ) { + this.target = target; this.testSetChannelId = testSetChannelId; this.trimStackTraces = trimStackTraces; stdOutHeader = createHeader( BOOTERCODE_STDOUT, testSetChannelId ); @@ -203,15 +203,11 @@ public class ForkingRunListener System.arraycopy( header, 0, encodeBytes, 0, header.length ); System.arraycopy( content, 0, encodeBytes, header.length, i ); - synchronized ( FileDescriptor.out ) // See notes about synchronization/thread safety in class javadoc + synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { - FileOutputStream out = new FileOutputStream( FileDescriptor.out ); - try - { - out.write( encodeBytes, 0, encodeBytes.length ); - out.getFD().sync(); - } - catch ( IOException e ) + target.write( encodeBytes, 0, encodeBytes.length ); + target.flush(); + if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception @@ -277,20 +273,15 @@ public class ForkingRunListener private void encodeAndWriteToTarget( String string ) { byte[] encodeBytes = encodeStringForForkCommunication( string ); - synchronized ( FileDescriptor.out ) // See notes about synchronization/thread safety in class javadoc + synchronized ( target ) // See notes about synchronization/thread safety in class javadoc { - FileOutputStream out = new FileOutputStream( FileDescriptor.out ); - try - { - out.write( encodeBytes, 0, encodeBytes.length ); - out.getFD().sync(); - } - catch ( IOException e ) + target.write( encodeBytes, 0, encodeBytes.length ); + target.flush(); + if ( target.checkError() ) { // We MUST NOT throw any exception from this method; otherwise we are in loop and CPU goes up: // ForkingRunListener -> Exception -> JUnit Notifier and RunListener -> ForkingRunListener -> Exception - DumpErrorSingleton.getSingleton() - .dumpStreamText( "Unexpected IOException with stream: " + string ); + DumpErrorSingleton.getSingleton().dumpStreamText( "Unexpected IOException: " + string ); } } } http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/4f953601/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java ---------------------------------------------------------------------- diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java index e1d4a7f..c94848a 100644 --- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java +++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/ForkedBooter.java @@ -251,21 +251,13 @@ public final class ForkedBooter }; } - private static void encodeAndWriteToOutput( String string, PrintStream out1 ) + private static void encodeAndWriteToOutput( String string, PrintStream out ) { byte[] encodeBytes = encodeStringForForkCommunication( string ); - synchronized ( FileDescriptor.out ) + synchronized ( out ) { - FileOutputStream out = new FileOutputStream( FileDescriptor.out ); - try - { - out.write( encodeBytes, 0, encodeBytes.length ); - out.getFD().sync(); - } - catch ( IOException e ) - { - // - } + out.write( encodeBytes, 0, encodeBytes.length ); + out.flush(); } }