Search in sources :

Example 1 with StartedProcess

use of org.zeroturnaround.exec.StartedProcess in project ninja by ninjaframework.

the class RunClassInSeparateJvmMachineTest method multipleRestartsReallyQuickly.

@Test
public void multipleRestartsReallyQuickly() throws Exception {
    RunClassInSeparateJvmMachine rcsjm = new RunClassInSeparateJvmMachine("FakeDaemon", FakeDaemonMain.class.getName(), getOurClassPath(), Collections.EMPTY_LIST, new File("."));
    // override output so we can capture it
    final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
    rcsjm.setOutput(baos1);
    rcsjm.restart();
    StartedProcess startedProcess1 = rcsjm.getActiveProcess();
    rcsjm.restart();
    StartedProcess startedProcess2 = rcsjm.getActiveProcess();
    rcsjm.restart();
    StartedProcess startedProcess3 = rcsjm.getActiveProcess();
    rcsjm.restart();
    StartedProcess startedProcess4 = rcsjm.getActiveProcess();
    assertTrue(isAlive(startedProcess4.getProcess()));
    assertFalse(isAlive(startedProcess1.getProcess()));
    assertFalse(isAlive(startedProcess2.getProcess()));
    assertFalse(isAlive(startedProcess3.getProcess()));
    assertFalse(startedProcess1.equals(startedProcess2));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) StartedProcess(org.zeroturnaround.exec.StartedProcess) Test(org.junit.Test)

Example 2 with StartedProcess

use of org.zeroturnaround.exec.StartedProcess in project ninja by ninjaframework.

the class RunClassInSeparateJvmMachineTest method startProcess.

@Test
public void startProcess() throws Exception {
    RunClassInSeparateJvmMachine rcsjm = new RunClassInSeparateJvmMachine("FakeDaemon", FakeDaemonMain.class.getName(), getOurClassPath(), Collections.EMPTY_LIST, new File("."));
    // override output so we can capture it
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    rcsjm.setOutput(baos);
    StartedProcess startedProcess = rcsjm.startProcess();
    assertTrue(isAlive(startedProcess.getProcess()));
    waitOrTimeout(fakeDaemonCondition(baos), Timeout.timeout(Duration.millis(10000)));
    startedProcess.getProcess().destroy();
    ProcessResult processResult = startedProcess.getFuture().get();
}
Also used : ProcessResult(org.zeroturnaround.exec.ProcessResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) StartedProcess(org.zeroturnaround.exec.StartedProcess) Test(org.junit.Test)

Example 3 with StartedProcess

use of org.zeroturnaround.exec.StartedProcess in project ninja by ninjaframework.

the class RunClassInSeparateJvmMachineTest method restart.

@Test
public void restart() throws Exception {
    RunClassInSeparateJvmMachine rcsjm = new RunClassInSeparateJvmMachine("FakeDaemon", FakeDaemonMain.class.getName(), getOurClassPath(), Collections.EMPTY_LIST, new File("."));
    // override output so we can capture it
    final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
    rcsjm.setOutput(baos1);
    rcsjm.restart();
    StartedProcess startedProcess1 = rcsjm.getActiveProcess();
    assertTrue(isAlive(startedProcess1.getProcess()));
    waitOrTimeout(fakeDaemonCondition(baos1), Timeout.timeout(Duration.millis(10000)));
    // override output so we can capture it
    final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
    rcsjm.setOutput(baos2);
    rcsjm.restart();
    StartedProcess startedProcess2 = rcsjm.getActiveProcess();
    assertTrue(isAlive(startedProcess2.getProcess()));
    assertFalse(isAlive(startedProcess1.getProcess()));
    assertFalse(startedProcess1.equals(startedProcess2));
    waitOrTimeout(fakeDaemonCondition(baos2), Timeout.timeout(Duration.millis(10000)));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) StartedProcess(org.zeroturnaround.exec.StartedProcess) Test(org.junit.Test)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)3 Test (org.junit.Test)3 StartedProcess (org.zeroturnaround.exec.StartedProcess)3 ProcessResult (org.zeroturnaround.exec.ProcessResult)1