Examples of ExecutableScript


Examples of org.elasticsearch.script.ExecutableScript

    public void testChangingVarsCrossExecution2() {
        Map<String, Object> vars = new HashMap<String, Object>();
        Map<String, Object> ctx = 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));
    }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

                        long y = ThreadLocalRandom.current().nextInt();
                        long addition = x + y;
                        Map<String, Object> vars = new HashMap<String, Object>();
                        vars.put("x", x);
                        vars.put("y", y);
                        ExecutableScript script = se.executable(compiled, vars);
                        for (int i = 0; i < 100000; i++) {
                            long result = ((Number) script.run()).longValue();
                            assertThat(result, equalTo(addition));
                        }
                    } catch (Throwable t) {
                        failed.set(true);
                        logger.error("failed", t);
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

            se.execute(compiled, vars);
        }
        System.out.println("Execute Took: " + stopWatch.stop().lastTaskTime());

        stopWatch = new StopWatch().start();
        ExecutableScript executableScript = se.executable(compiled, vars);
        for (long i = 0; i < ITER; i++) {
            executableScript.run();
        }
        System.out.println("Executable Took: " + stopWatch.stop().lastTaskTime());

        stopWatch = new StopWatch().start();
        executableScript = se.executable(compiled, vars);
        for (long i = 0; i < ITER; i++) {
            for (Map.Entry<String, Object> entry : vars.entrySet()) {
                executableScript.setNextVar(entry.getKey(), entry.getValue());
            }
            executableScript.run();
        }
        System.out.println("Executable (vars) Took: " + stopWatch.stop().lastTaskTime());
    }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

                    SingletonS2ContainerFactory.getContainer());
            localVars.put("settings", settings);
            try {
                final CompiledScript compiledScript = scriptService.compile(
                        lang, script, scriptType);
                ExecutableScript executable = scriptService.executable(
                        compiledScript, localVars);
                Object result = executable.run();
                logger.info("[{}] \"{}\" => {}", target, script, result);
            } catch (final Exception e) {
                logger.warn("Failed to execute script: {}", e, script);
            }
        }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

            } else {
                params = new HashMap<String, Object>();
            }
            params.put("facets", facetObjects);
            params.put("_client", client);
            ExecutableScript script = scriptService.executable(firstFacet.scriptLang(), firstFacet.reduceScript(), params);
            facet = script.run();
        } else {
            facet = facetObjects;
        }
        return new InternalScriptFacet(firstFacet.getName(), facet, firstFacet.scriptLang(), firstFacet.reduceScript(), firstFacet.reduceParams(), scriptService, client);
    }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

            scriptType = ScriptType.INLINE;
        }
        final ScriptService scriptService = riverConfig.getScriptService();
        final CompiledScript compiledScript = scriptService.compile(lang,
                script, scriptType);
        ExecutableScript executable = scriptService.executable(compiledScript,
                vars);
        return executable.run();
    }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

      assertThat(e.getMessage()).isEqualTo("Missing 'field' parameter");
    }

    // Has all required attributes and Null Value
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, "test");
    ExecutableScript script = factory.newScript(params);
    assertThat(script).isNotNull();

    // Has all required attributes and VALUE of wrong type
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, new Integer(52));
    try {
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "A"));

    ExecutableScript script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();

    mapFields = (Collection) source.get(listField);
    System.out.println("source = " + source);
    assertThat(mapFields).hasSize(1);

    // Add item to existing list
    params = new HashMap<String, Object>();
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "B"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // updated first item in list
    params = new HashMap<String, Object>();
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "1", "value", "a"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // updated second item in list
    params = new HashMap<String, Object>();
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "2");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, mapOf("key", "2", "value", "b"));
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(2);

    // delete first item
    params = new HashMap<String, Object>();
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_FIELD, listField);
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_FIELD, "key");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_ID_VALUE, "1");
    params.put(ProcessConstants.ES_PLUGIN_LISTUPDATE_VALUE, null);
    script = factory.newScript(params);
    script.setNextVar("ctx", ImmutableMap.of("_source", source));
    script.run();
    mapFields = (Collection) source.get(listField);
    assertThat(mapFields).hasSize(1);
  }
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

                        long y = ThreadLocalRandom.current().nextInt();
                        long addition = x + y;
                        Map<String, Object> vars = new HashMap<String, Object>();
                        vars.put("x", x);
                        vars.put("y", y);
                        ExecutableScript script = se.executable(compiled, vars);
                        for (int i = 0; i < 100000; i++) {
                            long result = ((Number) script.run()).longValue();
                            assertThat(result, equalTo(addition));
                        }
                    } catch (Throwable t) {
                        failed.set(true);
                        logger.error("failed", t);
View Full Code Here

Examples of org.elasticsearch.script.ExecutableScript

                    try {
                        barrier.await();
                        long x = ThreadLocalRandom.current().nextInt();
                        Map<String, Object> vars = new HashMap<String, Object>();
                        vars.put("x", x);
                        ExecutableScript script = se.executable(compiled, vars);
                        for (int i = 0; i < 100000; i++) {
                            long y = ThreadLocalRandom.current().nextInt();
                            long addition = x + y;
                            script.setNextVar("y", y);
                            long result = ((Number) script.run()).longValue();
                            assertThat(result, equalTo(addition));
                        }
                    } catch (Throwable t) {
                        failed.set(true);
                        logger.error("failed", t);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.