Search in sources :

Example 6 with TestProcessor

use of org.elasticsearch.ingest.TestProcessor in project elasticsearch by elastic.

the class TrackingResultProcessorTests method testActualCompoundProcessorWithOnFailure.

public void testActualCompoundProcessorWithOnFailure() throws Exception {
    RuntimeException exception = new RuntimeException("fail");
    TestProcessor failProcessor = new TestProcessor("fail", "test", ingestDocument -> {
        throw exception;
    });
    TestProcessor onFailureProcessor = new TestProcessor("success", "test", ingestDocument -> {
    });
    CompoundProcessor actualProcessor = new CompoundProcessor(false, Arrays.asList(new CompoundProcessor(false, Arrays.asList(failProcessor, onFailureProcessor), Arrays.asList(onFailureProcessor, failProcessor))), Arrays.asList(onFailureProcessor));
    CompoundProcessor trackingProcessor = decorate(actualProcessor, resultList);
    trackingProcessor.execute(ingestDocument);
    SimulateProcessorResult expectedFailResult = new SimulateProcessorResult(failProcessor.getTag(), ingestDocument);
    SimulateProcessorResult expectedSuccessResult = new SimulateProcessorResult(onFailureProcessor.getTag(), ingestDocument);
    assertThat(failProcessor.getInvokedCounter(), equalTo(2));
    assertThat(onFailureProcessor.getInvokedCounter(), equalTo(2));
    assertThat(resultList.size(), equalTo(4));
    assertThat(resultList.get(0).getIngestDocument(), nullValue());
    assertThat(resultList.get(0).getFailure(), equalTo(exception));
    assertThat(resultList.get(0).getProcessorTag(), equalTo(expectedFailResult.getProcessorTag()));
    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()));
    assertThat(resultList.get(2).getIngestDocument(), nullValue());
    assertThat(resultList.get(2).getFailure(), equalTo(exception));
    assertThat(resultList.get(2).getProcessorTag(), equalTo(expectedFailResult.getProcessorTag()));
    metadata = resultList.get(3).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(3).getFailure(), nullValue());
    assertThat(resultList.get(3).getProcessorTag(), equalTo(expectedSuccessResult.getProcessorTag()));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor)

Example 7 with TestProcessor

use of org.elasticsearch.ingest.TestProcessor in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteItem.

public void testExecuteItem() throws Exception {
    TestProcessor processor = new TestProcessor("processor_0", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
    assertThat(processor.getInvokedCounter(), equalTo(2));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
    SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
    assertThat(simulateDocumentBaseResult.getIngestDocument(), equalTo(ingestDocument));
    assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 8 with TestProcessor

use of org.elasticsearch.ingest.TestProcessor in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteItemWithFailure.

public void testExecuteItemWithFailure() throws Exception {
    TestProcessor processor = new TestProcessor(ingestDocument -> {
        throw new RuntimeException("processor failed");
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
    assertThat(processor.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
    SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
    assertThat(simulateDocumentBaseResult.getIngestDocument(), nullValue());
    assertThat(simulateDocumentBaseResult.getFailure(), instanceOf(RuntimeException.class));
    Exception exception = simulateDocumentBaseResult.getFailure();
    assertThat(exception, instanceOf(ElasticsearchException.class));
    assertThat(exception.getMessage(), equalTo("java.lang.IllegalArgumentException: java.lang.RuntimeException: processor failed"));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) ElasticsearchException(org.elasticsearch.ElasticsearchException) ElasticsearchException(org.elasticsearch.ElasticsearchException) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 9 with TestProcessor

use of org.elasticsearch.ingest.TestProcessor in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteVerboseItemExceptionWithIgnoreFailure.

public void testExecuteVerboseItemExceptionWithIgnoreFailure() throws Exception {
    RuntimeException exception = new RuntimeException("processor failed");
    TestProcessor testProcessor = new TestProcessor("processor_0", "mock", ingestDocument -> {
        throw exception;
    });
    CompoundProcessor processor = new CompoundProcessor(true, Collections.singletonList(testProcessor), Collections.emptyList());
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(testProcessor.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(1));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), sameInstance(exception));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument)));
    assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), ingestDocument);
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata())));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 10 with TestProcessor

use of org.elasticsearch.ingest.TestProcessor in project elasticsearch by elastic.

the class SimulateExecutionServiceTests method testExecuteVerboseItemWithoutExceptionAndWithIgnoreFailure.

public void testExecuteVerboseItemWithoutExceptionAndWithIgnoreFailure() throws Exception {
    TestProcessor testProcessor = new TestProcessor("processor_0", "mock", ingestDocument -> {
    });
    CompoundProcessor processor = new CompoundProcessor(true, Collections.singletonList(testProcessor), Collections.emptyList());
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(testProcessor.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(1));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), not(sameInstance(ingestDocument)));
    assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), ingestDocument);
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata(), not(sameInstance(ingestDocument.getSourceAndMetadata())));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Aggregations

TestProcessor (org.elasticsearch.ingest.TestProcessor)19 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)12 Pipeline (org.elasticsearch.ingest.Pipeline)8 HashMap (java.util.HashMap)7 IngestDocument (org.elasticsearch.ingest.IngestDocument)6 ArrayList (java.util.ArrayList)4 Processor (org.elasticsearch.ingest.Processor)4 List (java.util.List)3 Map (java.util.Map)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)2 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)2 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 Locale (java.util.Locale)1 PipelineStore (org.elasticsearch.ingest.PipelineStore)1 TemplateService (org.elasticsearch.ingest.TemplateService)1 TestTemplateService (org.elasticsearch.ingest.TestTemplateService)1 ESTestCase (org.elasticsearch.test.ESTestCase)1 Matchers.equalTo (org.hamcrest.Matchers.equalTo)1