/** task which fails if the given PID is not running */ public static SshEffectorTaskFactory<?> requirePidRunning(Integer pid) { return codePidRunning(pid).summary("PID "+pid+" is-running check (required)").requiringExitCodeZero("Process with PID "+pid+" is required to be running"); }
/** as {@link #codePidRunning(Integer)} but returning boolean */ public static SshEffectorTaskFactory<Boolean> isPidRunning(Integer pid) { return codePidRunning(pid).summary("PID "+pid+" is-running check (boolean)").returning(new Function<ProcessTaskWrapper<?>, Boolean>() { @Override public Boolean apply(@Nullable ProcessTaskWrapper<?> input) { return Integer.valueOf(0).equals(input.getExitCode()); } }); }
@Test(groups="Integration") public void testNonRunningPid() { ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.codePidRunning(99999)); Assert.assertNotEquals(t.getTask().getUnchecked(), 0); Assert.assertNotEquals(t.getExitCode(), 0); ProcessTaskWrapper<Boolean> t2 = submit(SshEffectorTasks.isPidRunning(99999)); Assert.assertFalse(t2.getTask().getUnchecked()); }
@Test(groups="Integration") public void testRunningPid() { ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.codePidRunning(getMyPid())); Assert.assertEquals(t.getTask().getUnchecked(), (Integer)0); ProcessTaskWrapper<Boolean> t2 = submit(SshEffectorTasks.isPidRunning(getMyPid())); Assert.assertTrue(t2.getTask().getUnchecked()); }
protected void checkIsRunningAndStops(Entity mysql, SshMachineLocation lh) { Integer pid = getPid(mysql); Assert.assertNotNull(pid, "PID should be set as an attribute (or getPid() overridden to supply)"); Entities.submit(app, SshEffectorTasks.requirePidRunning(pid).machine(lh).newTask() ).get(); app.stop(); // let the kill -1 take effect Time.sleep(Duration.ONE_SECOND); // and assert it has died log.info("mysql in pid "+pid+" should be dead now"); // (app has stopped, so submit on mgmt context) ProcessTaskWrapper<Integer> t = SshEffectorTasks.codePidRunning(pid).machine(lh).newTask(); mgmt.getExecutionManager().submit(t); Assert.assertNotEquals(t.block().getExitCode(), 0); } }