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 81bd734  after review by 
https://github.com/apache/maven-surefire/pull/240/#discussion_r378260883
81bd734 is described below

commit 81bd734f0ec5d1b76d5ea1a461284fd8b66ee134
Author: tibordigana <[email protected]>
AuthorDate: Mon Feb 17 23:03:23 2020 +0100

    after review by 
https://github.com/apache/maven-surefire/pull/240/#discussion_r378260883
---
 .../plugin/surefire/booterclient/ForkStarter.java  | 12 +++---
 .../surefire/extensions/LegacyForkChannel.java     | 24 ++---------
 .../surefire/extensions/SurefireForkChannel.java   | 25 ++---------
 .../maven/surefire/extensions/ForkChannelTest.java | 24 ++++++++---
 surefire-booter/pom.xml                            |  2 +
 .../maven/surefire/extensions/ForkChannel.java     | 48 ++++------------------
 .../extensions/util/CountdownCloseable.java        |  7 +---
 7 files changed, 43 insertions(+), 99 deletions(-)

diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
index 4c407ba..ad66d0a 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
@@ -563,6 +563,7 @@ public class ForkStarter
                             boolean readTestsFromInStream )
         throws SurefireBooterForkException
     {
+        CloseableCloser closer = new CloseableCloser( forkNumber, 
commandReader );
         final String tempDir;
         final File surefireProperties;
         final File systPropsFile;
@@ -570,6 +571,7 @@ public class ForkStarter
         try
         {
             forkChannel = forkNodeFactory.createForkChannel( forkNumber );
+            closer.addCloseable( forkChannel );
             tempDir = forkConfiguration.getTempDirectory().getCanonicalPath();
             BooterSerializer booterSerializer = new BooterSerializer( 
forkConfiguration );
             Long pluginPid = 
forkConfiguration.getPluginPlatform().getPluginPid();
@@ -613,7 +615,7 @@ public class ForkStarter
         }
 
         ThreadedStreamConsumer eventConsumer = new ThreadedStreamConsumer( 
forkClient );
-        CloseableCloser closer = new CloseableCloser( forkNumber, 
eventConsumer, commandReader );
+        closer.addCloseable( eventConsumer );
 
         log.debug( "Forking command line: " + cli );
 
@@ -634,16 +636,12 @@ public class ForkStarter
 
             forkChannel.connectToClient();
 
-            in = forkChannel.useStdIn()
-                ? forkChannel.bindCommandReader( commandReader, 
streams.getStdInChannel() )
-                : forkChannel.bindCommandReader( commandReader );
+            in = forkChannel.bindCommandReader( commandReader, 
streams.getStdInChannel() );
             in.start();
 
             StreamConsumer stdErrConsumer = new NativeStdErrStreamConsumer( 
reporter );
 
-            out = forkChannel.useStdOut()
-                ? forkChannel.bindEventHandler( eventConsumer, 
streams.getStdOutChannel(), countdownCloseable )
-                : forkChannel.bindEventHandler( stdErrConsumer );
+            out = forkChannel.bindEventHandler( eventConsumer, 
countdownCloseable, streams.getStdOutChannel() );
             out.start();
 
             err = new LineConsumerThread( "std-err-fork-" + forkNumber, 
streams.getStdErrChannel(),
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/LegacyForkChannel.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/LegacyForkChannel.java
index 4ec9962..e030c43 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/LegacyForkChannel.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/extensions/LegacyForkChannel.java
@@ -53,12 +53,6 @@ final class LegacyForkChannel extends ForkChannel
     }
 
     @Override
-    public boolean useStdIn()
-    {
-        return true;
-    }
-
-    @Override
     public boolean useStdOut()
     {
         return true;
@@ -66,32 +60,20 @@ final class LegacyForkChannel extends ForkChannel
 
     @Override
     public CloseableDaemonThread bindCommandReader( @Nonnull CommandReader 
commands,
-                                                    @Nonnull 
WritableByteChannel stdIn )
+                                                    WritableByteChannel stdIn )
     {
         return new StreamFeeder( "std-in-fork-" + getForkChannelId(), stdIn, 
commands );
     }
 
     @Override
-    public CloseableDaemonThread bindCommandReader( @Nonnull CommandReader 
commands )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public CloseableDaemonThread bindEventHandler( @Nonnull StreamConsumer 
consumer,
-                                                   @Nonnull 
ReadableByteChannel stdOut,
-                                                   @Nonnull CountdownCloseable 
countdownCloseable )
+                                                   @Nonnull CountdownCloseable 
countdownCloseable,
+                                                   ReadableByteChannel stdOut )
     {
         return new LineConsumerThread( "std-out-fork-" + getForkChannelId(), 
stdOut, consumer, countdownCloseable );
     }
 
     @Override
