use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.
the class JavaEvaluatorTest method evaluateStreamInOneLine.
@Test
public void evaluateStreamInOneLine() throws Exception {
// given
String code = "import java.util.stream.Stream;\n" + "return Stream.of(1, 2, 3, 4).map(i -> { return i * 10;});";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = javaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.result()).isNotNull();
}
use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.
the class JavaEvaluatorTest method evaluateIfStatement.
@Test
public void evaluateIfStatement() throws Exception {
// given
String code = "" + "if (true){\n" + " return \"AAA\";\n" + "}else {\n" + " return \"BBB\";\n" + "}";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = javaEvaluator.evaluate(seo, code);
// then
assertThat((String) evaluate.result()).isEqualTo("AAA");
}
use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.
the class ClasspathAddDynamicMagicCommand method execute.
@Override
public MagicCommandOutcomeItem execute(MagicCommandExecutionParam param) {
String command = param.getCommand();
String[] split = splitPath(command);
if (split.length < 4) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, WRONG_FORMAT_MSG + CLASSPATH_ADD_DYNAMIC);
}
String codeToExecute = command.substring(command.indexOf(DYNAMIC) + DYNAMIC.length()).trim();
SimpleEvaluationObject seo = createSimpleEvaluationObject(codeToExecute, kernel, param.getCode().getMessage(), param.getExecutionCount());
TryResult either = kernel.executeCode(codeToExecute, seo);
if (either.isResult()) {
try {
Collection<String> newAddedJars = addJars(either.result());
if (newAddedJars.isEmpty()) {
return new MagicCommandOutput(MagicCommandOutput.Status.OK);
}
String textMessage = "Added jar" + (newAddedJars.size() > 1 ? "s: " : ": ") + newAddedJars;
return new MagicCommandOutput(MagicCommandOutput.Status.OK, textMessage);
} catch (Exception e) {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during execution of " + CLASSPATH_ADD_DYNAMIC + " : " + e.getMessage());
}
} else {
return new MagicCommandOutput(MagicCommandOutput.Status.ERROR, "There occurs problem during execution of " + CLASSPATH_ADD_DYNAMIC + " : " + either.error());
}
}
use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.
the class ExecuteRequestHandler method handleException.
private void handleException(Message message, Exception e) {
SimpleEvaluationObject seo = createSimpleEvaluationObject(takeCodeFrom(message), kernel, message, executionCount);
seo.error(e);
}
use of com.twosigma.beakerx.jvm.object.SimpleEvaluationObject in project beakerx by twosigma.
the class MagicCommand method executeFrame.
@Override
public void executeFrame(Code code, KernelFunctionality kernel, Message message, int executionCount) {
MagicCommandOutcomeItem execute = execute(code, executionCount, false);
sendMagicCommandOutcome(execute, kernel, message, executionCount);
TryResult result = execute.getResult();
SimpleEvaluationObject seo = execute.getSimpleEvaluationObject();
handleResult(seo, result);
}
Aggregations