You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ti...@apache.org on 2020/04/08 08:22:10 UTC

[maven-surefire] 02/18: added TCP alternative in ConsoleOutputIT

This is an automated email from the ASF dual-hosted git repository.

tibordigana pushed a commit to branch maven2surefire-jvm-communication
in repository https://gitbox.apache.org/repos/asf/maven-surefire.git

commit 7a3cdef95d66267ec3991e4475546bd2ea1f977a
Author: tibordigana <ti...@apache.org>
AuthorDate: Mon Mar 9 08:43:00 2020 +0100

    added TCP alternative in ConsoleOutputIT
---
 .../spi/LegacyMasterProcessChannelEncoder.java     | 12 +++-
 .../apache/maven/surefire/its/ConsoleOutputIT.java | 78 +++++++++++++++++++---
 .../src/test/resources/consoleOutput/pom.xml       | 17 +++++
 3 files changed, 93 insertions(+), 14 deletions(-)

diff --git a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelEncoder.java b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelEncoder.java
index 57c84d4..a9bd41a 100644
--- a/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelEncoder.java
+++ b/surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelEncoder.java
@@ -32,6 +32,7 @@ import org.apache.maven.surefire.shared.codec.binary.Base64;
 import javax.annotation.Nonnull;
 import java.io.IOException;
 import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
 import java.nio.channels.WritableByteChannel;
 import java.nio.charset.Charset;
 import java.util.Map;
@@ -286,15 +287,20 @@ public class LegacyMasterProcessChannelEncoder implements MasterProcessChannelEn
         encodeAndPrintEvent( event );
     }
 
