Repository: maven-surefire
Updated Branches:
  refs/heads/master 572954801 -> 179abbf02


[SUREFIRE-1333] Process pending events from forked process after exited and 
then finish forked Thread.


Project: http://git-wip-us.apache.org/repos/asf/maven-surefire/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-surefire/commit/179abbf0
Tree: http://git-wip-us.apache.org/repos/asf/maven-surefire/tree/179abbf0
Diff: http://git-wip-us.apache.org/repos/asf/maven-surefire/diff/179abbf0

Branch: refs/heads/master
Commit: 179abbf026902e44b1d95f7ef41b69bdb24434df
Parents: 5729548
Author: Tibor17 <tibo...@lycos.com>
Authored: Tue Feb 14 01:26:24 2017 +0100
Committer: Tibor17 <tibo...@lycos.com>
Committed: Tue Feb 14 01:26:24 2017 +0100

----------------------------------------------------------------------
 .../output/ThreadedStreamConsumer.java          | 30 +++++++++++++++-----
 1 file changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/179abbf0/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
----------------------------------------------------------------------
diff --git 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
index 71831c0..c7d39ae 100644
--- 
a/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
+++ 
b/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/output/ThreadedStreamConsumer.java
@@ -39,7 +39,9 @@ public final class ThreadedStreamConsumer
 {
     private static final String END_ITEM = "";
 
-    private static final int ITEM_LIMIT_BEFORE_SLEEP = 10000;
+    private static final int ITEM_LIMIT_BEFORE_SLEEP = 10 * 1000;
+
+    private static final long CLOSE_TIMEOUT_MILLIS = 5 * 60 * 1000L;
 
     private final BlockingQueue<String> items = new 
ArrayBlockingQueue<String>( ITEM_LIMIT_BEFORE_SLEEP );
 
@@ -47,7 +49,7 @@ public final class ThreadedStreamConsumer
 
     private final Pumper pumper;
 
-    private volatile boolean closed;
+    private volatile boolean stop;
 
     final class Pumper
             implements Runnable
@@ -74,7 +76,7 @@ public final class ThreadedStreamConsumer
          */
         public void run()
         {
-            while ( !ThreadedStreamConsumer.this.closed )
+            while ( !ThreadedStreamConsumer.this.stop )
             {
                 try
                 {
@@ -112,7 +114,7 @@ public final class ThreadedStreamConsumer
 
     public void consumeLine( String s )
     {
-        if ( closed && !thread.isAlive() )
+        if ( stop && !thread.isAlive() )
         {
             items.clear();
             return;
@@ -132,17 +134,25 @@ public final class ThreadedStreamConsumer
     public void close()
             throws IOException
     {
+        if ( stop )
+        {
+            return;
+        }
+
         try
         {
-            closed = true;
             items.put( END_ITEM );
-            thread.join();
+            thread.join( CLOSE_TIMEOUT_MILLIS );
         }
         catch ( InterruptedException e )
         {
             currentThread().interrupt();
             throw new IOException( e );
         }
+        finally
+        {
+            stop = true;
+        }
 
         if ( pumper.hasErrors() )
         {
@@ -150,8 +160,14 @@ public final class ThreadedStreamConsumer
         }
     }
 
+    /**
+     * Compared item with {@link #END_ITEM} by identity.
+     *
+     * @param item    element from <code>items</code>
+     * @return <tt>true</tt> if tail of the queue
+     */
     private boolean shouldStopQueueing( String item )
     {
-        return closed && item == END_ITEM;
+        return item == END_ITEM;
     }
 }

Reply via email to