-    public CloseableDaemonThread bindEventHandler( @Nonnull StreamConsumer 
consumer )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
     public void close()
     {
     }
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 a917460..d7d0880 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
@@ -89,12 +89,6 @@ final class SurefireForkChannel extends ForkChannel
     }
 
     @Override
-    public boolean useStdIn()
-    {
-        return false;
-    }
-
-    @Override
     public boolean useStdOut()
     {
         return false;
@@ -102,29 +96,16 @@ final class SurefireForkChannel extends ForkChannel
 
     @Override
     public CloseableDaemonThread bindCommandReader( @Nonnull CommandReader 
commands,
-                                                    @Nonnull 
WritableByteChannel stdIn )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public CloseableDaemonThread bindCommandReader( @Nonnull CommandReader 
commands )
+                                                    WritableByteChannel stdIn )
     {
         return new StreamFeeder( "commands-fork-" + getForkChannelId(), 
channel, commands );
     }
 
     @Override
     public CloseableDaemonThread bindEventHandler( @Nonnull StreamConsumer 
consumer,
-                                                   @Nonnull 
ReadableByteChannel stdOut,
-                                                   @Nonnull CountdownCloseable 
countdownCloseable )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    @Override
-    public CloseableDaemonThread bindEventHandler( @Nonnull StreamConsumer 
consumer )
+                                                   @Nonnull CountdownCloseable 
countdownCloseable,
+                                                   ReadableByteChannel stdOut )
     {
-        CountdownCloseable countdownCloseable = new CountdownCloseable( null, 
0 );
         return new LineConsumerThread( "events-fork-" + getForkChannelId(), 
channel, consumer, countdownCloseable );
     }
 
diff --git 
a/maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
 
b/maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
index 4f35684..3b3780b 100644
--- 
a/maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
+++ 
b/maven-surefire-common/src/test/java/org/apache/maven/surefire/extensions/ForkChannelTest.java
@@ -22,9 +22,11 @@ package org.apache.maven.surefire.extensions;
 import 
org.apache.maven.plugin.surefire.booterclient.lazytestprovider.TestLessInputStream;
 import 
org.apache.maven.plugin.surefire.booterclient.lazytestprovider.TestLessInputStream.TestLessInputStreamBuilder;
 import org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory;
+import org.apache.maven.surefire.extensions.util.CountdownCloseable;
 import org.apache.maven.surefire.shared.utils.cli.StreamConsumer;
 import org.junit.Test;
 
+import java.io.Closeable;
 import java.io.IOException;
 import java.net.Socket;
 import java.net.URI;
@@ -54,9 +56,6 @@ public class ForkChannelTest
             assertThat( channel.getForkChannelId() )
                 .isEqualTo( 1 );
 
-            assertThat( channel.useStdIn() )
-                .isFalse();
-
             assertThat( channel.useStdOut() )
                 .isFalse();
 
@@ -79,8 +78,20 @@ public class ForkChannelTest
 
             TestLessInputStreamBuilder builder = new 
TestLessInputStreamBuilder();
             TestLessInputStream commandReader = builder.build();
-            channel.bindCommandReader( commandReader ).start();
-            channel.bindEventHandler( consumer ).start();
+
+            channel.bindCommandReader( commandReader, null ).start();
+
+            final AtomicBoolean isCloseableCalled = new AtomicBoolean();
+            Closeable closeable = new Closeable()
+            {
+                @Override
+                public void close()
+                {
+                    isCloseableCalled.set( true );
+                }
+            };
+            CountdownCloseable cc = new CountdownCloseable( closeable, 1 );
+            channel.bindEventHandler( consumer, cc, null ).start();
 
             SECONDS.sleep( 3L );
 
@@ -93,6 +104,9 @@ public class ForkChannelTest
             assertThat( hasError.get() )
                 .isFalse();
 
+            assertThat( isCloseableCalled.get() )
+                .isTrue();
+
             assertThat( consumer.lines )
                 .hasSize( 1 )
                 .containsOnly( "Hi There!" );
diff --git a/surefire-booter/pom.xml b/surefire-booter/pom.xml
index a0dbd9a..c7129c7 100644
--- a/surefire-booter/pom.xml
+++ b/surefire-booter/pom.xml
@@ -124,6 +124,8 @@
         </dependencies>
         <configuration>
           <argLine>${jvm.args.tests} ${jacoco.agent}</argLine>
+            <useFile>true</useFile>
+            <redirectTestOutputToFile>true</redirectTestOutputToFile>
           <includes>
             <include>**/JUnit4SuiteTest.java</include>
           </includes>
diff --git 
a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkChannel.java
 
