Search in sources :

Example 6 with Pipeline

use of org.elasticsearch.ingest.Pipeline 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)

Example 7 with Pipeline

use of org.elasticsearch.ingest.Pipeline 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 8 with Pipeline

use of org.elasticsearch.ingest.Pipeline 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 9 with Pipeline

use of org.elasticsearch.ingest.Pipeline 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 10 with Pipeline

use of org.elasticsearch.ingest.Pipeline 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)

Aggregations

Pipeline (org.elasticsearch.ingest.Pipeline)10 CompoundProcessor (org.elasticsearch.ingest.CompoundProcessor)8 TestProcessor (org.elasticsearch.ingest.TestProcessor)8 IngestDocument (org.elasticsearch.ingest.IngestDocument)4 IngestDocumentMatcher.assertIngestDocument (org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocument)2 ElasticsearchException (org.elasticsearch.ElasticsearchException)1 PipelineStore (org.elasticsearch.ingest.PipelineStore)1 Before (org.junit.Before)1