Search in sources :

Example 41 with TryResult

use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.

the class JavaEvaluatorTest method noCode.

@Test
public void noCode() throws Exception {
    // given
    String code = "";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = javaEvaluator.evaluate(seo, code);
    // then
    assertThat(evaluate).isNotNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 42 with TryResult

use of com.twosigma.beakerx.TryResult 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();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 43 with TryResult

use of com.twosigma.beakerx.TryResult 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");
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 44 with TryResult

use of com.twosigma.beakerx.TryResult 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());
    }
}
Also used : MagicCommandOutput(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput) TryResult(com.twosigma.beakerx.TryResult) PlainCode.createSimpleEvaluationObject(com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)

Example 45 with TryResult

use of com.twosigma.beakerx.TryResult 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);
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) MagicCommandOutcomeItem(com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)

Aggregations

TryResult (com.twosigma.beakerx.TryResult)55 SimpleEvaluationObject (com.twosigma.beakerx.jvm.object.SimpleEvaluationObject)41 Test (org.junit.Test)30 InvocationTargetException (java.lang.reflect.InvocationTargetException)8 NamespaceClient (com.twosigma.beakerx.NamespaceClient)5 PrintWriter (java.io.PrintWriter)5 StringWriter (java.io.StringWriter)5 KernelTest (com.twosigma.beakerx.KernelTest)4 EvaluatorParameters (com.twosigma.beakerx.kernel.EvaluatorParameters)3 PlainCode.createSimpleEvaluationObject (com.twosigma.beakerx.kernel.PlainCode.createSimpleEvaluationObject)3 MagicCommandOutput (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutput)3 HashMap (java.util.HashMap)3 Plot (com.twosigma.beakerx.chart.xychart.Plot)2 MagicCommandOutcomeItem (com.twosigma.beakerx.kernel.magic.command.outcome.MagicCommandOutcomeItem)2 Message (com.twosigma.beakerx.message.Message)2 ThreadMXBean (java.lang.management.ThreadMXBean)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 ReplEvalResult (org.jetbrains.kotlin.cli.common.repl.ReplEvalResult)2 Code (com.twosigma.beakerx.kernel.Code)1