/** * Build the process to execute when the service is started * @param commandList list of commands is inserted on the front * @param env environment variables above those generated by * @throws IOException IO problems */ public void build(Map<String, String> env, List<String> commandList) throws IOException { assert process == null; process = new LongLivedProcess(getName(), processLog, commandList); process.setLifecycleCallback(this); //set the env variable mapping process.putEnvMap(env); }
public Integer getExitCode() { return process.getExitCode(); }
public int getExitCodeSignCorrected() { Integer exitCode = process.getExitCodeSignCorrected(); if (exitCode == null) return -1; return exitCode; }
@Test public void testExitCodes() throws Throwable { SliderTestUtils.skipOnWindows(); initProcess(commandFactory.exitFalse()); process.start(); //in-thread wait process.run(); //here stopped assertFalse(process.isRunning()); int exitCode = process.getExitCode(); assertTrue(exitCode != 0); int corrected = process.getExitCodeSignCorrected(); assertEquals(1, corrected); }
@Test public void testSetenv() throws Throwable { String var = "TEST_RUN"; String val = "TEST-RUN-ENV-VALUE"; initProcess(commandFactory.env()); process.setEnv(var, val); process.start(); //in-thread wait process.run(); //here stopped assertTrue("process stop callback not received", stopped); assertEquals(0, process.getExitCode().intValue()); assertStringInOutput(val, getFinalOutput()); }
private LongLivedProcess initProcess(List<String> commands) { process = new LongLivedProcess(name.getMethodName(), log, commands); process.setLifecycleCallback(this); // increase the line limit to accommodate containers with long list of envs process.setRecentLineLimit(640); return process; }
@Test public void testEcho() throws Throwable { SliderTestUtils.skipOnWindows(); String echoText = "hello, world"; initProcess(commandFactory.echo(echoText)); process.start(); //in-thread wait process.run(); //here stopped assertTrue("process stop callback not received", stopped); assertEquals(0, process.getExitCode().intValue()); assertStringInOutput(echoText, getFinalOutput()); }
if (finalOutput) { finishedOutput = isFinalOutputProcessed(); } else { finishedOutput = !isRecentOutputEmpty(); return getRecentOutput();
/** * Get the recent output from the process, or [] if not defined * @return a possibly empty list */ public List<String> getRecentOutput() { return process != null ? process.getRecentOutput() : new LinkedList<String>(); }
private void stopForkedProcess() { if (process != null) { process.stop(); } }
/** * Stop the process if it is running. * This will trigger an application completion event with the given exit code */ public void stop() { if (!isRunning()) { return; } process.destroy(); }
@Override //AbstractService protected void serviceStart() throws Exception { if (process == null) { throw new ServiceStateException("Process not yet configured"); } //now spawn the process -expect updates via callbacks process.start(); }
/** * Bulk set the environment from a map. This does * not replace the existing environment, just extend it/overwrite single * entries. * @param map map to add */ public void putEnvMap(Map<String, String> map) { for (Map.Entry<String, String> entry : map.entrySet()) { String val = entry.getValue(); String key = entry.getKey(); setEnv(key, val); } }
public void setRecentLineLimit(int limit) { process.setRecentLineLimit(limit); }
@Test public void testExitCodes() throws Throwable { SliderTestUtils.skipOnWindows(); initProcess(commandFactory.exitFalse()); process.start(); //in-thread wait process.run(); //here stopped assertFalse(process.isRunning()); int exitCode = process.getExitCode(); assertTrue(exitCode != 0); int corrected = process.getExitCodeSignCorrected(); assertEquals(1, corrected); }
@Test public void testSetenv() throws Throwable { String var = "TEST_RUN"; String val = "TEST-RUN-ENV-VALUE"; initProcess(commandFactory.env()); process.setEnv(var, val); process.start(); //in-thread wait process.run(); //here stopped assertTrue("process stop callback not received", stopped); assertEquals(0, process.getExitCode().intValue()); assertStringInOutput(val, getFinalOutput()); }
private LongLivedProcess initProcess(List<String> commands) { process = new LongLivedProcess(name.getMethodName(), log, commands); process.setLifecycleCallback(this); // increase the line limit to accommodate containers with long list of envs process.setRecentLineLimit(640); return process; }
@Test public void testEcho() throws Throwable { SliderTestUtils.skipOnWindows(); String echoText = "hello, world"; initProcess(commandFactory.echo(echoText)); process.start(); //in-thread wait process.run(); //here stopped assertTrue("process stop callback not received", stopped); assertEquals(0, process.getExitCode().intValue()); assertStringInOutput(echoText, getFinalOutput()); }
if (finalOutput) { finishedOutput = isFinalOutputProcessed(); } else { finishedOutput = !isRecentOutputEmpty(); return getRecentOutput();
/** * Get the recent output from the process, or [] if not defined * @return a possibly empty list */ public List<String> getRecentOutput() { return process != null ? process.getRecentOutput() : new LinkedList<String>(); }