You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@maven.apache.org by GitBox <gi...@apache.org> on 2020/07/20 13:49:06 UTC

[GitHub] [maven-surefire] Tibor17 opened a new pull request #308: [SUREFIRE-1827] The console output is not flushed

Tibor17 opened a new pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#issuecomment-661486443


   @rmannibucau 
   I have added two unit tests. But the important thing is the manual test i made. I have expected that you would like to make the same test on your PC. So i changed my commit to 100 millis from previous 200 millis because 100 millis makes the visual effect smooth. So i do not see the business value of config paramter. I would not bother the user with more and more config params because anyway they will be lost. Better if it just works with ideally no new config params. This was my test:
   
           for ( int i = 0; i < 50; i++ )
   ```
           {
               System.out.println( "01234567890123456789012345678901234567890123456789" );
               Thread.sleep(10);
           }
   ```


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] asfgit closed pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308


   


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#issuecomment-661267659


   Can be good to at least support a system property for flush interval and not leak the flush thread (stop the scheduler properly) but otherwise looks good.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#issuecomment-661051683


   Missing the unit tests for this functionality.
   I will work on it tomorrow.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r458276749



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );
+                    }
+                    catch ( Exception e )
+                    {
+                        // cannot do anything about this I/O issue
+                    }
+                }
+                else
+                {
+                    bufferOverflows.set( currentBufferOverflows );
+                }
+            }
+        }, 0L, delayInMillis, MILLISECONDS );
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        try
+        {
+            doPrivileged( new PrivilegedAction<Object>()

Review comment:
       If you care about fine level perf you can likely use the standard pattern (if (sm == null) doShutdown() else doPriviledgedShutdown()). Not sure the 3-4 allocations change much things in this particular case but it is always a bit surprising to see a doPriviledged not conditionned (guess it became a so common pattern than we think less about it now?).




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457868070



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelProcessorFactory.java
##########
@@ -36,8 +36,10 @@
  * @since 3.0.0-M5
  */
 public class LegacyMasterProcessChannelProcessorFactory
-    implements MasterProcessChannelProcessorFactory
+    extends AbstractMasterProcessChannelProcessorFactory
 {
+    private static final int FLUSH_PERIOD_MILLIS = 100;

Review comment:
       Fact is it depends the OS and potentially the tests so having a way to change a good default (>= 150ms IMHO) is good.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r458236542



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );
+                    }
+                    catch ( Exception e )
+                    {
+                        // cannot do anything about this I/O issue
+                    }
+                }
+                else
+                {
+                    bufferOverflows.set( currentBufferOverflows );
+                }
+            }
+        }, 0L, delayInMillis, MILLISECONDS );
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        try
+        {
+            doPrivileged( new PrivilegedAction<Object>()

Review comment:
       See the junit3 ITs. They are with the SecurityManager.
   You always have to do it, even in the ForkedBooter we have priviledged call.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 edited a comment on pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 edited a comment on pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#issuecomment-661486443


   @rmannibucau 
   I have added two unit tests. But the important thing is the manual test i made. I have expected that you would like to make the same test on your PC. So i changed my commit to 100 millis from previous 200 millis because 100 millis makes the visual effect smooth. So i do not see the business value of config paramter. I would not bother the user with more and more config params because anyway they will be lost. Better if it just works with ideally no new config params. This was my test:
   
   ```
           for ( int i = 0; i < 100; i++ )
           {
               System.out.println( "01234567890123456789012345678901234567890123456789" );
               Thread.sleep(10);
           }
   ```


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457869411



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );
+                    }
+                    catch ( Exception e )
+                    {
+                        // cannot do anything about this I/O issue
+                    }
+                }
+                else
+                {
+                    bufferOverflows.set( currentBufferOverflows );
+                }
+            }
+        }, 0L, delayInMillis, MILLISECONDS );
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        try
+        {
+            doPrivileged( new PrivilegedAction<Object>()
+                          {
+                              @Override
+                              public Object run()
+                              {
+                                  flusher.shutdown();

Review comment:
       Maybe call shutdownNow at least and cancel the scheduked task.
   Then calling awaitTermination should be immediate in this case which avoids side effects of this method even if unlikely (= makes it future proof)




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457858940



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelProcessorFactory.java
##########
@@ -36,8 +36,10 @@
  * @since 3.0.0-M5
  */
 public class LegacyMasterProcessChannelProcessorFactory
-    implements MasterProcessChannelProcessorFactory
+    extends AbstractMasterProcessChannelProcessorFactory
 {
+    private static final int FLUSH_PERIOD_MILLIS = 100;

Review comment:
       But it does not make sense. It is not a business feature and it is hidden for the user. The only purpose is that it just works, prints the console, nothing special.




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r458236871



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );

Review comment:
       sure, i will




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r458275537



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );

Review comment:
       I think there is never any reason to not handle the lifecycle of the object you create properly.
   System.exit cleanup order is not deterministic (in particular across JVM and versions) and you literally let a thread leak there assuming the OS cleans it up.
   It also depends your glic version (see https://www.man7.org/linux/man-pages/man2/_exit.2.html).
   So even not technically I would shutdown properly any started thread in the app + here you will not add any latency since it will exit immediately using shutdownnow + awaitTermination (will just do a state check so will be way faster than 100ms).




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] jglick commented on pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
jglick commented on pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#issuecomment-683125415


   Amending #240 IIUC.


----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] eolivelli commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
eolivelli commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457869371



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );
+                    }
+                    catch ( Exception e )
+                    {
+                        // cannot do anything about this I/O issue
+                    }
+                }
+                else
+                {
+                    bufferOverflows.set( currentBufferOverflows );
+                }
+            }
+        }, 0L, delayInMillis, MILLISECONDS );
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        try
+        {
+            doPrivileged( new PrivilegedAction<Object>()
+                          {
+                              @Override
+                              public Object run()
+                              {
+                                  flusher.shutdown();

Review comment:
       +1

##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );

Review comment:
       we can create a constant and save this buffer allocation

##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelProcessorFactory.java
##########
@@ -36,8 +36,10 @@
  * @since 3.0.0-M5
  */
 public class LegacyMasterProcessChannelProcessorFactory
-    implements MasterProcessChannelProcessorFactory
+    extends AbstractMasterProcessChannelProcessorFactory
 {
+    private static final int FLUSH_PERIOD_MILLIS = 100;

Review comment:
       I can see a use case of having in CI this value to be set to "infinite" in order to save resources.
   But adding a new knob means that we will have to maintain it.
   I am leaning toward keeping an hardcoded constant, but I don't feel so strong about it.

##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );
+    }
+
+    protected void schedulePeriodicFlusher( int delayInMillis, final WritableBufferedByteChannel channel  )
+    {
+        final AtomicLong bufferOverflows = new AtomicLong();
+        flusher.scheduleWithFixedDelay( new Runnable()
+        {
+            @Override
+            public void run()
+            {
+                long currentBufferOverflows = channel.countBufferOverflows();
+                // optimization: flush the Channel only if the buffer has not overflew after last period of time
+                if ( bufferOverflows.get() == currentBufferOverflows )
+                {
+                    try
+                    {
+                        channel.write( ByteBuffer.allocate( 0 ) );
+                    }
+                    catch ( Exception e )
+                    {
+                        // cannot do anything about this I/O issue
+                    }
+                }
+                else
+                {
+                    bufferOverflows.set( currentBufferOverflows );
+                }
+            }
+        }, 0L, delayInMillis, MILLISECONDS );
+    }
+
+    @Override
+    public void close() throws IOException
+    {
+        try
+        {
+            doPrivileged( new PrivilegedAction<Object>()

Review comment:
       just  for curiosity, why are you using "doPrivileged" ?




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] rmannibucau commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
rmannibucau commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457868926



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );

Review comment:
       Shouldnt be daemon, there is no reason and can only hide bugs.
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] olamy commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
olamy commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r457827367



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/LegacyMasterProcessChannelProcessorFactory.java
##########
@@ -36,8 +36,10 @@
  * @since 3.0.0-M5
  */
 public class LegacyMasterProcessChannelProcessorFactory
-    implements MasterProcessChannelProcessorFactory
+    extends AbstractMasterProcessChannelProcessorFactory
 {
+    private static final int FLUSH_PERIOD_MILLIS = 100;

Review comment:
       would be good to have this configurable. At least Integer.getInteger(""whatever name you like", 100)
   




----------------------------------------------------------------
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:
users@infra.apache.org



[GitHub] [maven-surefire] Tibor17 commented on a change in pull request #308: [SUREFIRE-1827] The console output is not flushed

Posted by GitBox <gi...@apache.org>.
Tibor17 commented on a change in pull request #308:
URL: https://github.com/apache/maven-surefire/pull/308#discussion_r458239726



##########
File path: surefire-booter/src/main/java/org/apache/maven/surefire/booter/spi/AbstractMasterProcessChannelProcessorFactory.java
##########
@@ -0,0 +1,106 @@
+package org.apache.maven.surefire.booter.spi;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import org.apache.maven.surefire.api.util.internal.WritableBufferedByteChannel;
+import org.apache.maven.surefire.spi.MasterProcessChannelProcessorFactory;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.security.AccessControlException;
+import java.security.PrivilegedAction;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.atomic.AtomicLong;
+
+import static java.security.AccessController.doPrivileged;
+import static java.util.concurrent.Executors.newScheduledThreadPool;
+import static java.util.concurrent.TimeUnit.MILLISECONDS;
+import static org.apache.maven.surefire.api.util.internal.DaemonThreadFactory.newDaemonThreadFactory;
+
+/**
+ * Default implementation of {@link MasterProcessChannelProcessorFactory}.
+ */
+public abstract class AbstractMasterProcessChannelProcessorFactory
+    implements MasterProcessChannelProcessorFactory
+{
+    private static final String STREAM_FLUSHER = "surefire-forkedjvm-stream-flusher";
+    private final ScheduledExecutorService flusher;
+
+    public AbstractMasterProcessChannelProcessorFactory()
+    {
+        flusher = newScheduledThreadPool( 1, newDaemonThreadFactory( STREAM_FLUSHER ) );

Review comment:
       The daemon will be safely stopped when we call `System.exit()` in `ForkedBooter`.
   This principle was used even before i entered the project.
   It will guarantee that the thread would not prolong the execution time.
   We were working with Jonathan Bell on fast JVM startup and teardown and we made the teardown from 200 minnils to 40.




----------------------------------------------------------------
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:
users@infra.apache.org