1 17 18 21 package org.apache.tools.ant.taskdefs; 22 23 import java.io.IOException ; 24 25 import org.apache.tools.ant.util.JavaEnvUtils; 26 27 import junit.framework.TestCase; 28 29 31 public class ProcessDestroyerTest extends TestCase { 32 33 37 public ProcessDestroyerTest(String arg0) { 38 super(arg0); 39 } 40 41 public void testProcessDestroyer(){ 42 if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1) 43 || JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) { 44 return; 45 } 46 47 try { 48 ProcessDestroyer processDestroyer = new ProcessDestroyer(); 49 Process process = 50 Runtime.getRuntime().exec( 51 "java -cp " 52 + System.getProperty("java.class.path") 53 + " " 54 + getClass().getName()); 55 56 assertFalse("Not registered as shutdown hook", 57 processDestroyer.isAddedAsShutdownHook()); 58 59 processDestroyer.add(process); 60 61 assertTrue("Registered as shutdown hook", 62 processDestroyer.isAddedAsShutdownHook()); 63 try { 64 process.destroy(); 65 } finally { 66 processDestroyer.remove(process); 67 } 68 69 assertFalse("Not registered as shutdown hook", 70 processDestroyer.isAddedAsShutdownHook()); 71 } catch (IOException e) { 72 e.printStackTrace(); 73 } 74 } 75 76 public static void main(String [] args){ 77 new ProcessDestroyerTest("testProcessDestroyer").testProcessDestroyer(); 78 try{ 79 Thread.sleep(60000); 80 }catch(InterruptedException ie){ 81 ie.printStackTrace(); 82 } 83 } 84 } 85 | Popular Tags |