Add emqx_cm, emqx_metrics, emqx_stats test suites
This commit is contained in:
parent
8b4be236e5
commit
6b45834de4
|
@ -0,0 +1,39 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2013-2018 EMQ Enterprise, Inc. (http://emqtt.io)
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(emqx_cm_SUITE).
|
||||
|
||||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
|
||||
all() -> [t_register_unregister_client].
|
||||
|
||||
t_register_unregister_client(_) ->
|
||||
{ok, _} = emqx_cm_sup:start_link(),
|
||||
Pid = self(),
|
||||
emqx_cm:register_client(<<0, 0, 1>>),
|
||||
emqx_cm:register_client({<<0, 0, 2>>, Pid}, [{port, 8080}, {ip, "192.168.0.1"}]),
|
||||
timer:sleep(2000),
|
||||
[{<<0, 0, 1>>, Pid}] = emqx_cm:lookup_client(<<0, 0, 1>>),
|
||||
[{<<0, 0, 2>>, Pid}] = emqx_cm:lookup_client(<<0, 0, 2>>),
|
||||
Pid = emqx_cm:lookup_client_pid(<<0, 0, 1>>),
|
||||
emqx_cm:unregister_client(<<0, 0, 1>>),
|
||||
[] = emqx_cm:lookup_client(<<0, 0, 1>>),
|
||||
[{port, 8080}, {ip, "192.168.0.1"}] = emqx_cm:get_client_attrs({<<0, 0, 2>>, Pid}),
|
||||
emqx_cm:set_client_stats(<<0, 0, 2>>, [[{count, 1}, {max, 2}]]),
|
||||
[[{count, 1}, {max, 2}]] = emqx_cm:get_client_stats({<<0, 0, 2>>, Pid}).
|
|
@ -0,0 +1,41 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2013-2018 EMQ Enterprise, Inc. (http://emqtt.io)
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(emqx_metrics_SUITE).
|
||||
|
||||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
|
||||
all() -> [t_inc_dec_metrics].
|
||||
|
||||
t_inc_dec_metrics(_) ->
|
||||
{ok, _} = emqx_metrics:start_link(),
|
||||
{0, 0} = {emqx_metrics:val('bytes/received'), emqx_metrics:val('messages/retained')},
|
||||
emqx_metrics:inc('bytes/received'),
|
||||
emqx_metrics:inc({counter, 'bytes/received'}, 2),
|
||||
emqx_metrics:inc(counter, 'bytes/received', 2),
|
||||
emqx_metrics:inc({gauge, 'messages/retained'}, 2),
|
||||
emqx_metrics:inc(gauge, 'messages/retained', 2),
|
||||
{5, 4} = {emqx_metrics:val('bytes/received'), emqx_metrics:val('messages/retained')},
|
||||
emqx_metrics:dec(gauge, 'messages/retained'),
|
||||
emqx_metrics:dec(gauge, 'messages/retained', 1),
|
||||
2 = emqx_metrics:val('messages/retained'),
|
||||
emqx_metrics:received(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNECT}}),
|
||||
{1, 1} = {emqx_metrics:val('packets/received'), emqx_metrics:val('packets/connect')},
|
||||
emqx_metrics:sent(#mqtt_packet{header = #mqtt_packet_header{type = ?CONNACK}}),
|
||||
{1, 1} = {emqx_metrics:val('packets/sent'), emqx_metrics:val('packets/connack')}.
|
|
@ -0,0 +1,60 @@
|
|||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2013-2018 EMQ Enterprise, Inc. (http://emqtt.io)
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(emqx_stats_SUITE).
|
||||
|
||||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
||||
all() -> [t_set_get_state, t_update_interval].
|
||||
|
||||
t_set_get_state(_) ->
|
||||
{ok, _} = emqx_stats:start_link(),
|
||||
SetClientsCount = emqx_stats:statsfun('clients/count'),
|
||||
SetClientsCount(1),
|
||||
1 = emqx_stats:getstat('clients/count'),
|
||||
emqx_stats:setstat('clients/count', 2),
|
||||
2 = emqx_stats:getstat('clients/count'),
|
||||
emqx_stats:setstat('clients/count', 'clients/max', 3),
|
||||
timer:sleep(100),
|
||||
3 = emqx_stats:getstat('clients/count'),
|
||||
3 = emqx_stats:getstat('clients/max'),
|
||||
emqx_stats:setstat('clients/count', 'clients/max', 2),
|
||||
timer:sleep(100),
|
||||
2 = emqx_stats:getstat('clients/count'),
|
||||
3 = emqx_stats:getstat('clients/max'),
|
||||
SetClients = emqx_stats:statsfun('clients/count', 'clients/max'),
|
||||
SetClients(4),
|
||||
timer:sleep(100),
|
||||
4 = emqx_stats:getstat('clients/count'),
|
||||
4 = emqx_stats:getstat('clients/max'),
|
||||
Clients = emqx_stats:getstats(),
|
||||
4 = proplists:get_value('clients/count', Clients),
|
||||
4 = proplists:get_value('clients/max', Clients).
|
||||
|
||||
t_update_interval(_) ->
|
||||
{ok, _} = emqx_stats:start_link(),
|
||||
ok = emqx_stats:update_interval(cm_stats, fun update_stats/0),
|
||||
timer:sleep(2000),
|
||||
1 = emqx_stats:getstat('clients/count').
|
||||
|
||||
update_stats() ->
|
||||
ClientsCount = emqx_stats:getstat('clients/count'),
|
||||
ct:log("hello~n"),
|
||||
% emqx_stats:setstat('clients/count', 'clients/max', ClientsCount + 1).
|
||||
emqx_stats:setstat('clients/count', 1).
|
Loading…
Reference in New Issue