Search in sources :

Example 21 with TryResult

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

the class EvaluatorBaseTest method returnHelloString.

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

Example 22 with TryResult

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

the class EvaluatorBaseTest method returnPrintln.

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

Example 23 with TryResult

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

the class SQLCodeRunner method call.

@Override
public TryResult call() throws Exception {
    TryResult either;
    try {
        InternalVariable.setValue(simpleEvaluationObject);
        Object r = sqlEvaluator.executeQuery(simpleEvaluationObject.getExpression(), namespaceClient, sqlEvaluator.defaultConnectionString, sqlEvaluator.namedConnectionString);
        either = TryResult.createResult(r);
    } catch (SQLException e) {
        either = TryResult.createError(e.toString());
    } catch (ThreadDeath e) {
        either = TryResult.createError(INTERUPTED_MSG);
    } catch (ReadVariableException e) {
        either = TryResult.createError(e.getMessage());
    } catch (Throwable e) {
        logger.error(e.getMessage());
        either = TryResult.createError(e.toString());
    }
    return either;
}
Also used : SQLException(java.sql.SQLException) TryResult(com.twosigma.beakerx.TryResult) SimpleEvaluationObject(com.twosigma.beakerx.jvm.object.SimpleEvaluationObject) ReadVariableException(com.twosigma.beakerx.sql.ReadVariableException)

Example 24 with TryResult

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

the class SQLWorkerThread method call.

@Override
public TryResult call() throws Exception {
    NamespaceClient namespaceClient = null;
    TryResult r;
    job.getSimpleEvaluationObject().started();
    try {
        job.getSimpleEvaluationObject().setOutputHandler();
        namespaceClient = NamespaceClient.getBeaker(sqlEvaluator.getSessionId());
        namespaceClient.setOutputObj(job.getSimpleEvaluationObject());
        r = sqlEvaluator.executeTask(new SQLCodeRunner(sqlEvaluator, job.getSimpleEvaluationObject(), namespaceClient));
    } finally {
        job.getSimpleEvaluationObject().clrOutputHandler();
        if (namespaceClient != null) {
            namespaceClient.setOutputObj(null);
        }
    }
    return r;
}
Also used : NamespaceClient(com.twosigma.beakerx.NamespaceClient) TryResult(com.twosigma.beakerx.TryResult)

Example 25 with TryResult

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

the class KotlinEvaluatorTest method handleErrors.

@Test
public void handleErrors() throws Exception {
    // given
    String code = "val plot = UndefinedPlot()";
    SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
    // when
    TryResult evaluate = evaluator.evaluate(seo, code);
    // then
    assertThat(evaluate.error()).contains("unresolved reference: UndefinedPlot");
}
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