use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.
the class ExpressionNumberSortScriptTests method testLinkError.
public void testLinkError() {
ScriptException e = expectThrows(ScriptException.class, () -> {
compile("doc['nonexistent'].value * 5");
});
assertTrue(e.getCause() instanceof ParseException);
}
use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.
the class ConditionalProcessorTests method testPrecompiledError.
public void testPrecompiledError() {
ScriptService scriptService = MockScriptService.singleContext(IngestConditionalScript.CONTEXT, code -> {
throw new ScriptException("bad script", new ParseException("error", 0), org.opensearch.common.collect.List.of(), "", "lang", null);
}, org.opensearch.common.collect.Map.of());
Script script = new Script(ScriptType.INLINE, "lang", "foo", org.opensearch.common.collect.Map.of());
ScriptException e = expectThrows(ScriptException.class, () -> new ConditionalProcessor(null, null, script, scriptService, null));
assertThat(e.getMessage(), equalTo("bad script"));
}
use of org.opensearch.script.ScriptException in project OpenSearch by opensearch-project.
the class ConditionalProcessorTests method testRuntimeCompileError.
public void testRuntimeCompileError() {
AtomicBoolean fail = new AtomicBoolean(false);
Map<String, StoredScriptSource> storedScripts = new HashMap<>();
storedScripts.put("foo", new StoredScriptSource("lang", "", org.opensearch.common.collect.Map.of()));
ScriptService scriptService = MockScriptService.singleContext(IngestConditionalScript.CONTEXT, code -> {
if (fail.get()) {
throw new ScriptException("bad script", new ParseException("error", 0), org.opensearch.common.collect.List.of(), "", "lang", null);
} else {
return params -> new IngestConditionalScript(params) {
@Override
public boolean execute(Map<String, Object> ctx) {
return false;
}
};
}
}, storedScripts);
Script script = new Script(ScriptType.STORED, null, "foo", org.opensearch.common.collect.Map.of());
ConditionalProcessor processor = new ConditionalProcessor(null, null, script, scriptService, null);
fail.set(true);
// must change the script source or the cached version will be used
storedScripts.put("foo", new StoredScriptSource("lang", "changed", org.opensearch.common.collect.Map.of()));
IngestDocument ingestDoc = new IngestDocument(org.opensearch.common.collect.Map.of(), org.opensearch.common.collect.Map.of());
processor.execute(ingestDoc, (doc, e) -> {
assertThat(e.getMessage(), equalTo("bad script"));
});
}
Aggregations