|
@@ -91,23 +91,17 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
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).getProcessorTag(), equalTo("test-id"));
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(0), pipeline.getId(), ingestDocument);
|
|
|
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())));
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(1), pipeline.getId(), ingestDocument);
|
|
|
+ assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getIngestDocument().getSourceAndMetadata(),
|
|
|
+ not(sameInstance(simulateDocumentVerboseResult.getProcessorResults().get(0).getIngestDocument().getSourceAndMetadata())));
|
|
|
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(1).getFailure(), nullValue());
|
|
|
}
|
|
|
-
|
|
|
public void testExecuteItem() throws Exception {
|
|
|
TestProcessor processor = new TestProcessor("processor_0", "mock", ingestDocument -> {});
|
|
|
Pipeline pipeline = new Pipeline("_id", "_description", version, new CompoundProcessor(processor, processor));
|
|
@@ -147,10 +141,7 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
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())));
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(0), pipeline.getId(), ingestDocument);
|
|
|
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));
|
|
@@ -191,14 +182,12 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
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);
|
|
|
-
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(1), pipeline.getId(),
|
|
|
+ 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);
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(2), pipeline.getId(), ingestDocument);
|
|
|
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(2).getFailure(), nullValue());
|
|
|
}
|
|
|
|
|
@@ -221,10 +210,7 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
assertThat(simulateDocumentVerboseResult.getProcessorResults().size(), equalTo(1));
|
|
|
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getProcessorTag(), equalTo("processor_0"));
|
|
|
assertThat(simulateDocumentVerboseResult.getProcessorResults().get(0).getFailure(), sameInstance(exception));
|
|
|
- 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())));
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(0), pipeline.getId(), ingestDocument);
|
|
|
}
|
|
|
|
|
|
public void testExecuteVerboseItemWithoutExceptionAndWithIgnoreFailure() throws Exception {
|
|
@@ -245,10 +231,7 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
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())));
|
|
|
+ assertVerboseResult(simulateDocumentVerboseResult.getProcessorResults().get(0), pipeline.getId(), ingestDocument);
|
|
|
}
|
|
|
|
|
|
public void testExecuteItemWithFailure() throws Exception {
|
|
@@ -392,4 +375,19 @@ public class SimulateExecutionServiceTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private static void assertVerboseResult(SimulateProcessorResult result,
|
|
|
+ String expectedPipelineId,
|
|
|
+ IngestDocument expectedIngestDocument) {
|
|
|
+ IngestDocument simulateVerboseIngestDocument = result.getIngestDocument();
|
|
|
+ // Remove and compare pipeline key. It is always in the verbose result,
|
|
|
+ // since that is a snapshot of how the ingest doc looks during pipeline execution, but not in the final ingestDocument.
|
|
|
+ // The key gets added and removed during pipeline execution.
|
|
|
+ String actualPipelineId = (String) simulateVerboseIngestDocument.getIngestMetadata().remove("pipeline");
|
|
|
+ assertThat(actualPipelineId, equalTo(expectedPipelineId));
|
|
|
+
|
|
|
+ assertThat(simulateVerboseIngestDocument, not(sameInstance(expectedIngestDocument)));
|
|
|
+ assertIngestDocument(simulateVerboseIngestDocument, expectedIngestDocument);
|
|
|
+ assertThat(simulateVerboseIngestDocument.getSourceAndMetadata(), not(sameInstance(expectedIngestDocument.getSourceAndMetadata())));
|
|
|
+ }
|
|
|
+
|
|
|
}
|