|
@@ -20,14 +20,15 @@
|
|
|
package org.elasticsearch.action.ingest;
|
|
|
|
|
|
import org.elasticsearch.ElasticsearchException;
|
|
|
-import org.elasticsearch.common.settings.Settings;
|
|
|
+import org.elasticsearch.ingest.DropProcessor;
|
|
|
+import org.elasticsearch.ingest.Processor;
|
|
|
import org.elasticsearch.ingest.RandomDocumentPicks;
|
|
|
import org.elasticsearch.ingest.TestProcessor;
|
|
|
import org.elasticsearch.ingest.CompoundProcessor;
|
|
|
import org.elasticsearch.ingest.IngestDocument;
|
|
|
import org.elasticsearch.ingest.Pipeline;
|
|
|
import org.elasticsearch.test.ESTestCase;
|
|
|
-import org.elasticsearch.threadpool.ThreadPool;
|
|
|
+import org.elasticsearch.threadpool.TestThreadPool;
|
|
|
import org.junit.After;
|
|
|
import org.junit.Before;
|
|
|
|
|
@@ -38,6 +39,7 @@ import static org.elasticsearch.ingest.IngestDocumentMatcher.assertIngestDocumen
|
|
|
import static org.hamcrest.Matchers.equalTo;
|
|
|
import static org.hamcrest.Matchers.instanceOf;
|
|
|
import static org.hamcrest.Matchers.not;
|
|
|
+import static org.hamcrest.Matchers.notNullValue;
|
|
|
import static org.hamcrest.Matchers.nullValue;
|
|
|
import static org.hamcrest.Matchers.sameInstance;
|
|
|
|
|
@@ -45,17 +47,13 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
|
|
|
private final Integer version = randomBoolean() ? randomInt() : null;
|
|
|
|
|
|
- private ThreadPool threadPool;
|
|
|
+ private TestThreadPool threadPool;
|
|
|
private SimulateExecutionService executionService;
|
|
|
private IngestDocument ingestDocument;
|
|
|
|
|
|
@Before
|
|
|
public void setup() {
|
|
|
- threadPool = new ThreadPool(
|
|
|
- Settings.builder()
|
|
|
- .put("node.name", getClass().getName())
|
|
|
- .build()
|
|
|
- );
|
|
|
+ threadPool = new TestThreadPool(SimulateExecutionServiceTests.class.getSimpleName());
|
|
|
executionService = new SimulateExecutionService(threadPool);
|
|
|
ingestDocument = RandomDocumentPicks.randomIngestDocument(random());
|
|
|
}
|
|
@@ -213,4 +211,52 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
assertThat(exception, instanceOf(ElasticsearchException.class));
|
|
|
assertThat(exception.getMessage(), equalTo("java.lang.IllegalArgumentException: java.lang.RuntimeException: processor failed"));
|
|
|
}
|
|
|
+
|
|
|
+ public void testDropDocument() {
|
|
|
+ TestProcessor processor1 = new TestProcessor(ingestDocument -> ingestDocument.setFieldValue("field", "value"));
|
|
|
+ Processor processor2 = new DropProcessor.Factory().create(Map.of(), null, Map.of());
|
|
|
+ Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor1, processor2));
|
|
|
+
|
|
|
+ SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, false);
|
|
|
+ assertThat(processor1.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(actualItemResponse, instanceOf(SimulateDocumentBaseResult.class));
|
|
|
+ SimulateDocumentBaseResult simulateDocumentBaseResult = (SimulateDocumentBaseResult) actualItemResponse;
|
|
|
+ assertThat(simulateDocumentBaseResult.getIngestDocument(), nullValue());
|
|
|
+ assertThat(simulateDocumentBaseResult.getFailure(), nullValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testDropDocumentVerbose() {
|
|
|
+ TestProcessor processor1 = new TestProcessor(ingestDocument -> ingestDocument.setFieldValue("field", "value"));
|
|
|
+ Processor processor2 = new DropProcessor.Factory().create(Map.of(), null, Map.of());
|
|
|
+ Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor1, processor2));
|
|
|
+
|
|
|
+ SimulateDocumentResult actualItemResponse = executionService.executeDocument(pipeline, ingestDocument, true);
|
|
|
+ assertThat(processor1.getInvokedCounter(), equalTo(1));
|
|
|
+ assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
|
|
|
+ SimulateDocumentVerboseResult verboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
|
|
|
+ assertThat(verboseResult.getProcessorResults().size(), equalTo(2));
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(0).getIngestDocument(), notNullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(0).getFailure(), nullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(1).getIngestDocument(), nullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(1).getFailure(), nullValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testDropDocumentVerboseExtraProcessor() {
|
|
|
+ TestProcessor processor1 = new TestProcessor(ingestDocument -> ingestDocument.setFieldValue("field1", "value"));
|
|
|
+ Processor processor2 = new DropProcessor.Factory().create(Map.of(), null, Map.of());
|
|
|
+ TestProcessor processor3 = new TestProcessor(ingestDocument -> ingestDocument.setFieldValue("field2", "value"));
|
|
|
+ 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(processor3.getInvokedCounter(), equalTo(0));
|
|
|
+ assertThat(actualItemResponse, instanceOf(SimulateDocumentVerboseResult.class));
|
|
|
+ SimulateDocumentVerboseResult verboseResult = (SimulateDocumentVerboseResult) actualItemResponse;
|
|
|
+ assertThat(verboseResult.getProcessorResults().size(), equalTo(2));
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(0).getIngestDocument(), notNullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(0).getFailure(), nullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(1).getIngestDocument(), nullValue());
|
|
|
+ assertThat(verboseResult.getProcessorResults().get(1).getFailure(), nullValue());
|
|
|
+ }
|
|
|
+
|
|
|
}
|