use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteNoop.
/**
* The interpreter should handle if no value is returned. Some Stellar expressions
* will result in no value.
*/
@Test
public void testExecuteNoop() {
// x is undefined and will have no result
InterpreterResult result = interpreter.interpret("x", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals(0, message.getData().length());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project metron by apache.
the class StellarInterpreterTest method testExecuteWithStellarMap.
/**
* Ensure that Stellar maps are displayed correctly in Zeppelin.
*/
@Test
public void testExecuteWithStellarMap() {
final String expected = "{foo=2, key=val}";
InterpreterResult result = interpreter.interpret("{ 'foo':2, 'key':'val' }", context);
// validate the result
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
assertEquals(1, result.message().size());
// validate the message
InterpreterResultMessage message = result.message().get(0);
assertEquals(expected, message.getData());
assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.
the class ShinyInterpreterTest method testInvalidShinyApp.
@Test
public void testInvalidShinyApp() throws IOException, InterpreterException, InterruptedException, UnirestException {
InterpreterContext context = getInterpreterContext();
context.getLocalProperties().put("type", "ui");
InterpreterResult result = interpreter.interpret(IOUtils.toString(getClass().getResource("/invalid_ui.R"), StandardCharsets.UTF_8), context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
context = getInterpreterContext();
context.getLocalProperties().put("type", "server");
result = interpreter.interpret(IOUtils.toString(getClass().getResource("/server.R"), StandardCharsets.UTF_8), context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
final InterpreterContext context2 = getInterpreterContext();
context2.getLocalProperties().put("type", "run");
Thread thread = new Thread(() -> {
try {
interpreter.interpret("", context2);
} catch (Exception e) {
e.printStackTrace();
}
});
thread.start();
// wait for the shiny app start
Thread.sleep(5 * 1000);
List<InterpreterResultMessage> resultMessages = context2.out.toInterpreterResultMessage();
assertEquals(resultMessages.toString(), 1, resultMessages.size());
assertEquals(InterpreterResult.Type.HTML, resultMessages.get(0).getType());
String resultMessageData = resultMessages.get(0).getData();
assertTrue(resultMessageData, resultMessageData.contains("<iframe"));
Pattern urlPattern = Pattern.compile(".*src=\"(http\\S*)\".*", Pattern.DOTALL);
Matcher matcher = urlPattern.matcher(resultMessageData);
if (!matcher.matches()) {
fail("Unable to extract url: " + resultMessageData);
}
String shinyURL = matcher.group(1);
// call shiny app via rest api
HttpResponse<String> response = Unirest.get(shinyURL).asString();
assertEquals(500, response.getStatus());
resultMessages = context2.out.toInterpreterResultMessage();
assertTrue(resultMessages.get(1).getData(), resultMessages.get(1).getData().contains("object 'Invalid_code' not found"));
// cancel paragraph to stop shiny app
interpreter.cancel(getInterpreterContext());
// wait for shiny app to be stopped
Thread.sleep(1000);
try {
Unirest.get(shinyURL).asString();
fail("Should fail to connect to shiny app");
} catch (Exception e) {
assertTrue(e.getMessage(), e.getMessage().contains("Connection refused"));
}
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.
the class IPythonInterpreterTest method testGrpcFrameSize.
@Test
public void testGrpcFrameSize() throws InterpreterException, IOException {
tearDown();
Properties properties = initIntpProperties();
properties.setProperty("zeppelin.jupyter.kernel.grpc.message_size", "4000");
startInterpreter(properties);
// to make this test can run under both python2 and python3
InterpreterResult result = interpreter.interpret("from __future__ import print_function", getInterpreterContext());
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
InterpreterContext context = getInterpreterContext();
result = interpreter.interpret("print('1'*4000)", context);
assertEquals(InterpreterResult.Code.ERROR, result.code());
List<InterpreterResultMessage> interpreterResultMessages = context.out.toInterpreterResultMessage();
assertEquals(1, interpreterResultMessages.size());
assertTrue(interpreterResultMessages.get(0).getData().contains("exceeds maximum size 4000"));
// next call continue work
result = interpreter.interpret("print(1)", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
tearDown();
// increase framesize to make it work
properties.setProperty("zeppelin.ipython.grpc.message_size", "5000");
startInterpreter(properties);
// to make this test can run under both python2 and python3
result = interpreter.interpret("from __future__ import print_function", getInterpreterContext());
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
context = getInterpreterContext();
result = interpreter.interpret("print('1'*3000)", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
}
use of org.apache.zeppelin.interpreter.InterpreterResultMessage in project zeppelin by apache.
the class IPythonInterpreterTest method testIPythonAdvancedFeatures.
@Test
public void testIPythonAdvancedFeatures() throws InterpreterException, InterruptedException, IOException {
// ipython help
InterpreterContext context = getInterpreterContext();
InterpreterResult result = interpreter.interpret("range?", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
List<InterpreterResultMessage> interpreterResultMessages = context.out.toInterpreterResultMessage();
assertTrue(interpreterResultMessages.get(0).getData().contains("range(stop)"));
// timeit
context = getInterpreterContext();
result = interpreter.interpret("%timeit range(100)", context);
assertEquals(InterpreterResult.Code.SUCCESS, result.code());
interpreterResultMessages = context.out.toInterpreterResultMessage();
assertTrue(interpreterResultMessages.get(0).getData().contains("loops"));
// cancel
final InterpreterContext context2 = getInterpreterContext();
new Thread() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
interpreter.cancel(context2);
} catch (InterpreterException e) {
e.printStackTrace();
}
}
}.start();
result = interpreter.interpret("import time\ntime.sleep(10)", context2);
assertEquals(InterpreterResult.Code.ERROR, result.code());
interpreterResultMessages = context2.out.toInterpreterResultMessage();
assertTrue(interpreterResultMessages.get(0).getData().contains("KeyboardInterrupt"));
}
Aggregations