use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class KotlinCodeRunner method call.
@Override
public TryResult call() throws Exception {
TryResult either;
ClassLoader oldld = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(loader);
InternalVariable.setValue(theOutput);
try {
theOutput.setOutputHandler();
InternalVariable.setValue(theOutput);
ReplEvalResult eval = repl.eval(this.codeToBeExecuted);
either = interpretResult(eval);
} catch (Throwable e) {
if (e instanceof InvocationTargetException)
e = ((InvocationTargetException) e).getTargetException();
if ((e instanceof InterruptedException) || (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();
Thread.currentThread().setContextClassLoader(oldld);
}
return either;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class KotlinWorkerThread method call.
@Override
public TryResult call() throws Exception {
NamespaceClient nc = null;
TryResult either;
try {
nc = NamespaceClient.getBeaker(kotlinEvaluator.getSessionId());
nc.setOutputObj(j.outputObject);
j.outputObject.started();
try {
KotlinCodeRunner kotlinCodeRunner = new KotlinCodeRunner(j.outputObject, kotlinEvaluator.getClassLoader(), kotlinEvaluator.getRepl(), j.codeToBeExecuted);
either = kotlinEvaluator.executeTask(kotlinCodeRunner);
if (nc != null) {
nc.setOutputObj(null);
nc = null;
}
} catch (Exception e) {
either = TryResult.createError(e.getMessage());
}
} catch (Throwable e) {
e.printStackTrace();
either = TryResult.createError(e.getMessage());
} finally {
if (nc != null) {
nc.setOutputObj(null);
nc = null;
}
}
return either;
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class JavaEvaluatorTest method evaluateDivisionByZero_shouldReturnArithmeticException.
@Test
public void evaluateDivisionByZero_shouldReturnArithmeticException() throws Exception {
// given
String code = "return 16/0;";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = javaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.error()).contains("java.lang.ArithmeticException");
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class JavaEvaluatorTest method evaluateStreamInMultipleLines.
@Test
public void evaluateStreamInMultipleLines() throws Exception {
// given
String code = "import java.util.stream.Stream;\n" + "return Stream.of(1, 2, 3, 4).map(i -> { \n" + " return i * 10;\n" + "});";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = javaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.result()).isNotNull();
}
use of com.twosigma.beakerx.TryResult in project beakerx by twosigma.
the class JavaEvaluatorTest method evaluatePlot_shouldCreatePlotObject.
@Test
public void evaluatePlot_shouldCreatePlotObject() throws Exception {
// given
String code = "import com.twosigma.beakerx.chart.xychart.*;\n" + "Plot plot = new Plot(); plot.setTitle(\"test title\");\n" + "return plot;";
SimpleEvaluationObject seo = new SimpleEvaluationObject(code);
// when
TryResult evaluate = javaEvaluator.evaluate(seo, code);
// then
assertThat(evaluate.result() instanceof Plot).isTrue();
assertThat(((Plot) evaluate.result()).getTitle()).isEqualTo("test title");
}
Aggregations