zeppelin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ahyoung...@apache.org
Subject zeppelin git commit: [ZEPPELIN-1880] Fix shell interpreter output streaming result
Date Tue, 24 Jan 2017 05:09:48 GMT
Repository: zeppelin
Updated Branches:
  refs/heads/master 57bf5be7e -> 9b4a1bf72


[ZEPPELIN-1880] Fix shell interpreter output streaming result

### What is this PR for?
Shell interpreter streaming output had been available by #683, but currently it's broken after
#1087 merged. This patch is for putting it back.

### What type of PR is it?
Bug Fix

### TODO
- [x] Fix test

### What is the Jira issue?
[ZEPPELIN-1880](https://issues.apache.org/jira/browse/ZEPPELIN-1880)

### How should this be tested?
```
%sh

date && sleep 3 && date
```

the each timestamp must be printed as streaming output

### Screenshots (if appropriate)
 - before
![shellintpresultbefore](https://cloud.githubusercontent.com/assets/10060731/21585515/60c35a04-d105-11e6-8e68-853ee784e89d.gif)

 - after
![shellintpresult](https://cloud.githubusercontent.com/assets/10060731/21585516/62142ac8-d105-11e6-8628-1d6eec35daae.gif)

### Questions:
* Does the licenses files need update? no
* Is there breaking changes for older versions? no
* Does this needs documentation? no

Author: AhyoungRyu <fbdkdud93@hanmail.net>

Closes #1833 from AhyoungRyu/ZEPPELIN-1880 and squashes the following commits:

8fe33c4 [AhyoungRyu] Fix invalid test cases
e2fd4bf [AhyoungRyu] Add test for shell inpt timeout property
34d3021 [AhyoungRyu] Fix shell intp streaming output result


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/9b4a1bf7
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/9b4a1bf7
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/9b4a1bf7

Branch: refs/heads/master
Commit: 9b4a1bf72b46159f18bd11988bf7a448827f2b76
Parents: 57bf5be
Author: AhyoungRyu <fbdkdud93@hanmail.net>
Authored: Tue Jan 3 02:25:18 2017 +0900
Committer: ahyoungryu <ahyoungryu@apache.org>
Committed: Tue Jan 24 14:09:42 2017 +0900

----------------------------------------------------------------------
 .../apache/zeppelin/shell/ShellInterpreter.java |  7 ++---
 .../zeppelin/shell/ShellInterpreterTest.java    | 30 +++++++++++++-------
 2 files changed, 23 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9b4a1bf7/shell/src/main/java/org/apache/zeppelin/shell/ShellInterpreter.java
----------------------------------------------------------------------
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 838c6f1..abf5ee8 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 @@ package org.apache.zeppelin.shell;
 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 class ShellInterpreter extends Interpreter {
 
     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 class ShellInterpreter extends Interpreter {
       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);
       }

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/9b4a1bf7/shell/src/test/java/org/apache/zeppelin/shell/ShellInterpreterTest.java
----------------------------------------------------------------------
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 e52253f..a882394 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 @@ import org.junit.Test;
 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 class ShellInterpreterTest {
 
   @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 class ShellInterpreterTest {
 
   @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"));
+  }
 }


Mime
View raw message