|
|
@@ -28,7 +28,7 @@
|
|
|
all() -> emqx_common_test_helpers:all(?MODULE).
|
|
|
|
|
|
-define(BASE_CONF, <<"""
|
|
|
-emqx_retainer {
|
|
|
+retainer {
|
|
|
enable = true
|
|
|
msg_clear_interval = 0s
|
|
|
msg_expiry_interval = 0s
|
|
|
@@ -90,7 +90,10 @@ t_store_and_clean(_) ->
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
|
|
|
- emqtt:publish(C1, <<"retained">>, <<"this is a retained message">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained">>,
|
|
|
+ <<"this is a retained message">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
timer:sleep(100),
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained">>, [{qos, 0}, {rh, 0}]),
|
|
|
?assertEqual(1, length(receive_messages(1))),
|
|
|
@@ -118,7 +121,10 @@ t_retain_handling(_) ->
|
|
|
?assertEqual(0, length(receive_messages(1))),
|
|
|
{ok, #{}, [0]} = emqtt:unsubscribe(C1, <<"retained/#">>),
|
|
|
|
|
|
- emqtt:publish(C1, <<"retained">>, <<"this is a retained message">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained">>,
|
|
|
+ <<"this is a retained message">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained">>, [{qos, 0}, {rh, 0}]),
|
|
|
?assertEqual(1, length(receive_messages(1))),
|
|
|
@@ -148,9 +154,18 @@ t_retain_handling(_) ->
|
|
|
t_wildcard_subscription(_) ->
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
- emqtt:publish(C1, <<"retained/0">>, <<"this is a retained message 0">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/1">>, <<"this is a retained message 1">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/a/b/c">>, <<"this is a retained message 2">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/0">>,
|
|
|
+ <<"this is a retained message 0">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/1">>,
|
|
|
+ <<"this is a retained message 1">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/a/b/c">>,
|
|
|
+ <<"this is a retained message 2">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/+">>, 0),
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/+/b/#">>, 0),
|
|
|
@@ -165,11 +180,26 @@ t_message_expiry(_) ->
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
|
|
|
- emqtt:publish(C1, <<"retained/0">>, #{'Message-Expiry-Interval' => 0}, <<"don't expire">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/1">>, #{'Message-Expiry-Interval' => 2}, <<"expire">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/2">>, #{'Message-Expiry-Interval' => 5}, <<"don't expire">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/3">>, <<"don't expire">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"$SYS/retained/4">>, <<"don't expire">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/0">>, #{'Message-Expiry-Interval' => 0},
|
|
|
+ <<"don't expire">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/1">>, #{'Message-Expiry-Interval' => 2},
|
|
|
+ <<"expire">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/2">>, #{'Message-Expiry-Interval' => 5},
|
|
|
+ <<"don't expire">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/3">>,
|
|
|
+ <<"don't expire">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"$SYS/retained/4">>,
|
|
|
+ <<"don't expire">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/+">>, 0),
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"$SYS/retained/+">>, 0),
|
|
|
@@ -210,9 +240,18 @@ t_message_expiry_2(_) ->
|
|
|
t_clean(_) ->
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
- emqtt:publish(C1, <<"retained/0">>, <<"this is a retained message 0">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/1">>, <<"this is a retained message 1">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/test/0">>, <<"this is a retained message 2">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/0">>,
|
|
|
+ <<"this is a retained message 0">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/1">>,
|
|
|
+ <<"this is a retained message 1">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/test/0">>,
|
|
|
+ <<"this is a retained message 2">>,
|
|
|
+ [{qos, 0}, {retain, true}]),
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/#">>, [{qos, 0}, {rh, 0}]),
|
|
|
?assertEqual(3, length(receive_messages(3))),
|
|
|
|
|
|
@@ -227,7 +266,11 @@ t_stop_publish_clear_msg(_) ->
|
|
|
emqx_retainer:update_config(#{<<"stop_publish_clear_msg">> => true}),
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
- emqtt:publish(C1, <<"retained/0">>, <<"this is a retained message 0">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/0">>,
|
|
|
+ <<"this is a retained message 0">>,
|
|
|
+ [{qos, 0}, {retain, true}]
|
|
|
+ ),
|
|
|
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/#">>, [{qos, 0}, {rh, 0}]),
|
|
|
?assertEqual(1, length(receive_messages(1))),
|
|
|
@@ -239,14 +282,27 @@ t_stop_publish_clear_msg(_) ->
|
|
|
ok = emqtt:disconnect(C1).
|
|
|
|
|
|
t_flow_control(_) ->
|
|
|
- emqx_retainer:update_config(#{<<"flow_control">> => #{<<"max_read_number">> => 1,
|
|
|
- <<"msg_deliver_quota">> => 1,
|
|
|
- <<"quota_release_interval">> => <<"1s">>}}),
|
|
|
+ emqx_retainer:update_config(#{<<"flow_control">> =>
|
|
|
+ #{<<"max_read_number">> => 1,
|
|
|
+ <<"msg_deliver_quota">> => 1,
|
|
|
+ <<"quota_release_interval">> => <<"1s">>}}),
|
|
|
{ok, C1} = emqtt:start_link([{clean_start, true}, {proto_ver, v5}]),
|
|
|
{ok, _} = emqtt:connect(C1),
|
|
|
- emqtt:publish(C1, <<"retained/0">>, <<"this is a retained message 0">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/1">>, <<"this is a retained message 1">>, [{qos, 0}, {retain, true}]),
|
|
|
- emqtt:publish(C1, <<"retained/3">>, <<"this is a retained message 3">>, [{qos, 0}, {retain, true}]),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/0">>,
|
|
|
+ <<"this is a retained message 0">>,
|
|
|
+ [{qos, 0}, {retain, true}]
|
|
|
+ ),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/1">>,
|
|
|
+ <<"this is a retained message 1">>,
|
|
|
+ [{qos, 0}, {retain, true}]
|
|
|
+ ),
|
|
|
+ emqtt:publish(
|
|
|
+ C1, <<"retained/3">>,
|
|
|
+ <<"this is a retained message 3">>,
|
|
|
+ [{qos, 0}, {retain, true}]
|
|
|
+ ),
|
|
|
Begin = erlang:system_time(millisecond),
|
|
|
{ok, #{}, [0]} = emqtt:subscribe(C1, <<"retained/#">>, [{qos, 0}, {rh, 0}]),
|
|
|
?assertEqual(3, length(receive_messages(3))),
|