[1/2] git commit: [SUREFIRE-946] prevent hanging main process if forked process was killed (softly)

2013-01-21 Thread krosenvold
[SUREFIRE-946] prevent hanging main process if forked process was killed 
(softly)


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

Branch: refs/heads/master
Commit: 463f37b30dcc59de7c8550774c4dff19c96112fa
Parents: 9cd2acb
Author: agudian andreas.gud...@gmail.com
Authored: Sat Jan 5 21:13:12 2013 +0100
Committer: Kristian Rosenvold krosenv...@apache.org
Committed: Mon Jan 21 18:10:36 2013 +0100

--
 .../plugin/surefire/booterclient/ForkStarter.java  |   20 +-
 .../lazytestprovider/TestProvidingInputStream.java |  248 +++---
 .../surefire/booterclient/output/ForkClient.java   |   12 -
 pom.xml|2 +-
 .../maven/surefire/booter/ForkingRunListener.java  |2 -
 .../apache/maven/surefire/booter/ForkedBooter.java |   74 +
 .../maven/surefire/its/CrashDetectionIT.java   |5 +
 .../maven/surefire/its/fixture/MavenLauncher.java  |6 +-
 .../surefire/its/fixture/SurefireLauncher.java |7 +-
 ...Surefire946KillMainProcessInReusableForkIT.java |   71 
 .../test/java/junit44/environment/BasicTest.java   |8 +-
 .../pom.xml|   64 
 .../test/java/junit44/environment/Basic01Test.java |   26 ++
 .../test/java/junit44/environment/Basic02Test.java |   26 ++
 .../test/java/junit44/environment/Basic03Test.java |   26 ++
 .../test/java/junit44/environment/Basic04Test.java |   26 ++
 .../test/java/junit44/environment/Basic05Test.java |   26 ++
 .../test/java/junit44/environment/Basic06Test.java |   26 ++
 .../test/java/junit44/environment/Basic07Test.java |   26 ++
 .../test/java/junit44/environment/Basic08Test.java |   26 ++
 .../test/java/junit44/environment/Basic09Test.java |   26 ++
 .../test/java/junit44/environment/Basic10Test.java |   26 ++
 .../surefire-946-self-destruct-plugin/pom.xml  |   51 +++
 .../surefire/selfdestruct/SelfDestructMojo.java|  142 
 24 files changed, 761 insertions(+), 211 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/463f37b3/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
--
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 892c6a9..164f8c7 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
@@ -86,7 +86,7 @@ public class ForkStarter
  * Closes an InputStream
  */
 private final class InputStreamCloser
-extends Thread
+implements Runnable
 {
 private InputStream testProvidingInputStream;
 
@@ -95,8 +95,7 @@ public class ForkStarter
 this.testProvidingInputStream = testProvidingInputStream;
 }
 
-@Override
-public void run()
+public synchronized void run()
 {
 if ( testProvidingInputStream != null )
 {
@@ -108,6 +107,7 @@ public class ForkStarter
 {
 // ignore
 }
+testProvidingInputStream = null;
 }
 }
 }
@@ -412,16 +412,18 @@ public class ForkStarter
  
startupConfiguration.getClassLoaderConfiguration(),
  
startupConfiguration.isShadefire(), threadNumber );
 
-final InputStreamCloser inputStreamCloserHook;
+final InputStreamCloser inputStreamCloser;
+final Thread inputStreamCloserHook;
 if ( testProvidingInputStream != null )
 {
 testProvidingInputStream.setFlushReceiverProvider( cli );
-
-inputStreamCloserHook = new InputStreamCloser( 
testProvidingInputStream );
+inputStreamCloser = new InputStreamCloser( 
testProvidingInputStream );
+inputStreamCloserHook = new Thread( inputStreamCloser );
 addShutDownHook( inputStreamCloserHook );
 }
 else
 {
+inputStreamCloser = null;
 inputStreamCloserHook = null;
 }
 
@@ -446,7 +448,7 @@ public class ForkStarter
 final int timeout = forkedProcessTimeoutInSeconds  0 ? 
