FileDocCategorySizeDatePackage
ProcessDestroyerTest.javaAPI DocApache Ant 1.702598Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.taskdefs

ProcessDestroyerTest

public class ProcessDestroyerTest extends TestCase

Fields Summary
Constructors Summary
public ProcessDestroyerTest(String arg0)
Constructor for ProcessDestroyerTest.

param
arg0

        super(arg0);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        new ProcessDestroyerTest("testProcessDestroyer").testProcessDestroyer();
        try{
            Thread.sleep(60000);
        }catch(InterruptedException ie){
            ie.printStackTrace();
        }
    
public voidtestProcessDestroyer()

        if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
            return;
        }

        try {
            ProcessDestroyer processDestroyer = new ProcessDestroyer();
            Process process =
                Runtime.getRuntime().exec(
                    "java -cp "
                        + System.getProperty("java.class.path")
                        + " "
                        + getClass().getName());

            assertFalse("Not registered as shutdown hook",
                        processDestroyer.isAddedAsShutdownHook());

            processDestroyer.add(process);

            assertTrue("Registered as shutdown hook",
                       processDestroyer.isAddedAsShutdownHook());
            try {
                process.destroy();
            } finally {
                processDestroyer.remove(process);
            }

            assertFalse("Not registered as shutdown hook",
                        processDestroyer.isAddedAsShutdownHook());
        } catch (IOException e) {
            e.printStackTrace();
        }