checkpoint_test.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. // Copyright 2021 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. "color": "yellow",
  54. "size": float64(4),
  55. "ts": float64(1541152488442),
  56. }},
  57. {{
  58. "color": "blue",
  59. "size": float64(2),
  60. "ts": float64(1541152487632),
  61. }, {
  62. "color": "yellow",
  63. "size": float64(4),
  64. "ts": float64(1541152488442),
  65. }, {
  66. "color": "red",
  67. "size": float64(1),
  68. "ts": float64(1541152489252),
  69. }},
  70. },
  71. M: map[string]interface{}{
  72. "op_3_project_0_records_in_total": int64(3),
  73. "op_3_project_0_records_out_total": int64(3),
  74. "sink_mockSink_0_records_in_total": int64(3),
  75. "sink_mockSink_0_records_out_total": int64(3),
  76. "source_demo_0_records_in_total": int64(3),
  77. "source_demo_0_records_out_total": int64(3),
  78. "op_2_window_0_records_in_total": int64(3),
  79. "op_2_window_0_records_out_total": int64(3),
  80. },
  81. },
  82. PauseSize: 3,
  83. Cc: 2,
  84. PauseMetric: map[string]interface{}{
  85. "op_3_project_0_records_in_total": int64(1),
  86. "op_3_project_0_records_out_total": int64(1),
  87. "sink_mockSink_0_records_in_total": int64(1),
  88. "sink_mockSink_0_records_out_total": int64(1),
  89. "source_demo_0_records_in_total": int64(3),
  90. "source_demo_0_records_out_total": int64(3),
  91. "op_2_window_0_records_in_total": int64(3),
  92. "op_2_window_0_records_out_total": int64(1),
  93. }},
  94. }
  95. HandleStream(true, streamList, t)
  96. options := []*api.RuleOption{
  97. {
  98. BufferLength: 100,
  99. Qos: api.AtLeastOnce,
  100. CheckpointInterval: 600,
  101. SendError: true,
  102. }, {
  103. BufferLength: 100,
  104. Qos: api.ExactlyOnce,
  105. CheckpointInterval: 600,
  106. SendError: true,
  107. },
  108. }
  109. for j, opt := range options {
  110. DoCheckpointRuleTest(t, tests, j, opt)
  111. }
  112. }