forkedProcessTimeoutInSeconds : 0;
 final int result =
 CommandLineUtils.executeCommandLine( cli, 

git commit: [SUREFIRE-946] prevent hanging main process if forked process was killed (softly)

2013-01-09 Thread krosenvold
Updated Branches:
  refs/heads/master 350dd6fd7 - e54dbd810


[SUREFIRE-946] prevent hanging main process if forked process was killed 
(softly)

Fixed with extended IT


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

Branch: refs/heads/master
Commit: e54dbd810f62fe723800f11279b881bff244b707
Parents: 350dd6f
Author: agudian andreas.gud...@gmail.com
Authored: Sat Jan 5 21:13:12 2013 +0100
Committer: Kristian Rosenvold krosenv...@apache.org
Committed: Wed Jan 9 18:24:38 2013 +0100

--
 .../plugin/surefire/booterclient/ForkStarter.java  |  140 +++
 .../lazytestprovider/TestProvidingInputStream.java |   29 ++-
 .../surefire/booterclient/output/ForkClient.java   |   22 ++-
 .../maven/surefire/booter/ForkingRunListener.java  |3 +
 .../apache/maven/surefire/booter/ForkedBooter.java |   74 ++--
 .../maven/surefire/its/CrashDetectionIT.java   |7 +-
 6 files changed, 215 insertions(+), 60 deletions(-)
--


http://git-wip-us.apache.org/repos/asf/maven-surefire/blob/e54dbd81/maven-surefire-common/src/main/java/org/apache/maven/plugin/surefire/booterclient/ForkStarter.java
--
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 620dfd4..892c6a9 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
@@ -21,6 +21,8 @@ package org.apache.maven.plugin.surefire.booterclient;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.security.AccessControlException;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
@@ -36,6 +38,7 @@ import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
+
 import org.apache.maven.plugin.surefire.AbstractSurefireMojo;
 import org.apache.maven.plugin.surefire.CommonReflector;
 import org.apache.maven.plugin.surefire.StartupReportConfiguration;
@@ -63,14 +66,13 @@ import org.apache.maven.surefire.report.StackTraceWriter;
 import org.apache.maven.surefire.suite.RunResult;
 import org.apache.maven.surefire.util.DefaultScanResult;
 
-
 /**
  * Starts the fork or runs in-process.
  * p/
  * Lives only on the plugin-side (not present in remote vms)
  * p/
  * Knows how to fork new vms and also how to delegate non-forking invocation 
to SurefireStarter directly
- *
+ * 
  * @author Jason van Zyl
  * @author Emmanuel Venisse
  * @author Brett Porter
@@ -80,6 +82,36 @@ import org.apache.maven.surefire.util.DefaultScanResult;
  */
 public class ForkStarter
 {
+/**
+ * Closes an InputStream
+ */
+private final class InputStreamCloser
+extends Thread
+{
+private InputStream testProvidingInputStream;
+
+public InputStreamCloser( InputStream testProvidingInputStream )
+{
+this.testProvidingInputStream = testProvidingInputStream;
+}
+
+@Override
+public void run()
+{
+if ( testProvidingInputStream != null )
+{
+try
+{
+testProvidingInputStream.close();
+}
+catch ( IOException e )
+{
+// ignore
+}
+}
+}
+}
+
 private final int forkedProcessTimeoutInSeconds;
 
 private final ProviderConfiguration providerConfiguration;
@@ -105,7 +137,6 @@ public class ForkStarter
 }
 };
 
-
 public ForkStarter( ProviderConfiguration providerConfiguration, 
StartupConfiguration startupConfiguration,
 ForkConfiguration forkConfiguration, int 
forkedProcessTimeoutInSeconds,
 StartupReportConfiguration startupReportConfiguration )
@@ -167,8 +198,9 @@ public class ForkStarter
 {
 
 ArrayListFutureRunResult results = new 
ArrayListFutureRunResult( forkCount );
-ExecutorService executorService = new ThreadPoolExecutor( forkCount, 
forkCount, 60, TimeUnit.SECONDS,
-  new 
ArrayBlockingQueueRunnable( forkCount ) );
+ExecutorService executorService =
+new ThreadPoolExecutor( forkCount,