### Question:
SshEffectorTasks { public static SshEffectorTaskFactory<?> requirePidFromFileRunning(String pidFile) { return codePidFromFileRunning(pidFile) .summary("PID file "+pidFile+" is-running check (required)") .requiringExitCodeZero("Process with PID from file "+pidFile+" is required to be running"); }  static SshEffectorTaskFactory<Integer> ssh(SshMachineLocation machine, String ...commands); static SshEffectorTaskFactory<Integer> ssh(String ...commands); static SshEffectorTaskFactory<Integer> ssh(List<String> commands); static SshPutTaskFactory put(String remoteFile); static SshFetchEffectorTaskFactory fetch(String remoteFile); static SshEffectorTaskFactory<Integer> codePidRunning(Integer pid); static SshEffectorTaskFactory<?> requirePidRunning(Integer pid); static SshEffectorTaskFactory<Boolean> isPidRunning(Integer pid); static SshEffectorTaskFactory<Integer> codePidFromFileRunning(final String pidFile); static SshEffectorTaskFactory<?> requirePidFromFileRunning(String pidFile); static SshEffectorTaskFactory<Boolean> isPidFromFileRunning(String pidFile); @Beta static Map<String, Object> getSshFlags(Entity entity, Location optionalLocation); static final ConfigKey<Boolean> IGNORE_ENTITY_SSH_FLAGS; }### Answer:
@Test(groups="Integration") public void testRequirePidFromFileOnFailure() throws IOException { File f = File.createTempFile("testBrooklynPid", ".pid"); Files.write( "99999".getBytes(), f ); ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidFromFileRunning(f.getPath())); setExpectingFailure(); try { t.getTask().getUnchecked(); } catch (Exception e) { log.info("The error if required PID is not found is: "+e); clearExpectedFailure(); Assert.assertTrue(e.toString().contains("Process with PID"), "Expected nice clue in error but got: "+e); Assert.assertEquals(t.getExitCode(), (Integer)1); } checkExpectedFailure(); }
@Test(groups="Integration") public void testRequirePidFromFileOnFailureNoSuchFile() throws IOException { ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidFromFileRunning("/path/does/not/exist/SADVQW")); setExpectingFailure(); try { t.getTask().getUnchecked(); } catch (Exception e) { log.info("The error if required PID is not found is: "+e); clearExpectedFailure(); Assert.assertTrue(e.toString().contains("Process with PID"), "Expected nice clue in error but got: "+e); Assert.assertEquals(t.getExitCode(), (Integer)1); } checkExpectedFailure(); }
@Test(groups="Integration") public void testRequirePidFromFileOnFailureTooManyFiles() throws IOException { ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidFromFileRunning("/*")); setExpectingFailure(); try { t.getTask().getUnchecked(); } catch (Exception e) { log.info("The error if required PID is not found is: "+e); clearExpectedFailure(); Assert.assertTrue(e.toString().contains("Process with PID"), "Expected nice clue in error but got: "+e); Assert.assertEquals(t.getExitCode(), (Integer)2); } checkExpectedFailure(); }
@Test(groups="Integration") public void testRequirePidFromFileOnSuccess() throws IOException { File f = File.createTempFile("testBrooklynPid", ".pid"); Files.write( (""+getMyPid()).getBytes(), f ); ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidFromFileRunning(f.getPath())); t.getTask().getUnchecked(); }
@Test(groups="Integration") public void testRequirePidFromFileOnSuccessAcceptsWildcards() throws IOException { File f = File.createTempFile("testBrooklynPid", ".pid"); Files.write( (""+getMyPid()).getBytes(), f ); ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidFromFileRunning(f.getPath()+"*")); t.getTask().getUnchecked(); }