|
|
@@ -19,21 +19,17 @@
|
|
|
|
|
|
package org.elasticsearch.ingest.core;
|
|
|
|
|
|
+import org.elasticsearch.ElasticsearchException;
|
|
|
import org.elasticsearch.ingest.TestProcessor;
|
|
|
-import org.elasticsearch.ingest.TestTemplateService;
|
|
|
-import org.elasticsearch.ingest.processor.AppendProcessor;
|
|
|
-import org.elasticsearch.ingest.processor.SetProcessor;
|
|
|
-import org.elasticsearch.ingest.processor.SplitProcessor;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
-import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
+import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
|
|
|
public class CompoundProcessorTests extends ESTestCase {
|
|
|
@@ -70,8 +66,8 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
try {
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
fail("should throw exception");
|
|
|
- } catch (Exception e) {
|
|
|
- assertThat(e.getMessage(), equalTo("error"));
|
|
|
+ } catch (ElasticsearchException e) {
|
|
|
+ assertThat(e.getRootCause().getMessage(), equalTo("error"));
|
|
|
}
|
|
|
assertThat(processor.getInvokedCounter(), equalTo(1));
|
|
|
}
|
|
|
@@ -117,4 +113,68 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(processorToFail.getInvokedCounter(), equalTo(1));
|
|
|
assertThat(lastProcessor.getInvokedCounter(), equalTo(1));
|
|
|
}
|
|
|
+
|
|
|
+ public void testCompoundProcessorExceptionFailWithoutOnFailure() throws Exception {
|
|
|
+ TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");});
|
|
|
+ TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> {
|
|
|
+ Map<String, String> ingestMetadata = ingestDocument.getIngestMetadata();
|
|
|
+ assertThat(ingestMetadata.entrySet(), hasSize(3));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("error"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("first"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("id1"));
|
|
|
+ });
|
|
|
+
|
|
|
+ CompoundProcessor failCompoundProcessor = new CompoundProcessor(firstProcessor);
|
|
|
+
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ Collections.singletonList(secondProcessor));
|
|
|
+ compoundProcessor.execute(ingestDocument);
|
|
|
+
|
|
|
+ assertThat(firstProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(secondProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testCompoundProcessorExceptionFail() throws Exception {
|
|
|
+ TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");});
|
|
|
+ TestProcessor failProcessor = new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");});
|
|
|
+ TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> {
|
|
|
+ Map<String, String> ingestMetadata = ingestDocument.getIngestMetadata();
|
|
|
+ assertThat(ingestMetadata.entrySet(), hasSize(3));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("custom error message"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("fail"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("tag_fail"));
|
|
|
+ });
|
|
|
+
|
|
|
+ CompoundProcessor failCompoundProcessor = new CompoundProcessor(Collections.singletonList(firstProcessor),
|
|
|
+ Collections.singletonList(failProcessor));
|
|
|
+
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ Collections.singletonList(secondProcessor));
|
|
|
+ compoundProcessor.execute(ingestDocument);
|
|
|
+
|
|
|
+ assertThat(firstProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(secondProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testCompoundProcessorExceptionFailInOnFailure() throws Exception {
|
|
|
+ TestProcessor firstProcessor = new TestProcessor("id1", "first", ingestDocument -> {throw new RuntimeException("error");});
|
|
|
+ TestProcessor failProcessor = new TestProcessor("tag_fail", "fail", ingestDocument -> {throw new RuntimeException("custom error message");});
|
|
|
+ TestProcessor secondProcessor = new TestProcessor("id3", "second", ingestDocument -> {
|
|
|
+ Map<String, String> ingestMetadata = ingestDocument.getIngestMetadata();
|
|
|
+ assertThat(ingestMetadata.entrySet(), hasSize(3));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_MESSAGE_FIELD), equalTo("custom error message"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("fail"));
|
|
|
+ assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("tag_fail"));
|
|
|
+ });
|
|
|
+
|
|
|
+ CompoundProcessor failCompoundProcessor = new CompoundProcessor(Collections.singletonList(firstProcessor),
|
|
|
+ Collections.singletonList(new CompoundProcessor(failProcessor)));
|
|
|
+
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ Collections.singletonList(secondProcessor));
|
|
|
+ compoundProcessor.execute(ingestDocument);
|
|
|
+
|
|
|
+ assertThat(firstProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(secondProcessor.getInvokedCounter(), equalTo(1));
|
|
|
+ }
|
|
|
}
|