@Override public int exec(ShellTool tool, Map<String,?> flags, List<String> cmds, Map<String,?> env) { return tool.execCommands(flags, cmds, env); }}); }
@Override public void run() { int exitStatus = tool.execCommands(ImmutableMap.<String,Object>of(), ImmutableList.of("ps aux| grep \"sleep 63\" | grep -v grep")); assertEquals(exitStatus, 0); }});
@Test(groups = {"Integration"}) @Deprecated // tests deprecated code public void testExecCapturesStderr() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream err = new ByteArrayOutputStream(); String nonExistantCmd = "acmdthatdoesnotexist"; tool.execCommands(ImmutableMap.of("out", out, "err", err), ImmutableList.of(nonExistantCmd)); String errMsg = new String(err.toByteArray()); assertTrue(errMsg.contains(nonExistantCmd+": command not found\n"), "errMsg="+errMsg+"; out="+out+"; err="+err); }
@Test(groups = {"Integration"}) public void testExecReturningNonZeroExitCode() throws Exception { int exitcode = tool.execCommands(MutableMap.<String,Object>of(), ImmutableList.of("exit 123")); assertEquals(exitcode, 123); }
@Override @Test(groups = {"Integration"}) public void testExecReturningNonZeroExitCode() throws Exception { int exitcode = tool.execCommands(MutableMap.<String,Object>of(), ImmutableList.of("exit 123")); assertEquals(exitcode, 123); }
@Test(groups = {"Integration"}) public void testExecReturningZeroExitCode() throws Exception { int exitcode = tool.execCommands(MutableMap.<String,Object>of(), ImmutableList.of("date")); assertEquals(exitcode, 0); }
protected String execCommands(ConfigBag config, List<String> cmds, Map<String,?> env) { ByteArrayOutputStream out = new ByteArrayOutputStream(); MutableMap<String,Object> flags = MutableMap.<String,Object>of("out", out); if (config!=null) flags.add(config.getAllConfig()); tool.execCommands(flags, cmds, env); return new String(out.toByteArray()); }
}}); tool.execCommands(ImmutableMap.<String,Object>of(), ImmutableList.of("ps aux| grep \"sleep 63\" | grep -v grep | awk '{print($2)}' | xargs kill"));