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/03/25 09:41:41 UTC

[maven-surefire] branch maven2surefire-jvm-communication updated: E2E test for TCP

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


The following commit(s) were added to refs/heads/maven2surefire-jvm-communication by this push:
     new 2171cdc  E2E test for TCP
2171cdc is described below

commit 2171cdcb7ca5f029e72b2f11bd72dae0b5425e08
Author: tibordigana <ti...@apache.org>
AuthorDate: Wed Mar 25 10:41:32 2020 +0100

    E2E test for TCP
---
 .../surefire/extensions/SurefireForkChannel.java   |   2 +-
 .../maven/plugin/surefire/extensions/E2ETest.java  | 126 +++++++++++++++++++++
 2 files changed, 127 insertions(+), 1 deletion(-)

diff --git a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
index e11b03f..3285486 100644
--- a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
+++ b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/SurefireForkChannel.java
@@ -65,7 +65,7 @@ final class SurefireForkChannel extends ForkChannel
     private final int localPort;
     private volatile SocketChannel channel;
 
-    SurefireForkChannel( int forkChannelId, ConsoleLogger logger ) throws IOException
+    SurefireForkChannel( int forkChannelId, @Nonnull ConsoleLogger logger ) throws IOException
     {
         super( forkChannelId );
         this.logger = logger;
diff --git a/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
new file mode 100644
index 0000000..ec76a8c
--- /dev/null
+++ b/maven-surefire-common/src/test/java/org/apache/maven/plugin/surefire/extensions/E2ETest.java
@@ -0,0 +1,126 @@
+package org.apache.maven.plugin.surefire.extensions;
+
+import org.apache.maven.plugin.surefire.log.api.ConsoleLogger;
+import org.apache.maven.surefire.booter.spi.SurefireMasterProcessChannelProcessorFactory;
+import org.apache.maven.surefire.eventapi.Event;
+import org.apache.maven.surefire.extensions.EventHandler;
+import org.apache.maven.surefire.extensions.util.CountdownCloseable;
+import org.apache.maven.surefire.providerapi.MasterProcessChannelEncoder;
+import org.apache.maven.surefire.report.ConsoleOutputCapture;
+import org.apache.maven.surefire.report.ConsoleOutputReceiver;
+import org.junit.Test;
+
+import javax.annotation.Nonnull;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.util.concurrent.TimeUnit;
+
+import static org.mockito.Mockito.mock;
+
+public class E2ETest
+{
+    private static final String LONG_STRING =
+        "0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789";
+
+    @Test
+    public void test() throws Exception
+    {
+        ConsoleLogger logger = mock( ConsoleLogger.class );
+        SurefireForkChannel server = new SurefireForkChannel(1, logger );
+
+        final String connection = server.getForkNodeConnectionString();
+
+        SurefireMasterProcessChannelProcessorFactory factory = new SurefireMasterProcessChannelProcessorFactory();
+        factory.connect( connection );
+        final MasterProcessChannelEncoder encoder = factory.createEncoder();
+
+        Thread t = new Thread()
+        {
+            @Override
+            public void run()
+            {
+                ConsoleOutputReceiver target = new ConsoleOutputReceiver()
+                {
+                    @Override
+                    public void writeTestOutput( String output, boolean newLine, boolean stdout )
+                    {
+                        encoder.stdOut( output, true );
+                    }
+                };
+
+                PrintStream out = System.out;
+                PrintStream err = System.err;
+
+                ConsoleOutputCapture.startCapture( target );
+
+                try
+                {
+                    for ( int i = 0; i < 320_000; i++ )
+                    {
+                        System.out.println( LONG_STRING );
+                    }
+                    System.setOut( out );
+                    System.setErr( err );
+                    TimeUnit.MINUTES.sleep( 1L );
+                }
+                catch ( Exception e )
+                {
+                    e.printStackTrace();
+                }
+            }
+        };
+        t.setDaemon( true );
+        t.start();
+
+        server.connectToClient();
+
+        EventHandler<Event> h = new EventHandler<Event>()
+        {
+            volatile int i;
+            volatile long t1;
+
+            @Override
+            public void handleEvent( @Nonnull Event event )
+            {
+                try
+                {
+                    if ( i++ == 0 )
+                    {
+                        t1 = System.currentTimeMillis();
+                    }
+
+                    if ( i == 320_000 )
+                    {
+                        long t2 = System.currentTimeMillis();
+                        TimeUnit.SECONDS.sleep( 1L );
+                        System.out.println( "Forked JVM spent "
+                            + ( t2 - t1 )
+                            + "ms on transferring all lines of the log." );
+                    }
+                }
+                catch ( InterruptedException e )
+                {
+                    e.printStackTrace();
+                }
+            }
+        };
+
+        Closeable c = new Closeable()
+        {
+            @Override
+            public void close() throws IOException
+            {
+
+            }
+        };
+
+        server.bindEventHandler( h, new CountdownCloseable( c, 1 ), null )
+        .start();
+
+        TimeUnit.SECONDS.sleep( 60L );
+
+        factory.close();
+        server.close();
+    }
+}