checkpoint_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // Copyright 2021-2022 EMQ Technologies Co., Ltd.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package topotest
  15. import (
  16. "github.com/lf-edge/ekuiper/internal/conf"
  17. "github.com/lf-edge/ekuiper/pkg/api"
  18. "testing"
  19. )
  20. // Full lifecycle test: Run window rule; trigger checkpoints by mock timer; restart rule; make sure the result is right;
  21. func TestCheckpoint(t *testing.T) {
  22. conf.IsTesting = true
  23. streamList := []string{"demo"}
  24. HandleStream(false, streamList, t)
  25. var tests = []RuleCheckpointTest{{
  26. RuleTest: RuleTest{
  27. Name: `TestCheckpointRule1`,
  28. Sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  29. R: [][]map[string]interface{}{
  30. {{
  31. "color": "red",
  32. "size": float64(3),
  33. "ts": float64(1541152486013),
  34. }, {
  35. "color": "blue",
  36. "size": float64(6),
  37. "ts": float64(1541152486822),
  38. }},
  39. {{
  40. "color": "red",
  41. "size": float64(3),
  42. "ts": float64(1541152486013),
  43. }, {
  44. "color": "blue",
  45. "size": float64(6),
  46. "ts": float64(1541152486822),
  47. }},
  48. {{
  49. "color": "blue",
  50. "size": float64(2),
  51. "ts": float64(1541152487632),
  52. }},
  53. {{
  54. "color": "blue",
  55. "size": float64(2),
  56. "ts": float64(1541152487632),
  57. }, {
  58. "color": "yellow",
  59. "size": float64(4),
  60. "ts": float64(1541152488442),
  61. }},
  62. {{
  63. "color": "yellow",
  64. "size": float64(4),
  65. "ts": float64(1541152488442),
  66. }, {
  67. "color": "red",
  68. "size": float64(1),
  69. "ts": float64(1541152489252),
  70. }},
  71. },
  72. M: map[string]interface{}{
  73. "op_3_project_0_records_in_total": int64(4),
  74. "op_3_project_0_records_out_total": int64(4),
  75. "sink_mockSink_0_records_in_total": int64(4),
  76. "sink_mockSink_0_records_out_total": int64(4),
  77. "source_demo_0_records_in_total": int64(3),
  78. "source_demo_0_records_out_total": int64(3),
  79. "op_2_window_0_records_in_total": int64(3),
  80. "op_2_window_0_records_out_total": int64(4),
  81. },
  82. },
  83. PauseSize: 3,
  84. Cc: 2,
  85. PauseMetric: map[string]interface{}{
  86. "op_3_project_0_records_in_total": int64(1),
  87. "op_3_project_0_records_out_total": int64(1),
  88. "sink_mockSink_0_records_in_total": int64(1),
  89. "sink_mockSink_0_records_out_total": int64(1),
  90. "source_demo_0_records_in_total": int64(3),
  91. "source_demo_0_records_out_total": int64(3),
  92. "op_2_window_0_records_in_total": int64(3),
  93. "op_2_window_0_records_out_total": int64(1),
  94. }},
  95. }
  96. HandleStream(true, streamList, t)
  97. options := []*api.RuleOption{
  98. {
  99. BufferLength: 100,
  100. Qos: api.AtLeastOnce,
  101. CheckpointInterval: 600,
  102. SendError: true,
  103. }, {
  104. BufferLength: 100,
  105. Qos: api.ExactlyOnce,
  106. CheckpointInterval: 600,
  107. SendError: true,
  108. },
  109. }
  110. for j, opt := range options {
  111. DoCheckpointRuleTest(t, tests, j, opt)
  112. }
  113. }