Skip to content

Rerunning ScriptModule fails #6

@Squareys

Description

@Squareys

Hello everybody!

I have a use case in which I would like to reuse a ScriptModule, but the Jython script always returns the same value (the value of the first execution). Consider the following test (you may copy into the JythonTest and autoimport to run):

    @Test
    public void testMultipleExecution() throws InterruptedException, ExecutionException,
        IOException, ScriptException, ModuleException
    {
        final Context context = new Context(ScriptService.class);
        final ModuleService moduleService = context.getService(ModuleService.class);

        final String TEST_CODE = "" + //
            "# @INPUT String str\n" + //
            "# @OUTPUT String out\n" +  //
            "out = \"Hello, \" + str\n";

        ScriptInfo info = new ScriptInfo(context, "hello.py", new StringReader(TEST_CODE));
        ScriptModule module = info.createModule();

        context.inject(module);

        module.setInput("str", "Albert");
        module.setResolved("str", true);
        moduleService.run(module, true).get();
        assertEquals("Hello, Albert", module.getOutput("out"));

        module.setInput("str", "Einstein");
        moduleService.run(module, true).get();

        assertEquals("Hello, Einstein", module.getOutput("out"));
    }

which gives the following output:

org.junit.ComparisonFailure: expected:<Hello, [Einstein]> but was:<Hello, [Albert]>

Debugging further this problem seems to go all the way down to everything working as expected until this line, where the out var from the script is not replaced with the new value.

Anybody have an idea? Or is there a different way of rerunning a script efficiently instead of reusing a module?

Thanks in advance!
Jonathan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions