Search in sources :

Example 16 with TestProcessor

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

the class TrackingResultProcessorTests method testActualCompoundProcessorWithoutOnFailure.

public void testActualCompoundProcessorWithoutOnFailure() throws Exception {
    RuntimeException exception = new RuntimeException("processor failed");
    TestProcessor testProcessor = new TestProcessor(ingestDocument -> {
        throw exception;
    });
    CompoundProcessor actualProcessor = new CompoundProcessor(testProcessor);
    CompoundProcessor trackingProcessor = decorate(actualProcessor, resultList);
    try {
        trackingProcessor.execute(ingestDocument);
        fail("processor should throw exception");
    } catch (ElasticsearchException e) {
        assertThat(e.getRootCause().getMessage(), equalTo(exception.getMessage()));
    }
    SimulateProcessorResult expectedFirstResult = new SimulateProcessorResult(testProcessor.getTag(), ingestDocument);
    assertThat(testProcessor.getInvokedCounter(), equalTo(1));
    assertThat(resultList.size(), equalTo(1));
    assertThat(resultList.get(0).getIngestDocument(), nullValue());
    assertThat(resultList.get(0).getFailure(), equalTo(exception));
    assertThat(resultList.get(0).getProcessorTag(), equalTo(expectedFirstResult.getProcessorTag()));
}
Also used : CompoundProcessor(org.elasticsearch.ingest.CompoundProcessor) TestProcessor(org.elasticsearch.ingest.TestProcessor) ElasticsearchException(org.elasticsearch.ElasticsearchException)

Example 17 with TestProcessor

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

the class ForEachProcessorTests method testNestedForEach.

public void testNestedForEach() throws Exception {
    List<Map<String, Object>> values = new ArrayList<>();
    List<Object> innerValues = new ArrayList<>();
    innerValues.add("abc");
    innerValues.add("def");
    Map<String, Object> value = new HashMap<>();
    value.put("values2", innerValues);
    values.add(value);
    innerValues = new ArrayList<>();
    innerValues.add("ghi");
    innerValues.add("jkl");
    value = new HashMap<>();
    value.put("values2", innerValues);
    values.add(value);
    IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, Collections.singletonMap("values1", values));
    TestProcessor testProcessor = new TestProcessor(doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_ingest._value", String.class).toUpperCase(Locale.ENGLISH)));
    ForEachProcessor processor = new ForEachProcessor("_tag", "values1", new ForEachProcessor("_tag", "_ingest._value.values2", testProcessor));
    processor.execute(ingestDocument);
    List result = ingestDocument.getFieldValue("values1.0.values2", List.class);
    assertThat(result.get(0), equalTo("ABC"));
    assertThat(result.get(1), equalTo("DEF"));
    result = ingestDocument.getFieldValue("values1.1.values2", List.class);
    assertThat(result.get(0), equalTo("GHI"));
    assertThat(result.get(1), equalTo("JKL"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) TestProcessor(org.elasticsearch.ingest.TestProcessor) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 18 with TestProcessor

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

the class ForEachProcessorTests method testScalarValueAllowsUnderscoreValueFieldToRemainAccessible.

public void testScalarValueAllowsUnderscoreValueFieldToRemainAccessible() throws Exception {
    List<Object> values = new ArrayList<>();
    values.add("please");
    values.add("change");
    values.add("me");
    Map<String, Object> source = new HashMap<>();
    source.put("_value", "new_value");
    source.put("values", values);
    IngestDocument ingestDocument = new IngestDocument("_index", "_type", "_id", null, null, source);
    TestProcessor processor = new TestProcessor(doc -> doc.setFieldValue("_ingest._value", doc.getFieldValue("_source._value", String.class)));
    ForEachProcessor forEachProcessor = new ForEachProcessor("_tag", "values", processor);
    forEachProcessor.execute(ingestDocument);
    List result = ingestDocument.getFieldValue("values", List.class);
    assertThat(result.get(0), equalTo("new_value"));
    assertThat(result.get(1), equalTo("new_value"));
    assertThat(result.get(2), equalTo("new_value"));
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IngestDocument(org.elasticsearch.ingest.IngestDocument) TestProcessor(org.elasticsearch.ingest.TestProcessor) ArrayList(java.util.ArrayList) List(java.util.List)

Example 19 with TestProcessor

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

the class ForEachProcessorFactoryTests method testCreate.

public void testCreate() throws Exception {
    Processor processor = new TestProcessor(ingestDocument -> {
    });
    Map<String, Processor.Factory> registry = new HashMap<>();
    registry.put("_name", (r, t, c) -> processor);
    ForEachProcessor.Factory forEachFactory = new ForEachProcessor.Factory();
    Map<String, Object> config = new HashMap<>();
    config.put("field", "_field");
    config.put("processor", Collections.singletonMap("_name", Collections.emptyMap()));
    ForEachProcessor forEachProcessor = forEachFactory.create(registry, null, config);
    assertThat(forEachProcessor, Matchers.notNullValue());
    assertThat(forEachProcessor.getField(), equalTo("_field"));
    assertThat(forEachProcessor.getProcessor(), Matchers.sameInstance(processor));
}
Also used : Processor(org.elasticsearch.ingest.Processor) TestProcessor(org.elasticsearch.ingest.TestProcessor) HashMap(java.util.HashMap) 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