rule_test.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. package processors
  2. import (
  3. "encoding/json"
  4. "github.com/emqx/kuiper/xstream"
  5. "github.com/emqx/kuiper/xstream/api"
  6. "testing"
  7. )
  8. func TestSingleSQL(t *testing.T) {
  9. //Reset
  10. streamList := []string{"demo", "demoError", "demo1"}
  11. handleStream(false, streamList, t)
  12. //Data setup
  13. var tests = []ruleTest{
  14. {
  15. name: `TestSingleSQLRule1`,
  16. sql: `SELECT * FROM demo`,
  17. r: [][]map[string]interface{}{
  18. {{
  19. "color": "red",
  20. "size": float64(3),
  21. "ts": float64(1541152486013),
  22. }},
  23. {{
  24. "color": "blue",
  25. "size": float64(6),
  26. "ts": float64(1541152486822),
  27. }},
  28. {{
  29. "color": "blue",
  30. "size": float64(2),
  31. "ts": float64(1541152487632),
  32. }},
  33. {{
  34. "color": "yellow",
  35. "size": float64(4),
  36. "ts": float64(1541152488442),
  37. }},
  38. {{
  39. "color": "red",
  40. "size": float64(1),
  41. "ts": float64(1541152489252),
  42. }},
  43. },
  44. m: map[string]interface{}{
  45. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  46. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  47. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  48. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  49. "op_2_project_0_exceptions_total": int64(0),
  50. "op_2_project_0_process_latency_us": int64(0),
  51. "op_2_project_0_records_in_total": int64(5),
  52. "op_2_project_0_records_out_total": int64(5),
  53. "sink_mockSink_0_exceptions_total": int64(0),
  54. "sink_mockSink_0_records_in_total": int64(5),
  55. "sink_mockSink_0_records_out_total": int64(5),
  56. "source_demo_0_exceptions_total": int64(0),
  57. "source_demo_0_records_in_total": int64(5),
  58. "source_demo_0_records_out_total": int64(5),
  59. },
  60. t: &xstream.PrintableTopo{
  61. Sources: []string{"source_demo"},
  62. Edges: map[string][]string{
  63. "source_demo": {"op_1_preprocessor_demo"},
  64. "op_1_preprocessor_demo": {"op_2_project"},
  65. "op_2_project": {"sink_mockSink"},
  66. },
  67. },
  68. }, {
  69. name: `TestSingleSQLRule2`,
  70. sql: `SELECT color, ts FROM demo where size > 3`,
  71. r: [][]map[string]interface{}{
  72. {{
  73. "color": "blue",
  74. "ts": float64(1541152486822),
  75. }},
  76. {{
  77. "color": "yellow",
  78. "ts": float64(1541152488442),
  79. }},
  80. },
  81. m: map[string]interface{}{
  82. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  83. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  84. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  85. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  86. "op_3_project_0_exceptions_total": int64(0),
  87. "op_3_project_0_process_latency_us": int64(0),
  88. "op_3_project_0_records_in_total": int64(2),
  89. "op_3_project_0_records_out_total": int64(2),
  90. "sink_mockSink_0_exceptions_total": int64(0),
  91. "sink_mockSink_0_records_in_total": int64(2),
  92. "sink_mockSink_0_records_out_total": int64(2),
  93. "source_demo_0_exceptions_total": int64(0),
  94. "source_demo_0_records_in_total": int64(5),
  95. "source_demo_0_records_out_total": int64(5),
  96. "op_2_filter_0_exceptions_total": int64(0),
  97. "op_2_filter_0_process_latency_us": int64(0),
  98. "op_2_filter_0_records_in_total": int64(5),
  99. "op_2_filter_0_records_out_total": int64(2),
  100. },
  101. }, {
  102. name: `TestSingleSQLRule3`,
  103. sql: `SELECT size as Int8, ts FROM demo where size > 3`,
  104. r: [][]map[string]interface{}{
  105. {{
  106. "Int8": float64(6),
  107. "ts": float64(1541152486822),
  108. }},
  109. {{
  110. "Int8": float64(4),
  111. "ts": float64(1541152488442),
  112. }},
  113. },
  114. m: map[string]interface{}{
  115. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  116. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  117. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  118. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  119. "op_3_project_0_exceptions_total": int64(0),
  120. "op_3_project_0_process_latency_us": int64(0),
  121. "op_3_project_0_records_in_total": int64(2),
  122. "op_3_project_0_records_out_total": int64(2),
  123. "sink_mockSink_0_exceptions_total": int64(0),
  124. "sink_mockSink_0_records_in_total": int64(2),
  125. "sink_mockSink_0_records_out_total": int64(2),
  126. "source_demo_0_exceptions_total": int64(0),
  127. "source_demo_0_records_in_total": int64(5),
  128. "source_demo_0_records_out_total": int64(5),
  129. "op_2_filter_0_exceptions_total": int64(0),
  130. "op_2_filter_0_process_latency_us": int64(0),
  131. "op_2_filter_0_records_in_total": int64(5),
  132. "op_2_filter_0_records_out_total": int64(2),
  133. },
  134. }, {
  135. name: `TestSingleSQLRule4`,
  136. sql: `SELECT size as Int8, ts FROM demoError where size > 3`,
  137. r: [][]map[string]interface{}{
  138. {{
  139. "error": "error in preprocessor: invalid data type for size, expect bigint but found string(red)",
  140. }},
  141. {{
  142. "Int8": float64(6),
  143. "ts": float64(1541152486822),
  144. }},
  145. {{
  146. "Int8": float64(4),
  147. "ts": float64(1541152488442),
  148. }},
  149. {{
  150. "error": "error in preprocessor: invalid data type for size, expect bigint but found string(blue)",
  151. }},
  152. },
  153. m: map[string]interface{}{
  154. "op_1_preprocessor_demoError_0_exceptions_total": int64(2),
  155. "op_1_preprocessor_demoError_0_process_latency_us": int64(0),
  156. "op_1_preprocessor_demoError_0_records_in_total": int64(5),
  157. "op_1_preprocessor_demoError_0_records_out_total": int64(3),
  158. "op_3_project_0_exceptions_total": int64(2),
  159. "op_3_project_0_process_latency_us": int64(0),
  160. "op_3_project_0_records_in_total": int64(4),
  161. "op_3_project_0_records_out_total": int64(2),
  162. "sink_mockSink_0_exceptions_total": int64(0),
  163. "sink_mockSink_0_records_in_total": int64(4),
  164. "sink_mockSink_0_records_out_total": int64(4),
  165. "source_demoError_0_exceptions_total": int64(0),
  166. "source_demoError_0_records_in_total": int64(5),
  167. "source_demoError_0_records_out_total": int64(5),
  168. "op_2_filter_0_exceptions_total": int64(2),
  169. "op_2_filter_0_process_latency_us": int64(0),
  170. "op_2_filter_0_records_in_total": int64(5),
  171. "op_2_filter_0_records_out_total": int64(2),
  172. },
  173. }, {
  174. name: `TestSingleSQLRule5`,
  175. sql: `SELECT meta(topic) as m, ts FROM demo`,
  176. r: [][]map[string]interface{}{
  177. {{
  178. "m": "mock",
  179. "ts": float64(1541152486013),
  180. }},
  181. {{
  182. "m": "mock",
  183. "ts": float64(1541152486822),
  184. }},
  185. {{
  186. "m": "mock",
  187. "ts": float64(1541152487632),
  188. }},
  189. {{
  190. "m": "mock",
  191. "ts": float64(1541152488442),
  192. }},
  193. {{
  194. "m": "mock",
  195. "ts": float64(1541152489252),
  196. }},
  197. },
  198. m: map[string]interface{}{
  199. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  200. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  201. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  202. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  203. "op_2_project_0_exceptions_total": int64(0),
  204. "op_2_project_0_process_latency_us": int64(0),
  205. "op_2_project_0_records_in_total": int64(5),
  206. "op_2_project_0_records_out_total": int64(5),
  207. "sink_mockSink_0_exceptions_total": int64(0),
  208. "sink_mockSink_0_records_in_total": int64(5),
  209. "sink_mockSink_0_records_out_total": int64(5),
  210. "source_demo_0_exceptions_total": int64(0),
  211. "source_demo_0_records_in_total": int64(5),
  212. "source_demo_0_records_out_total": int64(5),
  213. },
  214. }, {
  215. name: `TestSingleSQLRule6`,
  216. sql: `SELECT color, ts FROM demo where size > 3 and meta(topic)="mock"`,
  217. r: [][]map[string]interface{}{
  218. {{
  219. "color": "blue",
  220. "ts": float64(1541152486822),
  221. }},
  222. {{
  223. "color": "yellow",
  224. "ts": float64(1541152488442),
  225. }},
  226. },
  227. m: map[string]interface{}{
  228. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  229. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  230. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  231. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  232. "op_3_project_0_exceptions_total": int64(0),
  233. "op_3_project_0_process_latency_us": int64(0),
  234. "op_3_project_0_records_in_total": int64(2),
  235. "op_3_project_0_records_out_total": int64(2),
  236. "sink_mockSink_0_exceptions_total": int64(0),
  237. "sink_mockSink_0_records_in_total": int64(2),
  238. "sink_mockSink_0_records_out_total": int64(2),
  239. "source_demo_0_exceptions_total": int64(0),
  240. "source_demo_0_records_in_total": int64(5),
  241. "source_demo_0_records_out_total": int64(5),
  242. "op_2_filter_0_exceptions_total": int64(0),
  243. "op_2_filter_0_process_latency_us": int64(0),
  244. "op_2_filter_0_records_in_total": int64(5),
  245. "op_2_filter_0_records_out_total": int64(2),
  246. },
  247. }, {
  248. name: `TestSingleSQLRule7`,
  249. sql: "SELECT `from` FROM demo1",
  250. r: [][]map[string]interface{}{
  251. {{
  252. "from": "device1",
  253. }},
  254. {{
  255. "from": "device2",
  256. }},
  257. {{
  258. "from": "device3",
  259. }},
  260. {{
  261. "from": "device1",
  262. }},
  263. {{
  264. "from": "device3",
  265. }},
  266. },
  267. m: map[string]interface{}{
  268. "op_1_preprocessor_demo1_0_exceptions_total": int64(0),
  269. "op_1_preprocessor_demo1_0_process_latency_us": int64(0),
  270. "op_1_preprocessor_demo1_0_records_in_total": int64(5),
  271. "op_1_preprocessor_demo1_0_records_out_total": int64(5),
  272. "op_2_project_0_exceptions_total": int64(0),
  273. "op_2_project_0_process_latency_us": int64(0),
  274. "op_2_project_0_records_in_total": int64(5),
  275. "op_2_project_0_records_out_total": int64(5),
  276. "sink_mockSink_0_exceptions_total": int64(0),
  277. "sink_mockSink_0_records_in_total": int64(5),
  278. "sink_mockSink_0_records_out_total": int64(5),
  279. "source_demo1_0_exceptions_total": int64(0),
  280. "source_demo1_0_records_in_total": int64(5),
  281. "source_demo1_0_records_out_total": int64(5),
  282. },
  283. }, {
  284. name: `TestSingleSQLRule8`,
  285. sql: "SELECT * FROM demo1 where `from`=\"device1\"",
  286. r: [][]map[string]interface{}{
  287. {{
  288. "temp": float64(25.5),
  289. "hum": float64(65),
  290. "from": "device1",
  291. "ts": float64(1541152486013),
  292. }},
  293. {{
  294. "temp": float64(27.4),
  295. "hum": float64(80),
  296. "from": "device1",
  297. "ts": float64(1541152488442),
  298. }},
  299. },
  300. m: map[string]interface{}{
  301. "op_1_preprocessor_demo1_0_exceptions_total": int64(0),
  302. "op_1_preprocessor_demo1_0_process_latency_us": int64(0),
  303. "op_1_preprocessor_demo1_0_records_in_total": int64(5),
  304. "op_1_preprocessor_demo1_0_records_out_total": int64(5),
  305. "op_3_project_0_exceptions_total": int64(0),
  306. "op_3_project_0_process_latency_us": int64(0),
  307. "op_3_project_0_records_in_total": int64(2),
  308. "op_3_project_0_records_out_total": int64(2),
  309. "op_2_filter_0_exceptions_total": int64(0),
  310. "op_2_filter_0_process_latency_us": int64(0),
  311. "op_2_filter_0_records_in_total": int64(5),
  312. "op_2_filter_0_records_out_total": int64(2),
  313. "sink_mockSink_0_exceptions_total": int64(0),
  314. "sink_mockSink_0_records_in_total": int64(2),
  315. "sink_mockSink_0_records_out_total": int64(2),
  316. "source_demo1_0_exceptions_total": int64(0),
  317. "source_demo1_0_records_in_total": int64(5),
  318. "source_demo1_0_records_out_total": int64(5),
  319. },
  320. },
  321. }
  322. handleStream(true, streamList, t)
  323. options := []*api.RuleOption{
  324. {
  325. BufferLength: 100,
  326. }, {
  327. BufferLength: 100,
  328. Qos: api.AtLeastOnce,
  329. CheckpointInterval: 5000,
  330. }, {
  331. BufferLength: 100,
  332. Qos: api.ExactlyOnce,
  333. CheckpointInterval: 5000,
  334. },
  335. }
  336. for j, opt := range options {
  337. doRuleTest(t, tests, j, opt)
  338. }
  339. }
  340. func TestSingleSQLError(t *testing.T) {
  341. //Reset
  342. streamList := []string{"ldemo"}
  343. handleStream(false, streamList, t)
  344. //Data setup
  345. var tests = []ruleTest{
  346. {
  347. name: `TestSingleSQLErrorRule1`,
  348. sql: `SELECT color, ts FROM ldemo where size >= 3`,
  349. r: [][]map[string]interface{}{
  350. {{
  351. "color": "red",
  352. "ts": float64(1541152486013),
  353. }},
  354. {{
  355. "error": "run Where error: invalid operation string(string) >= int64(3)",
  356. }},
  357. {{
  358. "ts": float64(1541152487632),
  359. }},
  360. },
  361. m: map[string]interface{}{
  362. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  363. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  364. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  365. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  366. "op_3_project_0_exceptions_total": int64(1),
  367. "op_3_project_0_process_latency_us": int64(0),
  368. "op_3_project_0_records_in_total": int64(3),
  369. "op_3_project_0_records_out_total": int64(2),
  370. "sink_mockSink_0_exceptions_total": int64(0),
  371. "sink_mockSink_0_records_in_total": int64(3),
  372. "sink_mockSink_0_records_out_total": int64(3),
  373. "source_ldemo_0_exceptions_total": int64(0),
  374. "source_ldemo_0_records_in_total": int64(5),
  375. "source_ldemo_0_records_out_total": int64(5),
  376. "op_2_filter_0_exceptions_total": int64(1),
  377. "op_2_filter_0_process_latency_us": int64(0),
  378. "op_2_filter_0_records_in_total": int64(5),
  379. "op_2_filter_0_records_out_total": int64(2),
  380. },
  381. }, {
  382. name: `TestSingleSQLErrorRule2`,
  383. sql: `SELECT size * 5 FROM ldemo`,
  384. r: [][]map[string]interface{}{
  385. {{
  386. "rengine_field_0": float64(15),
  387. }},
  388. {{
  389. "error": "run Select error: invalid operation string(string) * int64(5)",
  390. }},
  391. {{
  392. "rengine_field_0": float64(15),
  393. }},
  394. {{
  395. "rengine_field_0": float64(10),
  396. }},
  397. {{}},
  398. },
  399. m: map[string]interface{}{
  400. "op_1_preprocessor_ldemo_0_exceptions_total": int64(0),
  401. "op_1_preprocessor_ldemo_0_process_latency_us": int64(0),
  402. "op_1_preprocessor_ldemo_0_records_in_total": int64(5),
  403. "op_1_preprocessor_ldemo_0_records_out_total": int64(5),
  404. "op_2_project_0_exceptions_total": int64(1),
  405. "op_2_project_0_process_latency_us": int64(0),
  406. "op_2_project_0_records_in_total": int64(5),
  407. "op_2_project_0_records_out_total": int64(4),
  408. "sink_mockSink_0_exceptions_total": int64(0),
  409. "sink_mockSink_0_records_in_total": int64(5),
  410. "sink_mockSink_0_records_out_total": int64(5),
  411. "source_ldemo_0_exceptions_total": int64(0),
  412. "source_ldemo_0_records_in_total": int64(5),
  413. "source_ldemo_0_records_out_total": int64(5),
  414. },
  415. },
  416. }
  417. handleStream(true, streamList, t)
  418. doRuleTest(t, tests, 0, &api.RuleOption{
  419. BufferLength: 100,
  420. })
  421. }
  422. func TestSingleSQLTemplate(t *testing.T) {
  423. //Reset
  424. streamList := []string{"demo"}
  425. handleStream(false, streamList, t)
  426. //Data setup
  427. var tests = []ruleTest{
  428. {
  429. name: `TestSingleSQLTemplateRule1`,
  430. sql: `SELECT * FROM demo`,
  431. r: []map[string]interface{}{
  432. {
  433. "c": "red",
  434. "wrapper": "w1",
  435. },
  436. {
  437. "c": "blue",
  438. "wrapper": "w1",
  439. },
  440. {
  441. "c": "blue",
  442. "wrapper": "w1",
  443. },
  444. {
  445. "c": "yellow",
  446. "wrapper": "w1",
  447. },
  448. {
  449. "c": "red",
  450. "wrapper": "w1",
  451. },
  452. },
  453. m: map[string]interface{}{
  454. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  455. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  456. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  457. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  458. "op_2_project_0_exceptions_total": int64(0),
  459. "op_2_project_0_process_latency_us": int64(0),
  460. "op_2_project_0_records_in_total": int64(5),
  461. "op_2_project_0_records_out_total": int64(5),
  462. "sink_mockSink_0_exceptions_total": int64(0),
  463. "sink_mockSink_0_records_in_total": int64(5),
  464. "sink_mockSink_0_records_out_total": int64(5),
  465. "source_demo_0_exceptions_total": int64(0),
  466. "source_demo_0_records_in_total": int64(5),
  467. "source_demo_0_records_out_total": int64(5),
  468. },
  469. },
  470. }
  471. handleStream(true, streamList, t)
  472. doRuleTestBySinkProps(t, tests, 0, &api.RuleOption{
  473. BufferLength: 100,
  474. }, map[string]interface{}{
  475. "dataTemplate": `{"wrapper":"w1", "c":"{{.color}}"}`,
  476. "sendSingle": true,
  477. }, func(result [][]byte) interface{} {
  478. var maps []map[string]interface{}
  479. for _, v := range result {
  480. var mapRes map[string]interface{}
  481. err := json.Unmarshal(v, &mapRes)
  482. if err != nil {
  483. t.Errorf("Failed to parse the input into map")
  484. continue
  485. }
  486. maps = append(maps, mapRes)
  487. }
  488. return maps
  489. })
  490. }
  491. func TestNoneSingleSQLTemplate(t *testing.T) {
  492. //Reset
  493. streamList := []string{"demo"}
  494. handleStream(false, streamList, t)
  495. //Data setup
  496. var tests = []ruleTest{
  497. {
  498. name: `TestNoneSingleSQLTemplateRule1`,
  499. sql: `SELECT * FROM demo`,
  500. r: [][]byte{
  501. []byte("<div>results</div><ul><li>red - 3</li></ul>"),
  502. []byte("<div>results</div><ul><li>blue - 6</li></ul>"),
  503. []byte("<div>results</div><ul><li>blue - 2</li></ul>"),
  504. []byte("<div>results</div><ul><li>yellow - 4</li></ul>"),
  505. []byte("<div>results</div><ul><li>red - 1</li></ul>"),
  506. },
  507. m: map[string]interface{}{
  508. "op_1_preprocessor_demo_0_exceptions_total": int64(0),
  509. "op_1_preprocessor_demo_0_process_latency_us": int64(0),
  510. "op_1_preprocessor_demo_0_records_in_total": int64(5),
  511. "op_1_preprocessor_demo_0_records_out_total": int64(5),
  512. "op_2_project_0_exceptions_total": int64(0),
  513. "op_2_project_0_process_latency_us": int64(0),
  514. "op_2_project_0_records_in_total": int64(5),
  515. "op_2_project_0_records_out_total": int64(5),
  516. "sink_mockSink_0_exceptions_total": int64(0),
  517. "sink_mockSink_0_records_in_total": int64(5),
  518. "sink_mockSink_0_records_out_total": int64(5),
  519. "source_demo_0_exceptions_total": int64(0),
  520. "source_demo_0_records_in_total": int64(5),
  521. "source_demo_0_records_out_total": int64(5),
  522. },
  523. },
  524. }
  525. handleStream(true, streamList, t)
  526. doRuleTestBySinkProps(t, tests, 0, &api.RuleOption{
  527. BufferLength: 100,
  528. }, map[string]interface{}{
  529. "dataTemplate": `<div>results</div><ul>{{range .}}<li>{{.color}} - {{.size}}</li>{{end}}</ul>`,
  530. }, func(result [][]byte) interface{} {
  531. return result
  532. })
  533. }
  534. func TestSingleSQLForBinary(t *testing.T) {
  535. //Reset
  536. streamList := []string{"binDemo"}
  537. handleStream(false, streamList, t)
  538. //Data setup
  539. var tests = []ruleTest{
  540. {
  541. name: `TestSingleSQLRule1`,
  542. sql: `SELECT * FROM binDemo`,
  543. r: [][]map[string]interface{}{
  544. {{
  545. "self": image,
  546. }},
  547. },
  548. m: map[string]interface{}{
  549. "op_1_preprocessor_binDemo_0_exceptions_total": int64(0),
  550. "op_1_preprocessor_binDemo_0_process_latency_us": int64(0),
  551. "op_1_preprocessor_binDemo_0_records_in_total": int64(1),
  552. "op_1_preprocessor_binDemo_0_records_out_total": int64(1),
  553. "op_2_project_0_exceptions_total": int64(0),
  554. "op_2_project_0_process_latency_us": int64(0),
  555. "op_2_project_0_records_in_total": int64(1),
  556. "op_2_project_0_records_out_total": int64(1),
  557. "sink_mockSink_0_exceptions_total": int64(0),
  558. "sink_mockSink_0_records_in_total": int64(1),
  559. "sink_mockSink_0_records_out_total": int64(1),
  560. "source_binDemo_0_exceptions_total": int64(0),
  561. "source_binDemo_0_records_in_total": int64(1),
  562. "source_binDemo_0_records_out_total": int64(1),
  563. },
  564. },
  565. }
  566. handleStream(true, streamList, t)
  567. options := []*api.RuleOption{
  568. {
  569. BufferLength: 100,
  570. }, {
  571. BufferLength: 100,
  572. Qos: api.AtLeastOnce,
  573. CheckpointInterval: 5000,
  574. }, {
  575. BufferLength: 100,
  576. Qos: api.ExactlyOnce,
  577. CheckpointInterval: 5000,
  578. },
  579. }
  580. byteFunc := func(result [][]byte) interface{} {
  581. var maps [][]map[string]interface{}
  582. for _, v := range result {
  583. var mapRes []map[string][]byte
  584. err := json.Unmarshal(v, &mapRes)
  585. if err != nil {
  586. panic("Failed to parse the input into map")
  587. }
  588. mapInt := make([]map[string]interface{}, len(mapRes))
  589. for i, mv := range mapRes {
  590. mapInt[i] = make(map[string]interface{})
  591. //assume only one key
  592. for k, v := range mv {
  593. mapInt[i][k] = v
  594. }
  595. }
  596. maps = append(maps, mapInt)
  597. }
  598. return maps
  599. }
  600. for j, opt := range options {
  601. doRuleTestBySinkProps(t, tests, j, opt, nil, byteFunc)
  602. }
  603. }