RunClassInSeparateJvmMachine { public synchronized void restart() { restarting.set(true); try { if (this.activeProcess != null) { log.debug("Attempting to destroy previous {} process", name); this.activeProcess.getProcess().destroy(); log.debug("Waiting for previous {} process to terminate", name); ProcessResult result = this.activeProcess.getFuture().get(); } log.debug("Starting new {}", name); this.activeProcess = startProcess(); } catch (ExecutionException | InterruptedException | IOException e) { log.error("Something fishy happenend. Unable to cleanly restart {}!", name, e); log.error("You'll probably need to restart maven?"); } finally { restarting.set(false); } } RunClassInSeparateJvmMachine(
            String name,
            String classNameWithMainToRun,
            List<String> classpath, 
            List<String> jvmArguments,
            File mavenBaseDir);  RunClassInSeparateJvmMachine(
            String name,
            String classNameWithMainToRun,
            String classpath, 
            List<String> jvmArguments,
            File mavenBaseDir); OutputStream getOutput(); void setOutput(OutputStream output); StartedProcess getActiveProcess(); void setActiveProcess(StartedProcess activeProcess); synchronized void restart();  }
@Test public void restart() throws Exception { RunClassInSeparateJvmMachine rcsjm = new RunClassInSeparateJvmMachine ( "FakeDaemon", FakeDaemonMain.class.getName(), getOurClassPath(), Collections.EMPTY_LIST, new File(".") ); 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))); 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))); }