Search in sources :

Example 26 with TryResult

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

the class KotlinEvaluatorTest method executePlot.

@Test
public void executePlot() throws Exception {
    // given
    String code = "" + "import com.twosigma.beakerx.chart.xychart.*\n" + "val plot = Plot()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.result()).isNull();
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

Example 27 with TryResult

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

the class ScalaCodeRunner method call.

@Override
public TryResult call() throws Exception {
    TryResult either;
    try {
        theOutput.setOutputHandler();
        InternalVariable.setValue(theOutput);
        either = scalaEvaluator.getShell().evaluate(theOutput, theCode);
    } catch (Throwable e) {
        if (e instanceof InterruptedException || e instanceof InvocationTargetException || e instanceof ThreadDeath) {
            either = TryResult.createError(INTERUPTED_MSG);
        } else {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            either = TryResult.createError(sw.toString());
        }
    } finally {
        theOutput.clrOutputHandler();
    }
    return either;
}
Also used : StringWriter(java.io.StringWriter) TryResult(com.twosigma.beakerx.TryResult) InvocationTargetException(java.lang.reflect.InvocationTargetException) PrintWriter(java.io.PrintWriter)

Example 28 with TryResult

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

the class ScalaWorkerThread method call.

@Override
public TryResult call() throws Exception {
    NamespaceClient nc = null;
    TryResult either;
    try {
        j.outputObject.started();
        nc = NamespaceClient.getBeaker(scalaEvaluator.getSessionId());
        nc.setOutputObj(j.outputObject);
        either = scalaEvaluator.executeTask(new ScalaCodeRunner(scalaEvaluator, j.codeToBeExecuted, j.outputObject));
        if (nc != null) {
            nc.setOutputObj(null);
            nc = null;
        }
    } catch (Throwable e) {
        e.printStackTrace();
        either = TryResult.createError(e.getMessage());
    } finally {
        if (nc != null) {
            nc.setOutputObj(null);
            nc = null;
        }
    }
    return either;
}
Also used : NamespaceClient(com.twosigma.beakerx.NamespaceClient) TryResult(com.twosigma.beakerx.TryResult)

Example 29 with TryResult

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

the class SQLEvaluatorTest method insertsShouldReturnOutputCellHIDDEN.

@Test
public void insertsShouldReturnOutputCellHIDDEN() throws Exception {
    // given
    SimpleEvaluationObject seo = new SimpleEvaluationObject(SQLForColorTable.CREATE);
    // when
    TryResult evaluate = sqlEvaluator.evaluate(seo, seo.getExpression());
    // then
    verifyInsertResult(evaluate);
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test) KernelTest(com.twosigma.beakerx.KernelTest)

Example 30 with TryResult

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

the class EvaluatorBaseTest method shouldCreateErrorResultWithArithmeticExceptionWhenDivisionByZero.

@Test
public void shouldCreateErrorResultWithArithmeticExceptionWhenDivisionByZero() throws Exception {
    // given
    String code = codeForDivisionByZero();
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult either = evaluator().evaluate(seo, code);
    // then
    assertThat(either.error()).contains(textAssertionForDivisionByZero());
}
Also used : TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) Test(org.junit.Test)

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