@@ -1040,6 +1040,128 @@ void flb_test_json_date_format_java_sql_timestamp()
10401040 test_ctx_destroy (ctx );
10411041}
10421042
1043+ static struct test_ctx * test_ctx_create_in_http (struct flb_lib_out_cb * cb )
1044+ {
1045+ int i_ffd ;
1046+ int o_ffd ;
1047+ struct test_ctx * ctx = NULL ;
1048+
1049+ ctx = flb_malloc (sizeof (struct test_ctx ));
1050+ if (!TEST_CHECK (ctx != NULL )) {
1051+ TEST_MSG ("malloc failed" );
1052+ flb_errno ();
1053+ return NULL ;
1054+ }
1055+
1056+ /* Service config */
1057+ ctx -> flb = flb_create ();
1058+ flb_service_set (ctx -> flb ,
1059+ "Flush" , "0.200000000" ,
1060+ "Grace" , "1" ,
1061+ "Log_Level" , "error" ,
1062+ NULL );
1063+
1064+ /* Input */
1065+ i_ffd = flb_input (ctx -> flb , (char * ) "http" , NULL );
1066+ TEST_CHECK (i_ffd >= 0 );
1067+ ctx -> i_ffd = i_ffd ;
1068+
1069+ /* Output */
1070+ o_ffd = flb_output (ctx -> flb , (char * ) "lib" , cb );
1071+ ctx -> o_ffd = o_ffd ;
1072+
1073+ return ctx ;
1074+ }
1075+
1076+ int callback_test (void * data , size_t size , void * cb_data )
1077+ {
1078+ int num ;
1079+
1080+ if (size > 0 ) {
1081+ num = get_output_num ();
1082+ set_output_num (num + 1 );
1083+ }
1084+ return 0 ;
1085+ }
1086+
1087+ /* test to make sure out_http is always able to work with in_http by default. */
1088+ void flb_test_in_http ()
1089+ {
1090+ struct test_ctx * ctx_in_http ;
1091+ struct test_ctx * ctx_out_http ;
1092+ int ret ;
1093+ int num ;
1094+ struct flb_lib_out_cb cb ;
1095+
1096+ cb .cb = callback_test ;
1097+ cb .data = NULL ;
1098+ clear_output_num ();
1099+
1100+ char * buf1 = "[1, {\"msg\":\"hello world\"}]" ;
1101+ size_t size1 = strlen (buf1 );
1102+ char * buf2 = "[2, {\"msg\":\"hello world\"}]" ;
1103+ size_t size2 = strlen (buf2 );
1104+
1105+ ctx_in_http = test_ctx_create_in_http (& cb );
1106+ if (!TEST_CHECK (ctx_in_http != NULL )) {
1107+ TEST_MSG ("test_ctx_create failed" );
1108+ exit (EXIT_FAILURE );
1109+ }
1110+
1111+ ctx_out_http = test_ctx_create ();
1112+ if (!TEST_CHECK (ctx_out_http != NULL )) {
1113+ TEST_MSG ("test_ctx_create failed" );
1114+ exit (EXIT_FAILURE );
1115+ }
1116+
1117+ ret = flb_input_set (ctx_in_http -> flb ,
1118+ ctx_in_http -> i_ffd ,
1119+ "port" , "8888" ,
1120+ "host" , "127.0.0.1" ,
1121+ NULL );
1122+ TEST_CHECK (ret == 0 );
1123+
1124+ /* explicitly do not set anything beyond match, port and localhost
1125+ * to be sure the default options work with in_http.
1126+ */
1127+ ret = flb_output_set (ctx_out_http -> flb ,
1128+ ctx_out_http -> o_ffd ,
1129+ "match" , "*" ,
1130+ "host" , "127.0.0.1" ,
1131+ "port" , "8888" ,
1132+ NULL );
1133+ TEST_CHECK (ret == 0 );
1134+
1135+ /* Start the engines */
1136+ ret = flb_start (ctx_in_http -> flb );
1137+ TEST_CHECK (ret == 0 );
1138+ ret = flb_start (ctx_out_http -> flb );
1139+ TEST_CHECK (ret == 0 );
1140+
1141+ /* Ingest data sample */
1142+ ret = flb_lib_push (ctx_out_http -> flb ,
1143+ ctx_out_http -> i_ffd ,
1144+ (char * ) buf1 ,
1145+ size1 );
1146+ TEST_CHECK (ret >= 0 );
1147+ ret = flb_lib_push (ctx_out_http -> flb ,
1148+ ctx_out_http -> i_ffd ,
1149+ (char * ) buf2 ,
1150+ size2 );
1151+ TEST_CHECK (ret >= 0 );
1152+
1153+ /* waiting to flush */
1154+ flb_time_msleep (500 );
1155+
1156+ num = get_output_num ();
1157+ if (!TEST_CHECK (num > 0 )) {
1158+ TEST_MSG ("no outputs" );
1159+ }
1160+
1161+ test_ctx_destroy (ctx_out_http );
1162+ test_ctx_destroy (ctx_in_http );
1163+ }
1164+
10431165/* Test list */
10441166TEST_LIST = {
10451167 {"format_msgpack" , flb_test_format_msgpack },
@@ -1056,5 +1178,6 @@ TEST_LIST = {
10561178 {"json_date_format_epoch" , flb_test_json_date_format_epoch },
10571179 {"json_date_format_iso8601" , flb_test_json_date_format_iso8601 },
10581180 {"json_date_format_java_sql_timestamp" , flb_test_json_date_format_java_sql_timestamp },
1181+ {"in_http" , flb_test_in_http },
10591182 {NULL , NULL }
10601183};
0 commit comments