From 34d30210324a70a1fc56a05d79fb26f62d048818 Mon Sep 17 00:00:00 2001 From: AhyoungRyu Date: Mon, 2 Jan 2017 15:39:14 +0900 Subject: [PATCH 1/3] Fix shell intp streaming output result --- .../java/org/apache/zeppelin/shell/ShellInterpreter.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) 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); } From e2fd4bfd0f45f2b647e9699bbfc771308dfdbd82 Mon Sep 17 00:00:00 2001 From: AhyoungRyu Date: Mon, 2 Jan 2017 15:39:30 +0900 Subject: [PATCH 2/3] Add test for shell inpt timeout property --- .../zeppelin/shell/ShellInterpreterTest.java | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) 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..c5bfcd1ed3f 100644 --- a/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java +++ b/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java @@ -22,6 +22,7 @@ import java.util.Properties; +import org.apache.commons.exec.ExecuteException; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Code; @@ -38,6 +39,8 @@ public void setUp() throws Exception { Properties p = new Properties(); p.setProperty("shell.command.timeout.millisecs", "60000"); shell = new ShellInterpreter(p); + + shell.open(); } @After @@ -46,9 +49,8 @@ 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); + InterpreterResult result; if (System.getProperty("os.name").startsWith("Windows")) { result = shell.interpret("dir", context); } else { @@ -63,16 +65,30 @@ 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); + InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null); + InterpreterResult result; 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()); + assertEquals(InterpreterResult.Code.SUCCESS, result.code()); assertTrue(result.message().get(0).getData().contains("invalid_command")); } + @Test + public void testShellTimeout() { + InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null); + InterpreterResult result; + + if (System.getProperty("os.name").startsWith("Windows")) { + result = shell.interpret("timeout 61", context); + } else { + result = shell.interpret("sleep 61", context); + } + + assertEquals(InterpreterResult.Code.SUCCESS, result.code()); + assertEquals(Code.INCOMPLETE, result.code()); + assertTrue(result.message().get(0).getData().contains("Paragraph received a SIGTERM")); + } } From 8fe33c4869bc9e7d74d7bab682086f2b390af615 Mon Sep 17 00:00:00 2001 From: AhyoungRyu Date: Tue, 3 Jan 2017 02:25:18 +0900 Subject: [PATCH 3/3] Fix invalid test cases --- .../zeppelin/shell/ShellInterpreterTest.java | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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 c5bfcd1ed3f..a882394bca2 100644 --- a/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java +++ b/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java @@ -22,7 +22,6 @@ import java.util.Properties; -import org.apache.commons.exec.ExecuteException; import org.apache.zeppelin.interpreter.InterpreterContext; import org.apache.zeppelin.interpreter.InterpreterResult; import org.apache.zeppelin.interpreter.InterpreterResult.Code; @@ -33,6 +32,8 @@ public class ShellInterpreterTest { private ShellInterpreter shell; + private InterpreterContext context; + private InterpreterResult result; @Before public void setUp() throws Exception { @@ -40,6 +41,7 @@ public void setUp() throws Exception { 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(); } @@ -49,8 +51,6 @@ public void tearDown() throws Exception { @Test public void test() { - InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null); - InterpreterResult result; if (System.getProperty("os.name").startsWith("Windows")) { result = shell.interpret("dir", context); } else { @@ -65,29 +65,23 @@ public void test() { @Test public void testInvalidCommand(){ - InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null); - InterpreterResult result; if (System.getProperty("os.name").startsWith("Windows")) { result = shell.interpret("invalid_command\ndir", context); } else { 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() { - InterpreterContext context = new InterpreterContext("", "1", null, "", "", null, null, null, null, null, null, null); - InterpreterResult result; - if (System.getProperty("os.name").startsWith("Windows")) { result = shell.interpret("timeout 61", context); } else { result = shell.interpret("sleep 61", context); } - assertEquals(InterpreterResult.Code.SUCCESS, result.code()); assertEquals(Code.INCOMPLETE, result.code()); assertTrue(result.message().get(0).getData().contains("Paragraph received a SIGTERM")); }