3131import org .elasticsearch .cluster .ClusterChangedEvent ;
3232import org .elasticsearch .cluster .ClusterState ;
3333import org .elasticsearch .cluster .ClusterStateApplier ;
34+ import org .elasticsearch .cluster .metadata .AliasMetaData ;
3435import org .elasticsearch .cluster .metadata .IndexMetaData ;
3536import org .elasticsearch .cluster .metadata .IndexNameExpressionResolver ;
3637import org .elasticsearch .cluster .metadata .MetaData ;
@@ -80,6 +81,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
8081 * Index for which mock settings contain a default pipeline.
8182 */
8283 private static final String WITH_DEFAULT_PIPELINE = "index_with_default_pipeline" ;
84+ private static final String WITH_DEFAULT_PIPELINE_ALIAS = "alias_for_index_with_default_pipeline" ;
8385
8486 private static final Settings SETTINGS =
8587 Settings .builder ().put (AutoCreateIndex .AUTO_CREATE_INDEX_SETTING .getKey (), true ).build ();
@@ -190,7 +192,7 @@ public void setupAction() {
190192 IndexMetaData .builder (WITH_DEFAULT_PIPELINE ).settings (
191193 settings (Version .CURRENT ).put (IndexSettings .DEFAULT_PIPELINE .getKey (), "default_pipeline" )
192194 .build ()
193- ).numberOfShards (1 ).numberOfReplicas (1 ).build ()))
195+ ).putAlias ( AliasMetaData . builder ( WITH_DEFAULT_PIPELINE_ALIAS ). build ()). numberOfShards (1 ).numberOfReplicas (1 ).build ()))
194196 .build ()).build ();
195197 when (state .getMetaData ()).thenReturn (metaData );
196198 when (state .metaData ()).thenReturn (metaData );
@@ -399,15 +401,24 @@ public void testSingleItemBulkActionIngestForward() throws Exception {
399401 }
400402
401403 public void testUseDefaultPipeline () throws Exception {
404+ validateDefaultPipeline (new IndexRequest (WITH_DEFAULT_PIPELINE , "type" , "id" ));
405+ }
406+
407+ public void testUseDefaultPipelineWithAlias () throws Exception {
408+ validateDefaultPipeline (new IndexRequest (WITH_DEFAULT_PIPELINE_ALIAS , "type" , "id" ));
409+ }
410+
411+ public void testCreateIndexBeforeRunPipeline () throws Exception {
402412 Exception exception = new Exception ("fake exception" );
403- IndexRequest indexRequest = new IndexRequest (WITH_DEFAULT_PIPELINE , "type" , "id" );
413+ IndexRequest indexRequest = new IndexRequest ("missing_index" , "type" , "id" );
414+ indexRequest .setPipeline ("testpipeline" );
404415 indexRequest .source (Collections .emptyMap ());
405416 AtomicBoolean responseCalled = new AtomicBoolean (false );
406417 AtomicBoolean failureCalled = new AtomicBoolean (false );
418+ action .needToCheck = true ;
419+ action .indexCreated = false ;
407420 singleItemBulkWriteAction .execute (null , indexRequest , ActionListener .wrap (
408- response -> {
409- responseCalled .set (true );
410- },
421+ response -> responseCalled .set (true ),
411422 e -> {
412423 assertThat (e , sameInstance (exception ));
413424 failureCalled .set (true );
@@ -429,17 +440,15 @@ public void testUseDefaultPipeline() throws Exception {
429440 verifyZeroInteractions (transportService );
430441 }
431442
432- public void testCreateIndexBeforeRunPipeline () throws Exception {
443+ private void validateDefaultPipeline ( IndexRequest indexRequest ) {
433444 Exception exception = new Exception ("fake exception" );
434- IndexRequest indexRequest = new IndexRequest ("missing_index" , "type" , "id" );
435- indexRequest .setPipeline ("testpipeline" );
436445 indexRequest .source (Collections .emptyMap ());
437446 AtomicBoolean responseCalled = new AtomicBoolean (false );
438447 AtomicBoolean failureCalled = new AtomicBoolean (false );
439- action .needToCheck = true ;
440- action .indexCreated = false ;
441448 singleItemBulkWriteAction .execute (null , indexRequest , ActionListener .wrap (
442- response -> responseCalled .set (true ),
449+ response -> {
450+ responseCalled .set (true );
451+ },
443452 e -> {
444453 assertThat (e , sameInstance (exception ));
445454 failureCalled .set (true );
@@ -460,5 +469,4 @@ public void testCreateIndexBeforeRunPipeline() throws Exception {
460469 assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one
461470 verifyZeroInteractions (transportService );
462471 }
463-
464472}
0 commit comments