package com.netflix.priam.utils;

import java.io.IOException;

import org.junit.Test;

import junit.framework.Assert;

public class SystemUtilsTest
{
    @Test
    public void logProcessOutput_BadApp() throws IOException, InterruptedException
    {
        Process p = null;
        try
        {
            p = new ProcessBuilder("ls", "/tmppppp").start();
            Thread.sleep(100);
            Assert.assertFalse(0 == p.exitValue());
            SystemUtils.logProcessOutput(p);
        }
        catch(IOException ioe)
        {
            if(p!=null)
                SystemUtils.logProcessOutput(p);
        }
    }

    /**
     * note: this will succeed on a *nix machine, unclear about anything else...
     */
    @Test
    public void logProcessOutput_GoodApp() throws IOException, InterruptedException
    {
        Process p = new ProcessBuilder("true").start();
        Thread.sleep(100);
        Assert.assertEquals(0, p.exitValue());
        SystemUtils.logProcessOutput(p);
    }
}

@@ -364,32 +364,42 @@
         
-Thread.sleep(100
+int exitValue = p.waitFor(
 );%0A     
@@ -422,21 +422,18 @@
 sert
-Fals
+Tru
 e(0 
-=
+!
 = 
-p.
 exit
@@ -429,34 +429,32 @@
 e(0 != exitValue
-()
 );%0A            S
@@ -891,24 +891,34 @@
     
-Thread.sleep(100
+int exitValue = p.waitFor(
 );%0A 
@@ -947,18 +947,16 @@
 uals(0, 
-p.
 exitValu
@@ -956,18 +956,16 @@
 xitValue
-()
 );%0A     

use Process#waitFor instead of Thread#sleep