checkpoint_test.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. "testing"
  17. "github.com/lf-edge/ekuiper/internal/conf"
  18. "github.com/lf-edge/ekuiper/pkg/api"
  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. tests := []RuleCheckpointTest{
  26. {
  27. RuleTest: RuleTest{
  28. Name: `TestCheckpointRule1`,
  29. Sql: `SELECT * FROM demo GROUP BY HOPPINGWINDOW(ss, 2, 1)`,
  30. R: [][]map[string]interface{}{
  31. {{
  32. "color": "red",
  33. "size": float64(3),
  34. "ts": float64(1541152486013),
  35. }, {
  36. "color": "blue",
  37. "size": float64(6),
  38. "ts": float64(1541152486822),
  39. }},
  40. {{
  41. "color": "red",
  42. "size": float64(3),
  43. "ts": float64(1541152486013),
  44. }, {
  45. "color": "blue",
  46. "size": float64(6),
  47. "ts": float64(1541152486822),
  48. }},
  49. {{
  50. "color": "blue",
  51. "size": float64(2),
  52. "ts": float64(1541152487632),
  53. }},
  54. {{
  55. "color": "blue",
  56. "size": float64(2),
  57. "ts": float64(1541152487632),
  58. }, {
  59. "color": "yellow",
  60. "size": float64(4),
  61. "ts": float64(1541152488442),
  62. }},
  63. {{
  64. "color": "yellow",
  65. "size": float64(4),
  66. "ts": float64(1541152488442),
  67. }, {
  68. "color": "red",
  69. "size": float64(1),
  70. "ts": float64(1541152489252),
  71. }},
  72. },
  73. M: map[string]interface{}{
  74. "op_3_project_0_records_in_total": int64(4),
  75. "op_3_project_0_records_out_total": int64(4),
  76. "sink_mockSink_0_records_in_total": int64(4),
  77. "sink_mockSink_0_records_out_total": int64(4),
  78. "source_demo_0_records_in_total": int64(3),
  79. "source_demo_0_records_out_total": int64(3),
  80. "op_2_window_0_records_in_total": int64(3),
  81. "op_2_window_0_records_out_total": int64(4),
  82. },
  83. },
  84. PauseSize: 3,
  85. Cc: 2,
  86. PauseMetric: map[string]interface{}{
  87. "op_3_project_0_records_in_total": int64(1),
  88. "op_3_project_0_records_out_total": int64(1),
  89. "sink_mockSink_0_records_in_total": int64(1),
  90. "sink_mockSink_0_records_out_total": int64(1),
  91. "source_demo_0_records_in_total": int64(3),
  92. "source_demo_0_records_out_total": int64(3),
  93. "op_2_window_0_records_in_total": int64(3),
  94. "op_2_window_0_records_out_total": int64(1),
  95. },
  96. },
  97. }
  98. HandleStream(true, streamList, t)
  99. options := []*api.RuleOption{
  100. {
  101. BufferLength: 100,
  102. Qos: api.AtLeastOnce,
  103. CheckpointInterval: 600,
  104. SendError: true,
  105. }, {
  106. BufferLength: 100,
  107. Qos: api.ExactlyOnce,
  108. CheckpointInterval: 600,
  109. SendError: true,
  110. },
  111. }
  112. for j, opt := range options {
  113. DoCheckpointRuleTest(t, tests, j, opt)
  114. }
  115. }