|
@@ -24,6 +24,7 @@ import org.elasticsearch.ingest.TestProcessor;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
import org.junit.Before;
|
|
|
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.Collections;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -31,6 +32,7 @@ import java.util.Map;
|
|
|
import static org.hamcrest.CoreMatchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.hasSize;
|
|
|
import static org.hamcrest.Matchers.is;
|
|
|
+import static org.hamcrest.Matchers.sameInstance;
|
|
|
|
|
|
public class CompoundProcessorTests extends ESTestCase {
|
|
|
private IngestDocument ingestDocument;
|
|
@@ -51,7 +53,7 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
TestProcessor processor = new TestProcessor(ingestDocument -> {});
|
|
|
CompoundProcessor compoundProcessor = new CompoundProcessor(processor);
|
|
|
assertThat(compoundProcessor.getProcessors().size(), equalTo(1));
|
|
|
- assertThat(compoundProcessor.getProcessors().get(0), equalTo(processor));
|
|
|
+ assertThat(compoundProcessor.getProcessors().get(0), sameInstance(processor));
|
|
|
assertThat(compoundProcessor.getOnFailureProcessors().isEmpty(), is(true));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
assertThat(processor.getInvokedCounter(), equalTo(1));
|
|
@@ -61,7 +63,7 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
TestProcessor processor = new TestProcessor(ingestDocument -> {throw new RuntimeException("error");});
|
|
|
CompoundProcessor compoundProcessor = new CompoundProcessor(processor);
|
|
|
assertThat(compoundProcessor.getProcessors().size(), equalTo(1));
|
|
|
- assertThat(compoundProcessor.getProcessors().get(0), equalTo(processor));
|
|
|
+ assertThat(compoundProcessor.getProcessors().get(0), sameInstance(processor));
|
|
|
assertThat(compoundProcessor.getOnFailureProcessors().isEmpty(), is(true));
|
|
|
try {
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
@@ -72,6 +74,16 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(processor.getInvokedCounter(), equalTo(1));
|
|
|
}
|
|
|
|
|
|
+ public void testIgnoreFailure() throws Exception {
|
|
|
+ TestProcessor processor1 = new TestProcessor(ingestDocument -> {throw new RuntimeException("error");});
|
|
|
+ TestProcessor processor2 = new TestProcessor(ingestDocument -> {ingestDocument.setFieldValue("field", "value");});
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(true, Arrays.asList(processor1, processor2), Collections.emptyList());
|
|
|
+ compoundProcessor.execute(ingestDocument);
|
|
|
+ assertThat(processor1.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(processor2.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(ingestDocument.getFieldValue("field", String.class), equalTo("value"));
|
|
|
+ }
|
|
|
+
|
|
|
public void testSingleProcessorWithOnFailureProcessor() throws Exception {
|
|
|
TestProcessor processor1 = new TestProcessor("id", "first", ingestDocument -> {throw new RuntimeException("error");});
|
|
|
TestProcessor processor2 = new TestProcessor(ingestDocument -> {
|
|
@@ -82,7 +94,8 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("id"));
|
|
|
});
|
|
|
|
|
|
- CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(processor1), Collections.singletonList(processor2));
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(processor1),
|
|
|
+ Collections.singletonList(processor2));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
|
|
|
assertThat(processor1.getInvokedCounter(), equalTo(1));
|
|
@@ -106,8 +119,10 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TYPE_FIELD), equalTo("second"));
|
|
|
assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("id2"));
|
|
|
});
|
|
|
- CompoundProcessor compoundOnFailProcessor = new CompoundProcessor(Collections.singletonList(processorToFail), Collections.singletonList(lastProcessor));
|
|
|
- CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(processor), Collections.singletonList(compoundOnFailProcessor));
|
|
|
+ CompoundProcessor compoundOnFailProcessor = new CompoundProcessor(false, Collections.singletonList(processorToFail),
|
|
|
+ Collections.singletonList(lastProcessor));
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(processor),
|
|
|
+ Collections.singletonList(compoundOnFailProcessor));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
|
|
|
assertThat(processorToFail.getInvokedCounter(), equalTo(1));
|
|
@@ -126,7 +141,7 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
|
|
|
CompoundProcessor failCompoundProcessor = new CompoundProcessor(firstProcessor);
|
|
|
|
|
|
- CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(failCompoundProcessor),
|
|
|
Collections.singletonList(secondProcessor));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
|
|
@@ -136,7 +151,8 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
|
|
|
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 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));
|
|
@@ -145,10 +161,10 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("tag_fail"));
|
|
|
});
|
|
|
|
|
|
- CompoundProcessor failCompoundProcessor = new CompoundProcessor(Collections.singletonList(firstProcessor),
|
|
|
+ CompoundProcessor failCompoundProcessor = new CompoundProcessor(false, Collections.singletonList(firstProcessor),
|
|
|
Collections.singletonList(failProcessor));
|
|
|
|
|
|
- CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(failCompoundProcessor),
|
|
|
Collections.singletonList(secondProcessor));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
|
|
@@ -158,7 +174,8 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
|
|
|
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 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));
|
|
@@ -167,10 +184,10 @@ public class CompoundProcessorTests extends ESTestCase {
|
|
|
assertThat(ingestMetadata.get(CompoundProcessor.ON_FAILURE_PROCESSOR_TAG_FIELD), equalTo("tag_fail"));
|
|
|
});
|
|
|
|
|
|
- CompoundProcessor failCompoundProcessor = new CompoundProcessor(Collections.singletonList(firstProcessor),
|
|
|
+ CompoundProcessor failCompoundProcessor = new CompoundProcessor(false, Collections.singletonList(firstProcessor),
|
|
|
Collections.singletonList(new CompoundProcessor(failProcessor)));
|
|
|
|
|
|
- CompoundProcessor compoundProcessor = new CompoundProcessor(Collections.singletonList(failCompoundProcessor),
|
|
|
+ CompoundProcessor compoundProcessor = new CompoundProcessor(false, Collections.singletonList(failCompoundProcessor),
|
|
|
Collections.singletonList(secondProcessor));
|
|
|
compoundProcessor.execute(ingestDocument);
|
|
|
|