Search in sources :

Example 1 with VariableResult

use of org.apache.metron.stellar.common.shell.VariableResult in project metron by apache.

the class StellarInterpreterTest method testExecuteStellarMultipleLines.

/**
 * Ensure that we can run Stellar code in the interpreter.
 */
@Test
public void testExecuteStellarMultipleLines() {
    // multi-line input
    String input = "x := 2 + 2" + System.lineSeparator() + "y := 4 + 4";
    InterpreterResult result = interpreter.interpret(input, context);
    // expect x == 4 and y == 8
    Map<String, VariableResult> vars = interpreter.getExecutor().getState();
    assertEquals(4, vars.get("x").getResult());
    assertEquals(8, vars.get("y").getResult());
    // validate the result
    assertEquals(InterpreterResult.Code.SUCCESS, result.code());
    assertEquals(1, result.message().size());
    // the output is the result of only the 'last' expression
    InterpreterResultMessage message = result.message().get(0);
    assertEquals("8", message.getData());
    assertEquals(InterpreterResult.Type.TEXT, message.getType());
}
Also used : VariableResult(org.apache.metron.stellar.common.shell.VariableResult) InterpreterResult(org.apache.zeppelin.interpreter.InterpreterResult) InterpreterResultMessage(org.apache.zeppelin.interpreter.InterpreterResultMessage) Test(org.junit.jupiter.api.Test)

Example 2 with VariableResult

use of org.apache.metron.stellar.common.shell.VariableResult in project metron by apache.

the class ShellFunctionsTest method testListVarsWithVars.

@Test
public void testListVarsWithVars() {
    Map<String, VariableResult> variables = ImmutableMap.of("foo", VariableResult.withExpression(2.0, "1 + 1"));
    Context context = new Context.Builder().with(Context.Capabilities.SHELL_VARIABLES, () -> variables).build();
    Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context);
    assertEquals(expectedListWithFoo, out);
}
Also used : Context(org.apache.metron.stellar.dsl.Context) VariableResult(org.apache.metron.stellar.common.shell.VariableResult) Test(org.junit.jupiter.api.Test)

Aggregations

VariableResult (org.apache.metron.stellar.common.shell.VariableResult)2 Test (org.junit.jupiter.api.Test)2 Context (org.apache.metron.stellar.dsl.Context)1 InterpreterResult (org.apache.zeppelin.interpreter.InterpreterResult)1 InterpreterResultMessage (org.apache.zeppelin.interpreter.InterpreterResultMessage)1