|
@@ -28,6 +28,7 @@ import org.elasticsearch.action.index.IndexRequest;
|
|
|
import org.elasticsearch.action.index.IndexResponse;
|
|
|
import org.elasticsearch.action.support.ActionFilters;
|
|
|
import org.elasticsearch.action.support.AutoCreateIndex;
|
|
|
+import org.elasticsearch.action.update.UpdateRequest;
|
|
|
import org.elasticsearch.cluster.ClusterChangedEvent;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.ClusterStateApplier;
|
|
@@ -408,6 +409,57 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
validateDefaultPipeline(new IndexRequest(WITH_DEFAULT_PIPELINE_ALIAS, "type", "id"));
|
|
|
}
|
|
|
|
|
|
+ public void testUseDefaultPipelineWithBulkUpsert() throws Exception {
|
|
|
+ Exception exception = new Exception("fake exception");
|
|
|
+ BulkRequest bulkRequest = new BulkRequest();
|
|
|
+ IndexRequest indexRequest1 = new IndexRequest(WITH_DEFAULT_PIPELINE, "type", "id1").source(Collections.emptyMap());
|
|
|
+ IndexRequest indexRequest2 = new IndexRequest(WITH_DEFAULT_PIPELINE, "type", "id2").source(Collections.emptyMap());
|
|
|
+ IndexRequest indexRequest3 = new IndexRequest(WITH_DEFAULT_PIPELINE, "type", "id3").source(Collections.emptyMap());
|
|
|
+ UpdateRequest upsertRequest = new UpdateRequest(WITH_DEFAULT_PIPELINE, "type", "id1").upsert(indexRequest1).script(mockScript("1"));
|
|
|
+ UpdateRequest docAsUpsertRequest = new UpdateRequest(WITH_DEFAULT_PIPELINE, "type", "id2").doc(indexRequest2).docAsUpsert(true);
|
|
|
+ // this test only covers the mechanics that scripted bulk upserts will execute a default pipeline. However, in practice scripted
|
|
|
+ // bulk upserts with a default pipeline are a bit surprising since the script executes AFTER the pipeline.
|
|
|
+ UpdateRequest scriptedUpsert = new UpdateRequest(WITH_DEFAULT_PIPELINE, "type", "id2").upsert(indexRequest3).script(mockScript("1"))
|
|
|
+ .scriptedUpsert(true);
|
|
|
+ bulkRequest.add(upsertRequest).add(docAsUpsertRequest).add(scriptedUpsert);
|
|
|
+
|
|
|
+ AtomicBoolean responseCalled = new AtomicBoolean(false);
|
|
|
+ AtomicBoolean failureCalled = new AtomicBoolean(false);
|
|
|
+ assertNull(indexRequest1.getPipeline());
|
|
|
+ assertNull(indexRequest2.getPipeline());
|
|
|
+ assertNull(indexRequest3.getPipeline());
|
|
|
+ action.execute(null, bulkRequest, ActionListener.wrap(
|
|
|
+ response -> {
|
|
|
+ BulkItemResponse itemResponse = response.iterator().next();
|
|
|
+ assertThat(itemResponse.getFailure().getMessage(), containsString("fake exception"));
|
|
|
+ responseCalled.set(true);
|
|
|
+ },
|
|
|
+ e -> {
|
|
|
+ assertThat(e, sameInstance(exception));
|
|
|
+ failureCalled.set(true);
|
|
|
+ }));
|
|
|
+
|
|
|
+ // check failure works, and passes through to the listener
|
|
|
+ assertFalse(action.isExecuted); // haven't executed yet
|
|
|
+ assertFalse(responseCalled.get());
|
|
|
+ assertFalse(failureCalled.get());
|
|
|
+ verify(ingestService).executeBulkRequest(bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any());
|
|
|
+ assertEquals(indexRequest1.getPipeline(), "default_pipeline");
|
|
|
+ assertEquals(indexRequest2.getPipeline(), "default_pipeline");
|
|
|
+ assertEquals(indexRequest3.getPipeline(), "default_pipeline");
|
|
|
+ completionHandler.getValue().accept(exception);
|
|
|
+ assertTrue(failureCalled.get());
|
|
|
+
|
|
|
+ // now check success of the transport bulk action
|
|
|
+ indexRequest1.setPipeline(IngestService.NOOP_PIPELINE_NAME); // this is done by the real pipeline execution service when processing
|
|
|
+ indexRequest2.setPipeline(IngestService.NOOP_PIPELINE_NAME); // this is done by the real pipeline execution service when processing
|
|
|
+ indexRequest3.setPipeline(IngestService.NOOP_PIPELINE_NAME); // this is done by the real pipeline execution service when processing
|
|
|
+ completionHandler.getValue().accept(null);
|
|
|
+ assertTrue(action.isExecuted);
|
|
|
+ assertFalse(responseCalled.get()); // listener would only be called by real index action, not our mocked one
|
|
|
+ verifyZeroInteractions(transportService);
|
|
|
+ }
|
|
|
+
|
|
|
public void testCreateIndexBeforeRunPipeline() throws Exception {
|
|
|
Exception exception = new Exception("fake exception");
|
|
|
IndexRequest indexRequest = new IndexRequest("missing_index", "type", "id");
|
|
@@ -445,6 +497,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
indexRequest.source(Collections.emptyMap());
|
|
|
AtomicBoolean responseCalled = new AtomicBoolean(false);
|
|
|
AtomicBoolean failureCalled = new AtomicBoolean(false);
|
|
|
+ assertNull(indexRequest.getPipeline());
|
|
|
singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(
|
|
|
response -> {
|
|
|
responseCalled.set(true);
|
|
@@ -459,6 +512,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
assertFalse(responseCalled.get());
|
|
|
assertFalse(failureCalled.get());
|
|
|
verify(ingestService).executeBulkRequest(bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture(), any());
|
|
|
+ assertEquals(indexRequest.getPipeline(), "default_pipeline");
|
|
|
completionHandler.getValue().accept(exception);
|
|
|
assertTrue(failureCalled.get());
|
|
|
|