Tibor17 commented on a change in pull request #240: [SUREFIRE-1658] TCP/IP
Channel for forked Surefire JVM. Extensions API and SPI. Polymorphism for
remote and local process communication.
URL: https://github.com/apache/maven-surefire/pull/240#discussion_r381513125
##########
File path:
maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
##########
@@ -602,38 +615,40 @@ private RunResult fork( Object testSet,
PropertiesWrapper providerProperties, Fo
}
ThreadedStreamConsumer eventConsumer = new ThreadedStreamConsumer(
forkClient );
- CloseableCloser closer = new CloseableCloser( forkNumber,
eventConsumer, requireNonNull( commandInputStream ) );
+ closer.addCloseable( eventConsumer );
log.debug( "Forking command line: " + cli );
Integer result = null;
RunResult runResult = null;
SurefireBooterForkException booterForkException = null;
- StreamFeeder in = null;
- LineConsumerThread out = null;
- LineConsumerThread err = null;
+ CloseableDaemonThread in = null;
+ CloseableDaemonThread out = null;
+ CloseableDaemonThread err = null;
DefaultReporterFactory reporter =
forkClient.getDefaultReporterFactory();
currentForkClients.add( forkClient );
- CountdownCloseable countdownCloseable = new CountdownCloseable(
eventConsumer, 2 );
+ CountdownCloseable countdownCloseable =
+ new CountdownCloseable( eventConsumer, 1 + (
forkChannel.useStdOut() ? 1 : 0 ) );
try ( CommandlineExecutor exec = new CommandlineExecutor( cli,
countdownCloseable ) )
{
- // default impl of the extension - solves everything including the
encoder/decoder, Process starter,
- // adaptation of the streams to pipes and sockets
- // non-default impl may use another classes and not the
LineConsumerThread, StreamFeeder - freedom
- // BEGIN: beginning of the call of the extension
CommandlineStreams streams = exec.execute();
closer.addCloseable( streams );
- in = new StreamFeeder( "std-in-fork-" + forkNumber,
streams.getStdInChannel(), commandInputStream );
+
+ forkChannel.connectToClient();
+
+ in = forkChannel.bindCommandReader( commandReader,
streams.getStdInChannel() );
in.start();
- out = new LineConsumerThread( "std-out-fork-" + forkNumber,
streams.getStdOutChannel(),
- eventConsumer, countdownCloseable );
+
+ EventHandler stdErrConsumer = new NativeStdErrStreamConsumer(
reporter );
+
+ out = forkChannel.bindEventHandler( eventConsumer,
countdownCloseable, streams.getStdOutChannel() );
out.start();
- NativeStdErrStreamConsumer stdErrConsumer = new
NativeStdErrStreamConsumer( reporter );
+
err = new LineConsumerThread( "std-err-fork-" + forkNumber,
streams.getStdErrChannel(),
Review comment:
See the code deeper because the API avoid mixing the clients. The object
ForkChanel is instantiated, then the conection string is provided to the client
via properties file and the fork JVM has to use this connection string;
otherwise the client connects to nowhere and would not work either. We want to
bind to the local loopback `127.0.0.1` and port 0 on server socket which gives
a random but unused port and the connection string contains this port. We are
accepting only one connection and so nobody else can connect. So we bind to the
random port by the server socket which takes 8 milliseconds and the client
connects right after.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services