Search in sources :

Example 1 with ON_FAILURE_PROCESSOR_TAG_FIELD

use of org.opensearch.ingest.CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD in project OpenSearch by opensearch-project.

the class TrackingResultProcessorTests method testActualCompoundProcessorWithOnFailureAndTrueCondition.

public void testActualCompoundProcessorWithOnFailureAndTrueCondition() throws Exception {
    String scriptName = "conditionalScript";
    ScriptService scriptService = new ScriptService(Settings.builder().build(), Collections.singletonMap(Script.DEFAULT_SCRIPT_LANG, new MockScriptEngine(Script.DEFAULT_SCRIPT_LANG, Collections.singletonMap(scriptName, ctx -> true), Collections.emptyMap())), new HashMap<>(ScriptModule.CORE_CONTEXTS));
    RuntimeException exception = new RuntimeException("fail");
    TestProcessor failProcessor = new TestProcessor("fail", "test", null, exception);
    ConditionalProcessor conditionalProcessor = new ConditionalProcessor(randomAlphaOfLength(10), null, new Script(ScriptType.INLINE, Script.DEFAULT_SCRIPT_LANG, scriptName, Collections.emptyMap()), scriptService, failProcessor);
    TestProcessor onFailureProcessor = new TestProcessor("success", "test", null, ingestDocument -> {
    });
    CompoundProcessor actualProcessor = new CompoundProcessor(false, Arrays.asList(conditionalProcessor), Arrays.asList(onFailureProcessor));
    CompoundProcessor trackingProcessor = decorate(actualProcessor, null, resultList);
    trackingProcessor.execute(ingestDocument, (result, e) -> {
    });
    SimulateProcessorResult expectedFailResult = new SimulateProcessorResult(failProcessor.getType(), failProcessor.getTag(), failProcessor.getDescription(), ingestDocument, null);
    SimulateProcessorResult expectedSuccessResult = new SimulateProcessorResult(onFailureProcessor.getType(), onFailureProcessor.getTag(), onFailureProcessor.getDescription(), ingestDocument, null);
    assertThat(failProcessor.getInvokedCounter(), equalTo(1));
    assertThat(onFailureProcessor.getInvokedCounter(), equalTo(1));
    assertThat(resultList.size(), equalTo(2));
    assertThat(resultList.get(0).getIngestDocument(), nullValue());
    assertThat(resultList.get(0).getFailure(), equalTo(exception));
    assertThat(resultList.get(0).getProcessorTag(), equalTo(expectedFailResult.getProcessorTag()));
    assertThat(resultList.get(0).getConditionalWithResult().v1(), equalTo(scriptName));
    assertThat(resultList.get(0).getConditionalWithResult().v2(), is(Boolean.TRUE));
    Map<String, Object> metadata = resultList.get(1).getIngestDocument().getIngestMetadata();
    assertThat(metadata.get(ON_FAILURE_MESSAGE_FIELD), equalTo("fail"));
    assertThat(metadata.get(ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("test"));
    assertThat(metadata.get(ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("fail"));
    assertThat(resultList.get(1).getFailure(), nullValue());
    assertThat(resultList.get(1).getProcessorTag(), equalTo(expectedSuccessResult.getProcessorTag()));
}
Also used : PipelineProcessorTests.createIngestService(org.opensearch.ingest.PipelineProcessorTests.createIngestService) Arrays(java.util.Arrays) ON_FAILURE_PROCESSOR_TAG_FIELD(org.opensearch.ingest.CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD) TrackingResultProcessor.decorate(org.opensearch.ingest.TrackingResultProcessor.decorate) ScriptModule(org.opensearch.script.ScriptModule) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) CoreMatchers.not(org.hamcrest.CoreMatchers.not) HashMap(java.util.HashMap) SimulateProcessorResult(org.opensearch.action.ingest.SimulateProcessorResult) ArrayList(java.util.ArrayList) ScriptType(org.opensearch.script.ScriptType) ON_FAILURE_PROCESSOR_TYPE_FIELD(org.opensearch.ingest.CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD) ON_FAILURE_MESSAGE_FIELD(org.opensearch.ingest.CompoundProcessor.ON_FAILURE_MESSAGE_FIELD) Map(java.util.Map) Matchers.nullValue(org.hamcrest.Matchers.nullValue) MockScriptEngine(org.opensearch.script.MockScriptEngine) Before(org.junit.Before) ScriptService(org.opensearch.script.ScriptService) Script(org.opensearch.script.Script) OpenSearchTestCase(org.opensearch.test.OpenSearchTestCase) Settings(org.opensearch.common.settings.Settings) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) Matchers.instanceOf(org.hamcrest.Matchers.instanceOf) Mockito(org.mockito.Mockito) List(java.util.List) Matchers.sameInstance(org.hamcrest.Matchers.sameInstance) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) Matchers.containsString(org.hamcrest.Matchers.containsString) Script(org.opensearch.script.Script) Matchers.containsString(org.hamcrest.Matchers.containsString) ScriptService(org.opensearch.script.ScriptService) SimulateProcessorResult(org.opensearch.action.ingest.SimulateProcessorResult) MockScriptEngine(org.opensearch.script.MockScriptEngine)

Aggregations

ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 CoreMatchers.equalTo (org.hamcrest.CoreMatchers.equalTo)1 CoreMatchers.not (org.hamcrest.CoreMatchers.not)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)1 Matchers.is (org.hamcrest.Matchers.is)1 Matchers.nullValue (org.hamcrest.Matchers.nullValue)1 Matchers.sameInstance (org.hamcrest.Matchers.sameInstance)1 Before (org.junit.Before)1 Mockito (org.mockito.Mockito)1 Mockito.verify (org.mockito.Mockito.verify)1 Mockito.when (org.mockito.Mockito.when)1 SimulateProcessorResult (org.opensearch.action.ingest.SimulateProcessorResult)1 Settings (org.opensearch.common.settings.Settings)1 ON_FAILURE_MESSAGE_FIELD (org.opensearch.ingest.CompoundProcessor.ON_FAILURE_MESSAGE_FIELD)1