@@ -799,6 +799,164 @@ void flb_test_logstash_prefix_separator()
799799 flb_destroy (ctx );
800800}
801801
802+ static void cb_check_response_success (void * ctx , int ffd ,
803+ int res_ret , void * res_data ,
804+ size_t res_size , void * data )
805+ {
806+ TEST_CHECK (res_ret == 1 );
807+ }
808+
809+ void flb_test_response_success ()
810+ {
811+ int ret ;
812+ char * response = "{\"took\":1,\"errors\":false,\"items\":[]}" ;
813+ int size = 37 ;
814+ flb_ctx_t * ctx ;
815+ int in_ffd ;
816+ int out_ffd ;
817+
818+ /* Create context, flush every second (some checks omitted here) */
819+ ctx = flb_create ();
820+ flb_service_set (ctx , "flush" , "1" , "grace" , "1" , NULL );
821+
822+ /* Lib input mode */
823+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
824+ flb_input_set (ctx , in_ffd , "tag" , "test" , NULL );
825+
826+ /* Elasticsearch output */
827+ out_ffd = flb_output (ctx , (char * ) "es" , NULL );
828+ flb_output_set (ctx , out_ffd ,
829+ "match" , "test" ,
830+ NULL );
831+
832+ /* Override defaults of index and type */
833+ flb_output_set (ctx , out_ffd ,
834+ "write_operation" , "create" ,
835+ NULL );
836+
837+ /* Enable test mode */
838+ ret = flb_output_set_http_test (ctx , out_ffd , "response" ,
839+ cb_check_response_success ,
840+ NULL );
841+
842+ /* Start */
843+ ret = flb_start (ctx );
844+ TEST_CHECK (ret == 0 );
845+
846+ /* Ingest data sample */
847+ ret = flb_lib_response (ctx , out_ffd , 200 , response , size );
848+ TEST_CHECK (ret == 0 );
849+
850+ sleep (2 );
851+ flb_stop (ctx );
852+ flb_destroy (ctx );
853+ }
854+
855+ void flb_test_response_successes ()
856+ {
857+ int ret ;
858+ char * response = JSON_RESPONSE_SUCCESSES ;
859+ int size = JSON_RESPONSE_SUCCESSES_SIZE ;
860+ flb_ctx_t * ctx ;
861+ int in_ffd ;
862+ int out_ffd ;
863+
864+ /* Create context, flush every second (some checks omitted here) */
865+ ctx = flb_create ();
866+ flb_service_set (ctx , "flush" , "1" , "grace" , "1" , NULL );
867+
868+ /* Lib input mode */
869+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
870+ flb_input_set (ctx , in_ffd , "tag" , "test" , NULL );
871+
872+ /* Elasticsearch output */
873+ out_ffd = flb_output (ctx , (char * ) "es" , NULL );
874+ flb_output_set (ctx , out_ffd ,
875+ "match" , "test" ,
876+ NULL );
877+
878+ /* Override defaults of index and type */
879+ flb_output_set (ctx , out_ffd ,
880+ "write_operation" , "create" ,
881+ NULL );
882+
883+ /* Enable test mode */
884+ ret = flb_output_set_http_test (ctx , out_ffd , "response" ,
885+ cb_check_response_success ,
886+ NULL );
887+
888+ /* Start */
889+ ret = flb_start (ctx );
890+ TEST_CHECK (ret == 0 );
891+
892+ /* Ingest data sample */
893+ ret = flb_lib_response (ctx , out_ffd , 200 , response , size );
894+ TEST_CHECK (ret == 0 );
895+
896+ sleep (2 );
897+ flb_stop (ctx );
898+ flb_destroy (ctx );
899+ }
900+
901+ static void cb_check_response_partially_success (void * ctx , int ffd ,
902+ int res_ret , void * res_data ,
903+ size_t res_size , void * data )
904+ {
905+ int composed_ret = 0 ;
906+ composed_ret |= (1 << 0 );
907+ composed_ret |= (1 << 7 );
908+
909+ TEST_CHECK (res_ret == composed_ret );
910+ /* Check whether contains a success flag or not */
911+ TEST_CHECK ((res_ret & (1 << 0 )));
912+ }
913+
914+ void flb_test_response_partially_success ()
915+ {
916+ int ret ;
917+ char * response = JSON_RESPONSE_PARTIALLY_SUCCESS ;
918+ int size = JSON_RESPONSE_PARTIALLY_SUCCESS_SIZE ;
919+ flb_ctx_t * ctx ;
920+ int in_ffd ;
921+ int out_ffd ;
922+
923+ /* Create context, flush every second (some checks omitted here) */
924+ ctx = flb_create ();
925+ flb_service_set (ctx , "flush" , "1" , "grace" , "1" , NULL );
926+
927+ /* Lib input mode */
928+ in_ffd = flb_input (ctx , (char * ) "lib" , NULL );
929+ flb_input_set (ctx , in_ffd , "tag" , "test" , NULL );
930+
931+ /* Elasticsearch output */
932+ out_ffd = flb_output (ctx , (char * ) "es" , NULL );
933+ flb_output_set (ctx , out_ffd ,
934+ "match" , "test" ,
935+ NULL );
936+
937+ /* Override defaults of index and type */
938+ flb_output_set (ctx , out_ffd ,
939+ "write_operation" , "create" ,
940+ NULL );
941+
942+ /* Enable test mode */
943+ ret = flb_output_set_http_test (ctx , out_ffd , "response" ,
944+ cb_check_response_partially_success ,
945+ NULL );
946+
947+ /* Start */
948+ ret = flb_start (ctx );
949+ TEST_CHECK (ret == 0 );
950+
951+ /* Ingest data sample */
952+ ret = flb_lib_response (ctx , out_ffd , 200 , response , size );
953+ TEST_CHECK (ret == 0 );
954+
955+ sleep (2 );
956+ flb_stop (ctx );
957+ flb_destroy (ctx );
958+ }
959+
802960/* Test list */
803961TEST_LIST = {
804962 {"long_index" , flb_test_long_index },
@@ -814,5 +972,8 @@ TEST_LIST = {
814972 {"replace_dots" , flb_test_replace_dots },
815973 {"id_key" , flb_test_id_key },
816974 {"logstash_prefix_separator" , flb_test_logstash_prefix_separator },
975+ {"response_success" , flb_test_response_success },
976+ {"response_successes" , flb_test_response_successes },
977+ {"response_partially_success" , flb_test_response_partially_success },
817978 {NULL , NULL }
818979};
0 commit comments