@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 testRunningPidFromFile() throws IOException { File f = File.createTempFile("testBrooklynPid", ".pid"); Files.write( (""+getMyPid()).getBytes(), f ); ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.codePidFromFileRunning(f.getPath())); Assert.assertEquals(t.getTask().getUnchecked(), (Integer)0); ProcessTaskWrapper<Boolean> t2 = submit(SshEffectorTasks.isPidFromFileRunning(f.getPath())); Assert.assertTrue(t2.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(); }
@Test(groups="Integration") public void testSshFetch() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "f2"); FileUtils.write(new File(fn), "hello fetched world"); SshFetchTaskWrapper t = submit(SshEffectorTasks.fetch(fn)); t.block(); Assert.assertTrue(t.isDone()); Assert.assertEquals(t.get(), "hello fetched world"); }
@Test(groups="Integration") public void testSshEchoHello() { ProcessTaskWrapper<Integer> t = submit(SshEffectorTasks.ssh("sleep 1 ; echo hello world")); Assert.assertFalse(t.isDone()); Assert.assertEquals(t.get(), (Integer)0); Assert.assertEquals(t.getTask().getUnchecked(), (Integer)0); Assert.assertEquals(t.getStdout().trim(), "hello world"); }
@Test(groups="Integration") public void testSshPut() throws IOException { String fn = Urls.mergePaths(tempDir.getPath(), "f1"); SshPutTaskWrapper t = submit(SshEffectorTasks.put(fn).contents("hello world")); t.block(); Assert.assertEquals(FileUtils.readFileToString(new File(fn)), "hello world"); // and make sure this doesn't throw Assert.assertTrue(t.isDone()); Assert.assertTrue(t.isSuccessful()); Assert.assertEquals(t.get(), null); Assert.assertEquals(t.getExitCode(), (Integer)0); }
@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 testNonRunningPidRequired() { ProcessTaskWrapper<?> t = submit(SshEffectorTasks.requirePidRunning(99999)); 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); } checkExpectedFailure(); }
@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 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()); }
@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(); }