7777import  java .util .concurrent .Future ;
7878import  java .util .concurrent .TimeUnit ;
7979import  java .util .concurrent .atomic .AtomicBoolean ;
80- import  java .util .function .BiConsumer ;
8180import  java .util .function .Function ;
8281
8382import  static  org .hamcrest .Matchers .containsString ;
8483import  static  org .hamcrest .Matchers .sameInstance ;
8584import  static  org .mockito .ArgumentMatchers .any ;
8685import  static  org .mockito .ArgumentMatchers .anyInt ;
8786import  static  org .mockito .ArgumentMatchers .eq ;
88- import  static  org .mockito .ArgumentMatchers .same ;
8987import  static  org .mockito .Mockito .doAnswer ;
9088import  static  org .mockito .Mockito .mock ;
9189import  static  org .mockito .Mockito .never ;
@@ -127,7 +125,7 @@ public class TransportBulkActionIngestTests extends ESTestCase {
127125    @ Captor 
128126    ArgumentCaptor <TriConsumer <Integer , Exception , IndexDocFailureStoreStatus >> failureHandler ;
129127    @ Captor 
130-     ArgumentCaptor <BiConsumer < Thread ,  Exception >> completionHandler ;
128+     ArgumentCaptor <ActionListener < Void >> listener ;
131129    @ Captor 
132130    ArgumentCaptor <TransportResponseHandler <BulkResponse >> remoteResponseHandler ;
133131    @ Captor 
@@ -425,10 +423,9 @@ public void testIngestLocal() throws Exception {
425423            redirectPredicate .capture (),
426424            redirectHandler .capture (),
427425            failureHandler .capture (),
428-             completionHandler .capture (),
429-             same (writeCoordinationExecutor )
426+             listener .capture ()
430427        );
431-         completionHandler .getValue ().accept ( null ,  exception );
428+         listener .getValue ().onFailure ( exception );
432429        assertTrue (failureCalled .get ());
433430
434431        // now check success 
@@ -441,7 +438,7 @@ public void testIngestLocal() throws Exception {
441438        assertNull (redirectPredicate .getValue ().apply (WITH_DEFAULT_PIPELINE )); // no redirects for random existing indices 
442439        assertNull (redirectPredicate .getValue ().apply ("index" )); // no redirects for non-existent indices with no templates 
443440        redirectHandler .getValue ().apply (2 , WITH_FAILURE_STORE_ENABLED  + "-1" , exception ); // exception and redirect for request 3 (slot 2) 
444-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null ); // all ingestion completed 
441+         listener .getValue ().onResponse ( null ); // all ingestion completed 
445442        assertTrue (action .isExecuted );
446443        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
447444        verifyNoMoreInteractions (transportService );
@@ -476,15 +473,14 @@ public void testSingleItemBulkActionIngestLocal() throws Exception {
476473            any (),
477474            any (),
478475            failureHandler .capture (),
479-             completionHandler .capture (),
480-             same (writeCoordinationExecutor )
476+             listener .capture ()
481477        );
482-         completionHandler .getValue ().accept ( null ,  exception );
478+         listener .getValue ().onFailure ( exception );
483479        assertTrue (failureCalled .get ());
484480
485481        // now check success 
486482        indexRequest .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
487-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null );
483+         listener .getValue ().onResponse ( null );
488484        assertTrue (action .isExecuted );
489485        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
490486        verifyNoMoreInteractions (transportService );
@@ -525,18 +521,17 @@ public void testIngestSystemLocal() throws Exception {
525521            any (),
526522            any (),
527523            failureHandler .capture (),
528-             completionHandler .capture (),
529-             same (systemWriteCoordinationExecutor )
524+             listener .capture ()
530525        );
531-         completionHandler .getValue ().accept ( null ,  exception );
526+         listener .getValue ().onFailure ( exception );
532527        assertTrue (failureCalled .get ());
533528
534529        // now check success 
535530        Iterator <DocWriteRequest <?>> req  = bulkDocsItr .getValue ().iterator ();
536531        // have an exception for our one index request 
537532        failureHandler .getValue ().apply (0 , exception , IndexDocFailureStoreStatus .NOT_APPLICABLE_OR_UNKNOWN );
538533        indexRequest2 .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
539-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null );
534+         listener .getValue ().onResponse ( null );
540535        assertTrue (action .isExecuted );
541536        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
542537        verifyNoMoreInteractions (transportService );
@@ -558,7 +553,7 @@ public void testIngestForward() throws Exception {
558553        ActionTestUtils .execute (action , null , bulkRequest , listener );
559554
560555        // should not have executed ingest locally 
561-         verify (ingestService , never ()).executeBulkRequest (eq (projectId ), anyInt (), any (), any (), any (), any (), any (), any (),  any () );
556+         verify (ingestService , never ()).executeBulkRequest (eq (projectId ), anyInt (), any (), any (), any (), any (), any (), any ());
562557        // but instead should have sent to a remote node with the transport service 
563558        ArgumentCaptor <DiscoveryNode > node  = ArgumentCaptor .forClass (DiscoveryNode .class );
564559        verify (transportService ).sendRequest (node .capture (), eq (TransportBulkAction .NAME ), any (), remoteResponseHandler .capture ());
@@ -598,7 +593,7 @@ public void testSingleItemBulkActionIngestForward() throws Exception {
598593        ActionTestUtils .execute (singleItemBulkWriteAction , null , indexRequest , listener );
599594
600595        // should not have executed ingest locally 
601-         verify (ingestService , never ()).executeBulkRequest (eq (projectId ), anyInt (), any (), any (), any (), any (), any (), any (),  any () );
596+         verify (ingestService , never ()).executeBulkRequest (eq (projectId ), anyInt (), any (), any (), any (), any (), any (), any ());
602597        // but instead should have sent to a remote node with the transport service 
603598        ArgumentCaptor <DiscoveryNode > node  = ArgumentCaptor .forClass (DiscoveryNode .class );
604599        verify (transportService ).sendRequest (node .capture (), eq (TransportBulkAction .NAME ), any (), remoteResponseHandler .capture ());
@@ -686,20 +681,19 @@ private void validatePipelineWithBulkUpsert(@Nullable String indexRequestIndexNa
686681            any (),
687682            any (),
688683            failureHandler .capture (),
689-             completionHandler .capture (),
690-             same (writeCoordinationExecutor )
684+             listener .capture ()
691685        );
692686        assertEquals (indexRequest1 .getPipeline (), "default_pipeline" );
693687        assertEquals (indexRequest2 .getPipeline (), "default_pipeline" );
694688        assertEquals (indexRequest3 .getPipeline (), "default_pipeline" );
695-         completionHandler .getValue ().accept ( null ,  exception );
689+         listener .getValue ().onFailure ( exception );
696690        assertTrue (failureCalled .get ());
697691
698692        // now check success of the transport bulk action 
699693        indexRequest1 .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
700694        indexRequest2 .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
701695        indexRequest3 .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
702-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null );
696+         listener .getValue ().onResponse ( null );
703697        assertTrue (action .isExecuted );
704698        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
705699        verifyNoMoreInteractions (transportService );
@@ -737,16 +731,15 @@ public void testDoExecuteCalledTwiceCorrectly() throws Exception {
737731            any (),
738732            any (),
739733            failureHandler .capture (),
740-             completionHandler .capture (),
741-             same (writeCoordinationExecutor )
734+             listener .capture ()
742735        );
743-         completionHandler .getValue ().accept ( null ,  exception );
736+         listener .getValue ().onFailure ( exception );
744737        assertFalse (action .indexCreated ); // still no index yet, the ingest node failed. 
745738        assertTrue (failureCalled .get ());
746739
747740        // now check success 
748741        indexRequest .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
749-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null );
742+         listener .getValue ().onResponse ( null );
750743        assertTrue (action .isExecuted );
751744        assertTrue (action .indexCreated ); // now the index is created since we skipped the ingest node path. 
752745        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
@@ -831,8 +824,7 @@ public void testFindDefaultPipelineFromTemplateMatch() {
831824            any (),
832825            any (),
833826            failureHandler .capture (),
834-             completionHandler .capture (),
835-             same (writeCoordinationExecutor )
827+             listener .capture ()
836828        );
837829    }
838830
@@ -872,8 +864,7 @@ public void testFindDefaultPipelineFromV2TemplateMatch() {
872864            any (),
873865            any (),
874866            failureHandler .capture (),
875-             completionHandler .capture (),
876-             same (writeCoordinationExecutor )
867+             listener .capture ()
877868        );
878869    }
879870
@@ -902,11 +893,10 @@ public void testIngestCallbackExceptionHandled() throws Exception {
902893            any (),
903894            any (),
904895            failureHandler .capture (),
905-             completionHandler .capture (),
906-             same (writeCoordinationExecutor )
896+             listener .capture ()
907897        );
908898        indexRequest1 .autoGenerateId ();
909-         completionHandler .getValue ().accept ( Thread . currentThread (),  null );
899+         listener .getValue ().onResponse ( null );
910900
911901        // check failure passed through to the listener 
912902        assertFalse (action .isExecuted );
@@ -942,16 +932,15 @@ private void validateDefaultPipeline(IndexRequest indexRequest) {
942932            any (),
943933            any (),
944934            failureHandler .capture (),
945-             completionHandler .capture (),
946-             same (writeCoordinationExecutor )
935+             listener .capture ()
947936        );
948937        assertEquals (indexRequest .getPipeline (), "default_pipeline" );
949-         completionHandler .getValue ().accept ( null ,  exception );
938+         listener .getValue ().onFailure ( exception );
950939        assertTrue (failureCalled .get ());
951940
952941        // now check success 
953942        indexRequest .setPipeline (IngestService .NOOP_PIPELINE_NAME ); // this is done by the real pipeline execution service when processing 
954-         completionHandler .getValue ().accept ( DUMMY_WRITE_THREAD ,  null );
943+         listener .getValue ().onResponse ( null );
955944        assertTrue (action .isExecuted );
956945        assertFalse (responseCalled .get ()); // listener would only be called by real index action, not our mocked one 
957946        verifyNoMoreInteractions (transportService );
0 commit comments