diff --git a/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java b/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java index 838c6f15358..abf5ee8b5a6 100644 --- a/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java +++ b/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java @@ -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; @@ -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); @@ -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); } diff --git a/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java b/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java index e52253f3e90..a882394bca2 100644 --- a/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java +++ b/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java @@ -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 @@ -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 { @@ -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")); + } }