b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkChannel.java
index 520c224..40a167d 100644
--- 
a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkChannel.java
+++ 
b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/ForkChannel.java
@@ -61,23 +61,13 @@ public abstract class ForkChannel implements Closeable
     public abstract String getForkNodeConnectionString();
 
     /**
-     * Determines which one of the two <em>bindCommandReader-s</em> to call in 
<em>ForkStarter</em>.
-     * Can be called anytime.
-     *
-     * @return If {@code true}, calling {@link 
#bindCommandReader(CommandReader, WritableByteChannel)} by
-     * <em>ForkStarter</em> and {@link #bindCommandReader(CommandReader)} 
throws {@link UnsupportedOperationException}.
-     * If {@code false}, then opposite.
-     */
-    public abstract boolean useStdIn();
-
-    /**
      * Determines which one of the two <em>bindEventHandler-s</em> to call in 
<em>ForkStarter</em>.
      * Can be called anytime.
      *
-     * @return If {@code true}, the {@link #bindEventHandler(StreamConsumer, 
ReadableByteChannel, CountdownCloseable)}
-     * is called in <em>ForkStarter</em> and {@link 
#bindEventHandler(StreamConsumer)} throws
-     * {@link UnsupportedOperationException}.
-     * If {@code false}, then opposite.
+     * @return If {@code true}, both {@link ReadableByteChannel} and {@link 
CountdownCloseable} must not be null
+     * in {@link #bindEventHandler(StreamConsumer, CountdownCloseable, 
ReadableByteChannel)}. If {@code false} then
+     * both {@link ReadableByteChannel} and {@link CountdownCloseable} have to 
be null
+     * in {@link #bindEventHandler(StreamConsumer, CountdownCloseable, 
ReadableByteChannel)}.
      */
     public abstract boolean useStdOut();
 
@@ -85,45 +75,25 @@ public abstract class ForkChannel implements Closeable
      * Binds command handler to the channel.
      *
      * @param commands command reader, see {@link 
CommandReader#readNextCommand()}
-     * @param stdIn    the standard input stream of the JVM to write the 
encoded commands into it
+     * @param stdIn    optional standard input stream of the JVM to write the 
encoded commands into it
      * @return the thread instance to start up in order to stream out the data
      * @throws IOException if an error in the fork channel
      */
     public abstract CloseableDaemonThread bindCommandReader( @Nonnull 
CommandReader commands,
-                                                             @Nonnull 
WritableByteChannel stdIn )
-        throws IOException;
-
-    /**
-     * Binds command handler to the channel.
-     *
-     * @param commands command reader, see {@link 
CommandReader#readNextCommand()}
-     * @return the thread instance to start up in order to stream out the data
-     * @throws IOException if an error in the fork channel
-     */
-    public abstract CloseableDaemonThread bindCommandReader( @Nonnull 
CommandReader commands )
+                                                             
WritableByteChannel stdIn )
         throws IOException;
 
     /**
      *
      * @param consumer           event consumer
-     * @param stdOut             the standard output stream of the JVM
      * @param countdownCloseable count down of the final call of {@link 
Closeable#close()}
+     * @param stdOut             optional standard output stream of the JVM
      * @return the thread instance to start up in order to stream out the data
      * @throws IOException if an error in the fork channel
      */
     public abstract CloseableDaemonThread bindEventHandler( @Nonnull 
StreamConsumer consumer,
-                                                            @Nonnull 
ReadableByteChannel stdOut,
-                                                            @Nonnull 
CountdownCloseable countdownCloseable )
-        throws IOException;
-
-    /**
-     * Binds event handler to the channel.
-     *
-     * @param consumer event consumer
-     * @return the thread instance to start up in order to stream out the data
-     * @throws IOException if an error in the fork channel
-     */
-    public abstract CloseableDaemonThread bindEventHandler( @Nonnull 
StreamConsumer consumer )
+                                                            @Nonnull 
CountdownCloseable countdownCloseable,
+                                                            
ReadableByteChannel stdOut )
         throws IOException;
 
     /**
diff --git 
a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/CountdownCloseable.java
 
b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/CountdownCloseable.java
index 4bb5272..9818ec9 100644
--- 
a/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/CountdownCloseable.java
+++ 
b/surefire-extensions-api/src/main/java/org/apache/maven/surefire/extensions/util/CountdownCloseable.java
@@ -20,6 +20,7 @@ package org.apache.maven.surefire.extensions.util;
  */
 
 import javax.annotation.Nonnegative;
+import javax.annotation.Nonnull;
 import java.io.Closeable;
 import java.io.IOException;
 
@@ -32,12 +33,8 @@ public final class CountdownCloseable
     private final Closeable closeable;
     private volatile int countdown;
 
-    public CountdownCloseable( Closeable closeable, @Nonnegative int countdown 
)
+    public CountdownCloseable( @Nonnull Closeable closeable, @Nonnegative int 
countdown )
     {
-        if ( closeable == null && countdown > 0 )
-        {
-            throw new IllegalStateException( "closeable is null and countdown 
is " + countdown );
-        }
         this.closeable = closeable;
         this.countdown = countdown;
     }

Reply via email to