emqx_retainer_cli_SUITE.erl 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. %%--------------------------------------------------------------------
  2. %% Copyright (c) 2020-2024 EMQ Technologies Co., Ltd. All Rights Reserved.
  3. %%
  4. %% Licensed under the Apache License, Version 2.0 (the "License");
  5. %% you may not use this file except in compliance with the License.
  6. %% You may obtain a copy of the License at
  7. %%
  8. %% http://www.apache.org/licenses/LICENSE-2.0
  9. %%
  10. %% Unless required by applicable law or agreed to in writing, software
  11. %% distributed under the License is distributed on an "AS IS" BASIS,
  12. %% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. %% See the License for the specific language governing permissions and
  14. %% limitations under the License.
  15. %%--------------------------------------------------------------------
  16. -module(emqx_retainer_cli_SUITE).
  17. -compile(export_all).
  18. -compile(nowarn_export_all).
  19. -include("emqx_retainer.hrl").
  20. -include_lib("eunit/include/eunit.hrl").
  21. -include_lib("common_test/include/ct.hrl").
  22. -include_lib("snabbkaffe/include/snabbkaffe.hrl").
  23. all() -> emqx_common_test_helpers:all(?MODULE).
  24. init_per_suite(Config) ->
  25. Apps = emqx_cth_suite:start(
  26. [emqx, emqx_conf, emqx_retainer_SUITE:app_spec()],
  27. #{work_dir => emqx_cth_suite:work_dir(Config)}
  28. ),
  29. [{suite_apps, Apps} | Config].
  30. end_per_suite(Config) ->
  31. emqx_cth_suite:stop(?config(suite_apps, Config)).
  32. t_reindex_status(_Config) ->
  33. ok = emqx_retainer_cli:retainer(["reindex", "status"]).
  34. t_info(_Config) ->
  35. ok = emqx_retainer_cli:retainer(["info"]).
  36. t_topics(_Config) ->
  37. ok = emqx_retainer_cli:retainer(["topics"]).
  38. t_topics_with_len(_Config) ->
  39. ok = emqx_retainer_cli:retainer(["topics", "100", "200"]).
  40. t_clean(_Config) ->
  41. ok = emqx_retainer_cli:retainer(["clean"]).
  42. t_topic(_Config) ->
  43. ok = emqx_retainer_cli:retainer(["clean", "foo/bar"]).
  44. t_reindex(_Config) ->
  45. {ok, C} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
  46. {ok, _} = emqtt:connect(C),
  47. ok = emqx_retainer:clean(),
  48. ?check_trace(
  49. ?wait_async_action(
  50. lists:foreach(
  51. fun(N) ->
  52. emqtt:publish(
  53. C,
  54. erlang:iolist_to_binary([
  55. <<"retained/">>,
  56. io_lib:format("~5..0w", [N])
  57. ]),
  58. <<"this is a retained message">>,
  59. [{qos, 0}, {retain, true}]
  60. )
  61. end,
  62. lists:seq(1, 1000)
  63. ),
  64. #{?snk_kind := message_retained, topic := <<"retained/01000">>},
  65. 1000
  66. ),
  67. []
  68. ),
  69. emqx_config:put([retainer, backend, index_specs], [[4, 5]]),
  70. ok = emqx_retainer_cli:retainer(["reindex", "start"]),
  71. ?assertEqual(1000, mnesia:table_info(?TAB_INDEX, size)).