@Test
  public void testChangingVarsCrossExecution2() {
    Map<String, Object> vars = new HashMap<String, Object>();
    Object compiledScript = se.compile("value");

    ExecutableScript script = se.executable(compiledScript, vars);
    script.setNextVar("value", 1);
    Object o = script.run();
    assertThat(((Number) o).intValue(), equalTo(1));

    script.setNextVar("value", 2);
    o = script.run();
    assertThat(((Number) o).intValue(), equalTo(2));
  }
  @Test
  public void testJavaScriptInnerArrayCreation() {
    Map<String, Object> ctx = new HashMap<String, Object>();
    Map<String, Object> doc = new HashMap<String, Object>();
    ctx.put("doc", doc);

    Object compiled = se.compile("ctx.doc.field1 = ['value1', 'value2']");
    ExecutableScript script =
        se.executable(
            new CompiledScript(
                ScriptService.ScriptType.INLINE,
                "testJavaScriptInnerArrayCreation",
                "js",
                compiled),
            new HashMap<String, Object>());
    script.setNextVar("ctx", ctx);
    script.run();

    Map<String, Object> unwrap = (Map<String, Object>) script.unwrap(ctx);

    assertThat(((Map) unwrap.get("doc")).get("field1"), instanceOf(List.class));
  }
  @Test
  public void testChangingVarsCrossExecution1() {
    Map<String, Object> vars = new HashMap<String, Object>();
    Map<String, Object> ctx = new HashMap<String, Object>();
    vars.put("ctx", ctx);
    Object compiledScript = se.compile("ctx.value");

    ExecutableScript script =
        se.executable(
            new CompiledScript(
                ScriptService.ScriptType.INLINE,
                "testChangingVarsCrossExecution1",
                "js",
                compiledScript),
            vars);
    ctx.put("value", 1);
    Object o = script.run();
    assertThat(((Number) o).intValue(), equalTo(1));

    ctx.put("value", 2);
    o = script.run();
    assertThat(((Number) o).intValue(), equalTo(2));
  }