Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -86,7 +84,8 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr

try {
DefaultExecutor executor = new DefaultExecutor();
executor.setStreamHandler(new PumpStreamHandler(outStream, outStream));
executor.setStreamHandler(new PumpStreamHandler(
contextInterpreter.out, contextInterpreter.out));
executor.setWatchdog(new ExecuteWatchdog(Long.valueOf(getProperty(TIMEOUT_PROPERTY))));
executors.put(contextInterpreter.getParagraphId(), executor);
int exitVal = executor.execute(cmdLine);
Expand All @@ -100,7 +99,7 @@ public InterpreterResult interpret(String cmd, InterpreterContext contextInterpr
String message = outStream.toString();
if (exitValue == 143) {
code = Code.INCOMPLETE;
message += "Paragraph received a SIGTERM.\n";
message += "Paragraph received a SIGTERM\n";
LOGGER.info("The paragraph " + contextInterpreter.getParagraphId()
+ " stopped executing: " + message);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@
public class ShellInterpreterTest {

private ShellInterpreter shell;
private InterpreterContext context;
private InterpreterResult result;

@Before
public void setUp() throws Exception {
Properties p = new Properties();
p.setProperty("shell.command.timeout.millisecs", "60000");
shell = new ShellInterpreter(p);

context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null);
shell.open();
}

@After
Expand All @@ -46,9 +51,6 @@ public void tearDown() throws Exception {

@Test
public void test() {
shell.open();
InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null);
InterpreterResult result = new InterpreterResult(Code.ERROR);
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("dir", context);
} else {
Expand All @@ -63,16 +65,24 @@ public void test() {

@Test
public void testInvalidCommand(){
shell.open();
InterpreterContext context = new InterpreterContext("","1",null,"","",null,null,null,null,null,null,null);
InterpreterResult result = new InterpreterResult(Code.ERROR);
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("invalid_command\ndir",context);
result = shell.interpret("invalid_command\ndir", context);
} else {
result = shell.interpret("invalid_command\nls",context);
result = shell.interpret("invalid_command\nls", context);
}
assertEquals(InterpreterResult.Code.SUCCESS,result.code());
assertTrue(result.message().get(0).getData().contains("invalid_command"));
assertEquals(Code.SUCCESS, result.code());
assertTrue(shell.executors.isEmpty());
}

@Test
public void testShellTimeout() {
if (System.getProperty("os.name").startsWith("Windows")) {
result = shell.interpret("timeout 61", context);
} else {
result = shell.interpret("sleep 61", context);
}

assertEquals(Code.INCOMPLETE, result.code());
assertTrue(result.message().get(0).getData().contains("Paragraph received a SIGTERM"));
}
}