Search in sources :

Example 11 with TestProcessor

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

the class SimulateExecutionServiceTests method testExecuteVerboseItem.

public void testExecuteVerboseItem() throws Exception {
    TestProcessor processor = new TestProcessor("test-id", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(processor.getInvokedCounter(), equalTo(2));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("test-id"));
    IngestDocument firstProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument();
    assertThat(firstProcessorIngestDocument, not(sameInstance(this.ingestDocument)));
    assertIngestDocument(firstProcessorIngestDocument, this.ingestDocument);
    assertThat(firstProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata())));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("test-id"));
    IngestDocument secondProcessorIngestDocument = simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument();
    assertThat(secondProcessorIngestDocument, not(sameInstance(this.ingestDocument)));
    assertIngestDocument(secondProcessorIngestDocument, this.ingestDocument);
    assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(this.ingestDocument.getSourceAndMetadata())));
    assertThat(secondProcessorIngestDocument.getSourceAndMetadata(), not(sameInstance(firstProcessorIngestDocument.getSourceAndMetadata())));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 12 with TestProcessor

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

the class SimulateExecutionServiceTests method testExecuteVerboseItemExceptionWithoutOnFailure.

public void testExecuteVerboseItemExceptionWithoutOnFailure() throws Exception {
    TestProcessor processor1 = new TestProcessor("processor_0", "mock", ingestDocument -> {
    });
    TestProcessor processor2 = new TestProcessor("processor_1", "mock", ingestDocument -> {
        throw new RuntimeException("processor failed");
    });
    TestProcessor processor3 = new TestProcessor("processor_2", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor1, processor2, processor3));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(processor1.getInvokedCounter(), equalTo(1));
    assertThat(processor2.getInvokedCounter(), equalTo(1));
    assertThat(processor3.getInvokedCounter(), equalTo(0));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(2));
    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())));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("processor_1"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), instanceOf(RuntimeException.class));
    RuntimeException runtimeException = (RuntimeException) simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure();
    assertThat(runtimeException.getMessage(), equalTo("processor failed"));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 13 with TestProcessor

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

the class SimulateExecutionServiceTests method testExecuteVerboseItemWithOnFailure.

public void testExecuteVerboseItemWithOnFailure() throws Exception {
    TestProcessor processor1 = new TestProcessor("processor_0", "mock", ingestDocument -> {
        throw new RuntimeException("processor failed");
    });
    TestProcessor processor2 = new TestProcessor("processor_1", "mock", ingestDocument -> {
    });
    TestProcessor processor3 = new TestProcessor("processor_2", "mock", ingestDocument -> {
    });
    Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(new CompoundProcessor(false, Collections.singletonList(processor1), Collections.singletonList(processor2)), processor3));
    SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
    assertThat(processor1.getInvokedCounter(), equalTo(1));
    assertThat(processor2.getInvokedCounter(), equalTo(1));
    assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
    SimulateDocumentVerboseResult simulateDocumentVerboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
    assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(3));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), instanceOf(RuntimeException.class));
    RuntimeException runtimeException = (RuntimeException) simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure();
    assertThat(runtimeException.getMessage(), equalTo("processor failed"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getProcessorTag(), equalTo("processor_1"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), not(sameInstance(ingestDocument)));
    IngestDocument ingestDocumentWithOnFailureMetadata = new IngestDocument(ingestDocument);
    Map<String, Object> metadata = ingestDocumentWithOnFailureMetadata.getIngestMetadata();
    metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD, "mock");
    metadata.put(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD, "processor_0");
    metadata.put(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD, "processor failed");
    assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument(), ingestDocumentWithOnFailureMetadata);
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getProcessorTag(), equalTo("processor_2"));
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getIngestDocument(), not(sameInstance(ingestDocument)));
    assertIngestDocument(simulateDocumentVerboseResult.getProcessorResults().get(2).getIngestDocument(), ingestDocument);
    assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getFailure(), nullValue());
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) IngestDocumentMatcher.assertIngestDocument(org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument) IngestDocument(org.elasticsearch.ingest.IngestDocument) Pipeline(org.elasticsearch.ingest.Pipeline)

Example 14 with TestProcessor

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

the class SimulatePipelineRequestParsingTests method init.

@Before
public void init() throws IOException {
    TestProcessor processor = new TestProcessor(ingestDocument -> {
    });
    CompoundProcessor pipelineCompoundProcessor = new CompoundProcessor(processor);
    Pipeline pipeline = new Pipeline(SIMULATED_PIPELINE_ID, null, null, pipelineCompoundProcessor);
    Map<String, Processor.Factory> registry = Collections.singletonMap("mock_processor", (factories, tag, config) -> processor);
    store = mock(PipelineStore.class);
    when(store.get(SIMULATED_PIPELINE_ID)).thenReturn(pipeline);
    when(store.getProcessorFactories()).thenReturn(registry);
}
Also used : PipelineStore(org.elasticsearch.ingest.PipelineStore) CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) Pipeline(org.elasticsearch.ingest.Pipeline) Before(org.junit.Before)

Example 15 with TestProcessor

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

the class TrackingResultProcessorTests method testActualProcessor.

public void testActualProcessor() throws Exception {
    TestProcessor actualProcessor = new TestProcessor(ingestDocument -> {
    });
    TrackingResultProcessor trackingProcessor = new TrackingResultProcessor(false, actualProcessor, resultList);
    trackingProcessor.execute(ingestDocument);
    SimulateProcessorResult expectedResult = new SimulateProcessorResult(actualProcessor.getTag(), ingestDocument);
    assertThat(actualProcessor.getInvokedCounter(), equalTo(1));
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList.get(0).getIngestDocument(), equalTo(expectedResult.getIngestDocument()));
    assertThat(resultList.get(0).getFailure(), nullValue());
    assertThat(resultList.get(0).getProcessorTag(), equalTo(expectedResult.getProcessorTag()));
}
Also used : TestProcessor(org.elasticsearch.ingest.TestProcessor)

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