|
@@ -19,6 +19,7 @@
|
|
|
|
|
|
package org.elasticsearch.action.bulk;
|
|
|
|
|
|
+import org.elasticsearch.Version;
|
|
|
import org.elasticsearch.action.ActionListener;
|
|
|
import org.elasticsearch.action.DocWriteRequest;
|
|
|
import org.elasticsearch.action.index.IndexAction;
|
|
@@ -28,6 +29,8 @@ import org.elasticsearch.action.support.ActionFilters;
|
|
|
import org.elasticsearch.cluster.ClusterChangedEvent;
|
|
|
import org.elasticsearch.cluster.ClusterState;
|
|
|
import org.elasticsearch.cluster.ClusterStateApplier;
|
|
|
+import org.elasticsearch.cluster.metadata.IndexMetaData;
|
|
|
+import org.elasticsearch.cluster.metadata.MetaData;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNode;
|
|
|
import org.elasticsearch.cluster.node.DiscoveryNodes;
|
|
|
import org.elasticsearch.cluster.service.ClusterService;
|
|
@@ -35,6 +38,7 @@ import org.elasticsearch.common.collect.ImmutableOpenMap;
|
|
|
import org.elasticsearch.common.settings.Settings;
|
|
|
import org.elasticsearch.common.util.concurrent.AtomicArray;
|
|
|
import org.elasticsearch.index.IndexNotFoundException;
|
|
|
+import org.elasticsearch.index.IndexSettings;
|
|
|
import org.elasticsearch.ingest.IngestService;
|
|
|
import org.elasticsearch.ingest.PipelineExecutionService;
|
|
|
import org.elasticsearch.tasks.Task;
|
|
@@ -68,6 +72,11 @@ import static org.mockito.Mockito.when;
|
|
|
|
|
|
public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
|
|
|
+ /**
|
|
|
+ * Index for which mock settings contain a default pipeline.
|
|
|
+ */
|
|
|
+ private static final String WITH_DEFAULT_PIPELINE = "index_with_default_pipeline";
|
|
|
+
|
|
|
/** Services needed by bulk action */
|
|
|
TransportService transportService;
|
|
|
ClusterService clusterService;
|
|
@@ -153,6 +162,15 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
when(nodes.getIngestNodes()).thenReturn(ingestNodes);
|
|
|
ClusterState state = mock(ClusterState.class);
|
|
|
when(state.getNodes()).thenReturn(nodes);
|
|
|
+ when(state.getMetaData()).thenReturn(MetaData.builder().indices(ImmutableOpenMap.<String, IndexMetaData>builder()
|
|
|
+ .putAll(
|
|
|
+ Collections.singletonMap(
|
|
|
+ WITH_DEFAULT_PIPELINE,
|
|
|
+ IndexMetaData.builder(WITH_DEFAULT_PIPELINE).settings(
|
|
|
+ settings(Version.CURRENT).put(IndexSettings.DEFAULT_PIPELINE.getKey(), "default_pipeline")
|
|
|
+ .build()
|
|
|
+ ).numberOfShards(1).numberOfReplicas(1).build()))
|
|
|
+ .build()).build());
|
|
|
when(clusterService.state()).thenReturn(state);
|
|
|
doAnswer(invocation -> {
|
|
|
ClusterChangedEvent event = mock(ClusterChangedEvent.class);
|
|
@@ -227,7 +245,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
// now check success
|
|
|
Iterator<DocWriteRequest<?>> req = bulkDocsItr.getValue().iterator();
|
|
|
failureHandler.getValue().accept((IndexRequest)req.next(), exception); // have an exception for our one index request
|
|
|
- indexRequest2.setPipeline(null); // 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
|
|
|
completionHandler.getValue().accept(null);
|
|
|
assertTrue(action.isExecuted);
|
|
|
assertFalse(responseCalled.get()); // listener would only be called by real index action, not our mocked one
|
|
@@ -259,7 +277,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
assertTrue(failureCalled.get());
|
|
|
|
|
|
// now check success
|
|
|
- indexRequest.setPipeline(null); // this is done by the real pipeline execution service when processing
|
|
|
+ indexRequest.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
|
|
@@ -359,4 +377,35 @@ public class TransportBulkActionIngestTests extends ESTestCase {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public void testUseDefaultPipeline() throws Exception {
|
|
|
+ Exception exception = new Exception("fake exception");
|
|
|
+ IndexRequest indexRequest = new IndexRequest(WITH_DEFAULT_PIPELINE, "type", "id");
|
|
|
+ indexRequest.source(Collections.emptyMap());
|
|
|
+ AtomicBoolean responseCalled = new AtomicBoolean(false);
|
|
|
+ AtomicBoolean failureCalled = new AtomicBoolean(false);
|
|
|
+ singleItemBulkWriteAction.execute(null, indexRequest, ActionListener.wrap(
|
|
|
+ response -> {
|
|
|
+ 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(executionService).executeBulkRequest(bulkDocsItr.capture(), failureHandler.capture(), completionHandler.capture());
|
|
|
+ completionHandler.getValue().accept(exception);
|
|
|
+ assertTrue(failureCalled.get());
|
|
|
+
|
|
|
+ // now check success
|
|
|
+ indexRequest.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);
|
|
|
+ }
|
|
|
+
|
|
|
}
|