-    private void encodeAndPrintEvent( StringBuilder command )
+    private void encodeAndPrintEvent( StringBuilder event )
     {
-        byte[] array = command.append( '\n' ).toString().getBytes( STREAM_ENCODING );
+        byte[] array = event.append( '\n' ).toString().getBytes( STREAM_ENCODING );
         synchronized ( out )
         {
             try
             {
                 out.write( ByteBuffer.wrap( array ) );
             }
+            catch ( ClosedChannelException e )
+            {
+                DumpErrorSingleton.getSingleton()
+                    .dumpText( "Channel closed while writing the event '" + event + "'." );
+            }
             catch ( IOException e )
             {
                 DumpErrorSingleton.getSingleton().dumpException( e );
@@ -410,7 +416,7 @@ public class LegacyMasterProcessChannelEncoder implements MasterProcessChannelEn
      *
      * @param operation opcode
      * @param runMode   run mode
-     * @return encoded command
+     * @return encoded event
      */
     static StringBuilder encodeOpcode( String operation, String runMode )
     {
diff --git a/surefire-its/src/test/java/org/apache/maven/surefire/its/ConsoleOutputIT.java b/surefire-its/src/test/java/org/apache/maven/surefire/its/ConsoleOutputIT.java
index 6f0802c..430441b 100644
--- a/surefire-its/src/test/java/org/apache/maven/surefire/its/ConsoleOutputIT.java
+++ b/surefire-its/src/test/java/org/apache/maven/surefire/its/ConsoleOutputIT.java
@@ -19,10 +19,17 @@ package org.apache.maven.surefire.its;
  * under the License.
  */
 
+import com.googlecode.junittoolbox.ParallelParameterized;
 import org.apache.maven.surefire.its.fixture.OutputValidator;
 import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
+import org.apache.maven.surefire.its.fixture.SurefireLauncher;
 import org.apache.maven.surefire.its.fixture.TestFile;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.ArrayList;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
 
@@ -31,32 +38,71 @@ import static java.nio.charset.StandardCharsets.UTF_8;
  *
  * @author Kristian Rosenvold
  */
+@RunWith( ParallelParameterized.class )
 public class ConsoleOutputIT
     extends SurefireJUnit4IntegrationTestCase
 {
+    @Parameters
+    public static Iterable<Object[]> data()
+    {
+        ArrayList<Object[]> args = new ArrayList<>();
+        args.add( new Object[] { "tcp" } );
+        args.add( new Object[] { null } );
+        return args;
+    }
+
+    @Parameter
+    @SuppressWarnings( "checkstyle:visibilitymodifier" )
+    public String profileId;
+
     @Test
     public void properNewlinesAndEncodingWithDefaultEncodings()
     {
-        final OutputValidator outputValidator =
-            unpack( "/consoleOutput" ).forkOnce().executeTest();
+        SurefireLauncher launcher =
+            unpack( "/consoleOutput", profileId == null ? "" : profileId )
+                .forkOnce();
 
-        validate( outputValidator, true );
+        if ( profileId != null )
+        {
+            launcher.activateProfile( "tcp" );
+        }
+
+        OutputValidator outputValidator = launcher.executeTest();
+
+        validate( outputValidator, profileId == null );
     }
 
     @Test
     public void properNewlinesAndEncodingWithDifferentEncoding()
     {
-        final OutputValidator outputValidator =
-            unpack( "/consoleOutput" ).forkOnce().argLine( "-Dfile.encoding=UTF-16" ).executeTest();
+        SurefireLauncher launcher =
+            unpack( "/consoleOutput", profileId == null ? "" : profileId )
+                .forkOnce()
+                .argLine( "-Dfile.encoding=UTF-16" );
 
-        validate( outputValidator, true );
+        if ( profileId != null )
+        {
+            launcher.activateProfile( "tcp" );
+        }
+
+        OutputValidator outputValidator = launcher.executeTest();
+
+        validate( outputValidator, profileId == null );
     }
 
     @Test
     public void properNewlinesAndEncodingWithoutFork()
     {
-        final OutputValidator outputValidator =
-            unpack( "/consoleOutput" ).forkNever().executeTest();
+        SurefireLauncher launcher =
+            unpack( "/consoleOutput", profileId == null ? "" : profileId )
+                .forkNever();
+
+        if ( profileId != null )
+        {
+            launcher.activateProfile( "tcp" );
+        }
+
+        OutputValidator outputValidator = launcher.executeTest();
 
         validate( outputValidator, false );
     }
@@ -75,6 +121,8 @@ public class ConsoleOutputIT
 
         if ( includeShutdownHook )
         {
+            //todo it should not be reported in the last test which is completed
+            //todo this text should be in null-output.txt
             outputFile.assertContainsText( "Printline in shutdown hook" );
         }
     }
@@ -82,9 +130,17 @@ public class ConsoleOutputIT
     @Test
     public void largerSoutThanMemory()
     {
-        unpack( "consoleoutput-noisy" )
+        SurefireLauncher launcher =
+            unpack( "consoleoutput-noisy", profileId == null ? "" : "-" + profileId )
                 .setMavenOpts( "-Xmx64m" )
-                .sysProp( "thousand", "32000" )
-                .executeTest();
+                .sysProp( "thousand", "32000" );
+
+        if ( profileId != null )
+        {
+            launcher.activateProfile( "tcp" );
+        }
+
+        launcher.executeTest()
+            .verifyErrorFreeLog();
     }
 }
diff --git a/surefire-its/src/test/resources/consoleOutput/pom.xml b/surefire-its/src/test/resources/consoleOutput/pom.xml
index 407f909..2b52941 100644
--- a/surefire-its/src/test/resources/consoleOutput/pom.xml
+++ b/surefire-its/src/test/resources/consoleOutput/pom.xml
@@ -43,4 +43,21 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
+
+    <profiles>
+        <profile>
+            <id>tcp</id>
+            <build>
+                <plugins>
+                    <plugin>
+                        <groupId>org.apache.maven.plugins</groupId>
+                        <artifactId>maven-surefire-plugin</artifactId>
+                        <configuration>
+                            <forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory"/>
+                        </configuration>
+                    </plugin>
+                </plugins>
+            </build>
+        </profile>
+    </profiles>
 </project>