Merge branch 'emq30' of github.com:emqtt/emqttd into emq30
This commit is contained in:
commit
bf91f5d92f
3
Makefile
3
Makefile
|
@ -28,7 +28,8 @@ EUNIT_OPTS = verbose
|
||||||
# EUNIT_ERL_OPTS =
|
# EUNIT_ERL_OPTS =
|
||||||
|
|
||||||
CT_SUITES = emqttd emqttd_access emqttd_lib emqttd_mod emqttd_net \
|
CT_SUITES = emqttd emqttd_access emqttd_lib emqttd_mod emqttd_net \
|
||||||
emqttd_mqueue emqttd_protocol emqttd_topic emqttd_trie
|
emqttd_mqueue emqttd_protocol emqttd_topic emqttd_trie \
|
||||||
|
emqttd_vm
|
||||||
CT_OPTS = -cover test/ct.cover.spec -erl_args -name emqttd_ct@127.0.0.1
|
CT_OPTS = -cover test/ct.cover.spec -erl_args -name emqttd_ct@127.0.0.1
|
||||||
|
|
||||||
COVER = true
|
COVER = true
|
||||||
|
|
|
@ -101,6 +101,7 @@ groups() ->
|
||||||
init_per_suite(Config) ->
|
init_per_suite(Config) ->
|
||||||
application:start(lager),
|
application:start(lager),
|
||||||
DataDir = proplists:get_value(data_dir, Config),
|
DataDir = proplists:get_value(data_dir, Config),
|
||||||
|
peg_com(DataDir),
|
||||||
start_apps(emqttd, DataDir),
|
start_apps(emqttd, DataDir),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
|
@ -598,7 +599,6 @@ slave(node, Node) ->
|
||||||
N.
|
N.
|
||||||
|
|
||||||
start_apps(App, DataDir) ->
|
start_apps(App, DataDir) ->
|
||||||
application:start(lager),
|
|
||||||
Schema = cuttlefish_schema:files([filename:join([DataDir, atom_to_list(App) ++ ".schema"])]),
|
Schema = cuttlefish_schema:files([filename:join([DataDir, atom_to_list(App) ++ ".schema"])]),
|
||||||
Conf = conf_parse:file(filename:join([DataDir, atom_to_list(App) ++ ".conf"])),
|
Conf = conf_parse:file(filename:join([DataDir, atom_to_list(App) ++ ".conf"])),
|
||||||
NewConfig = cuttlefish_generator:map(Schema, Conf),
|
NewConfig = cuttlefish_generator:map(Schema, Conf),
|
||||||
|
@ -606,3 +606,23 @@ start_apps(App, DataDir) ->
|
||||||
[application:set_env(App, Par, Value) || {Par, Value} <- Vals],
|
[application:set_env(App, Par, Value) || {Par, Value} <- Vals],
|
||||||
application:ensure_all_started(App).
|
application:ensure_all_started(App).
|
||||||
|
|
||||||
|
peg_com(DataDir) ->
|
||||||
|
ParsePeg = file2(3, DataDir, "conf_parse.peg"),
|
||||||
|
neotoma:file(ParsePeg),
|
||||||
|
ParseErl = file2(3, DataDir, "conf_parse.erl"),
|
||||||
|
compile:file(ParseErl, []),
|
||||||
|
|
||||||
|
DurationPeg = file2(3, DataDir, "cuttlefish_duration_parse.peg"),
|
||||||
|
neotoma:file(DurationPeg),
|
||||||
|
DurationErl = file2(3, DataDir, "cuttlefish_duration_parse.erl"),
|
||||||
|
compile:file(DurationErl, []).
|
||||||
|
|
||||||
|
|
||||||
|
file2(Times, Dir, FileName) when Times < 1 ->
|
||||||
|
filename:join([Dir, "deps", "cuttlefish","src", FileName]);
|
||||||
|
|
||||||
|
file2(Times, Dir, FileName) ->
|
||||||
|
Dir1 = filename:dirname(Dir),
|
||||||
|
file2(Times - 1, Dir1, FileName).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -91,43 +91,39 @@ end_per_testcase(_TestCase, _Config) ->
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
reload_acl(_) ->
|
reload_acl(_) ->
|
||||||
[ok] = ?AC:reload_acl().
|
[] = ?AC:reload_acl().
|
||||||
|
|
||||||
register_mod(_) ->
|
register_mod(_) ->
|
||||||
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
{error, already_existed} = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
{error, already_existed} = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
[{emqttd_acl_test_mod, _, 0},
|
[{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl),
|
||||||
{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_dashboard, [], 99),
|
ok = ?AC:register_mod(auth, emqttd_auth_dashboard, [], 99),
|
||||||
[{emqttd_auth_dashboard, _, 99},
|
[{emqttd_auth_dashboard, _, 99},
|
||||||
{emqttd_auth_anonymous_test_mod, _, 0},
|
{emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth).
|
||||||
{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth).
|
|
||||||
|
|
||||||
unregister_mod(_) ->
|
unregister_mod(_) ->
|
||||||
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
ok = ?AC:register_mod(acl, emqttd_acl_test_mod, []),
|
||||||
[{emqttd_acl_test_mod, _, 0},
|
[{emqttd_acl_test_mod, _, 0}] = ?AC:lookup_mods(acl),
|
||||||
{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
|
||||||
ok = ?AC:unregister_mod(acl, emqttd_acl_test_mod),
|
ok = ?AC:unregister_mod(acl, emqttd_acl_test_mod),
|
||||||
timer:sleep(5),
|
timer:sleep(5),
|
||||||
[{emqttd_acl_internal, _, 0}] = ?AC:lookup_mods(acl),
|
[] = ?AC:lookup_mods(acl),
|
||||||
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
ok = ?AC:register_mod(auth, emqttd_auth_anonymous_test_mod,[]),
|
||||||
[{emqttd_auth_anonymous_test_mod, _, 0},
|
[{emqttd_auth_anonymous_test_mod, _, 0}] = ?AC:lookup_mods(auth),
|
||||||
{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth),
|
|
||||||
|
|
||||||
ok = ?AC:unregister_mod(auth, emqttd_auth_anonymous_test_mod),
|
ok = ?AC:unregister_mod(auth, emqttd_auth_anonymous_test_mod),
|
||||||
timer:sleep(5),
|
timer:sleep(5),
|
||||||
[{emqttd_auth_anonymous, _, 0}] = ?AC:lookup_mods(auth).
|
[] = ?AC:lookup_mods(auth).
|
||||||
|
|
||||||
check_acl(_) ->
|
check_acl(_) ->
|
||||||
User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>},
|
User1 = #mqtt_client{client_id = <<"client1">>, username = <<"testuser">>},
|
||||||
User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>},
|
User2 = #mqtt_client{client_id = <<"client2">>, username = <<"xyz">>},
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1">>),
|
||||||
deny = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"clients/client1/x/y">>),
|
||||||
allow = ?AC:check_acl(User1, publish, <<"users/testuser/1">>),
|
allow = ?AC:check_acl(User1, publish, <<"users/testuser/1">>),
|
||||||
allow = ?AC:check_acl(User1, subscribe, <<"a/b/c">>),
|
allow = ?AC:check_acl(User1, subscribe, <<"a/b/c">>),
|
||||||
deny = ?AC:check_acl(User2, subscribe, <<"a/b/c">>).
|
allow = ?AC:check_acl(User2, subscribe, <<"a/b/c">>).
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% emqttd_access_rule
|
%% emqttd_access_rule
|
||||||
|
|
|
@ -0,0 +1,174 @@
|
||||||
|
%%--------------------------------------------------------------------
|
||||||
|
%% Copyright (c) 2012-2016 Feng Lee <feng@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(emqttd_vm_SUITE).
|
||||||
|
|
||||||
|
-compile(export_all).
|
||||||
|
|
||||||
|
-include_lib("common_test/include/ct.hrl").
|
||||||
|
|
||||||
|
-define(SYSTEM_INFO, [allocated_areas,
|
||||||
|
allocator,
|
||||||
|
alloc_util_allocators,
|
||||||
|
build_type,
|
||||||
|
check_io,
|
||||||
|
compat_rel,
|
||||||
|
creation,
|
||||||
|
debug_compiled,
|
||||||
|
dist,
|
||||||
|
dist_ctrl,
|
||||||
|
driver_version,
|
||||||
|
elib_malloc,
|
||||||
|
dist_buf_busy_limit,
|
||||||
|
%fullsweep_after, % included in garbage_collection
|
||||||
|
garbage_collection,
|
||||||
|
%global_heaps_size, % deprecated
|
||||||
|
heap_sizes,
|
||||||
|
heap_type,
|
||||||
|
info,
|
||||||
|
kernel_poll,
|
||||||
|
loaded,
|
||||||
|
logical_processors,
|
||||||
|
logical_processors_available,
|
||||||
|
logical_processors_online,
|
||||||
|
machine,
|
||||||
|
%min_heap_size, % included in garbage_collection
|
||||||
|
%min_bin_vheap_size, % included in garbage_collection
|
||||||
|
modified_timing_level,
|
||||||
|
multi_scheduling,
|
||||||
|
multi_scheduling_blockers,
|
||||||
|
otp_release,
|
||||||
|
port_count,
|
||||||
|
process_count,
|
||||||
|
process_limit,
|
||||||
|
scheduler_bind_type,
|
||||||
|
scheduler_bindings,
|
||||||
|
scheduler_id,
|
||||||
|
schedulers,
|
||||||
|
schedulers_online,
|
||||||
|
smp_support,
|
||||||
|
system_version,
|
||||||
|
system_architecture,
|
||||||
|
threads,
|
||||||
|
thread_pool_size,
|
||||||
|
trace_control_word,
|
||||||
|
update_cpu_info,
|
||||||
|
version,
|
||||||
|
wordsize]).
|
||||||
|
|
||||||
|
-define(PROCESS_INFO, [initial_call,
|
||||||
|
current_function,
|
||||||
|
registered_name,
|
||||||
|
status,
|
||||||
|
message_queue_len,
|
||||||
|
group_leader,
|
||||||
|
priority,
|
||||||
|
trap_exit,
|
||||||
|
reductions,
|
||||||
|
%%binary,
|
||||||
|
last_calls,
|
||||||
|
catchlevel,
|
||||||
|
trace,
|
||||||
|
suspending,
|
||||||
|
sequential_trace_token,
|
||||||
|
error_handler]).
|
||||||
|
|
||||||
|
-define(PROCESS_GC, [memory,
|
||||||
|
total_heap_size,
|
||||||
|
heap_size,
|
||||||
|
stack_size,
|
||||||
|
min_heap_size]).
|
||||||
|
%fullsweep_after]).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
all() ->
|
||||||
|
[load, systeminfo, mem_info, process_list, process_info, process_gc,
|
||||||
|
get_ets_list, get_ets_info, get_ets_object, get_port_types, get_port_info,
|
||||||
|
scheduler_usage, get_memory, microsecs, schedulers, get_process_group_leader_info,
|
||||||
|
get_process_limit].
|
||||||
|
|
||||||
|
load(_Config) ->
|
||||||
|
Loads = emqttd_vm:loads(),
|
||||||
|
[{load1, _}, {load5, _}, {load15, _}] = Loads.
|
||||||
|
|
||||||
|
systeminfo(_Config) ->
|
||||||
|
Keys = [Key || {Key, _} <- emqttd_vm:get_system_info()],
|
||||||
|
?SYSTEM_INFO = Keys.
|
||||||
|
|
||||||
|
mem_info(_Config) ->
|
||||||
|
application:ensure_all_started(os_mon),
|
||||||
|
MemInfo = emqttd_vm:mem_info(),
|
||||||
|
[{total_memory, _},
|
||||||
|
{used_memory, _}]= MemInfo,
|
||||||
|
application:stop(os_mon).
|
||||||
|
|
||||||
|
process_list(_Config) ->
|
||||||
|
Pid = self(),
|
||||||
|
ProcessInfo = emqttd_vm:get_process_list(),
|
||||||
|
true = lists:member({pid, Pid}, lists:concat(ProcessInfo)).
|
||||||
|
|
||||||
|
process_info(_Config) ->
|
||||||
|
ProcessInfos = emqttd_vm:get_process_info(),
|
||||||
|
ProcessInfo = lists:last(ProcessInfos),
|
||||||
|
Keys = [K || {K, _V}<- ProcessInfo],
|
||||||
|
?PROCESS_INFO = Keys.
|
||||||
|
|
||||||
|
process_gc(_Config) ->
|
||||||
|
ProcessGcs = emqttd_vm:get_process_gc(),
|
||||||
|
ProcessGc = lists:last(ProcessGcs),
|
||||||
|
Keys = [K || {K, _V}<- ProcessGc],
|
||||||
|
?PROCESS_GC = Keys.
|
||||||
|
|
||||||
|
get_ets_list(_Config) ->
|
||||||
|
ets:new(test, [named_table]),
|
||||||
|
Ets = emqttd_vm:get_ets_list(),
|
||||||
|
true = lists:member(test, Ets).
|
||||||
|
|
||||||
|
get_ets_info(_Config) ->
|
||||||
|
ets:new(test, [named_table]),
|
||||||
|
[] = emqttd_vm:get_ets_info(test1),
|
||||||
|
EtsInfo = emqttd_vm:get_ets_info(test),
|
||||||
|
test = proplists:get_value(name, EtsInfo).
|
||||||
|
|
||||||
|
get_ets_object(_Config) ->
|
||||||
|
ets:new(test, [named_table]),
|
||||||
|
ets:insert(test, {k, v}),
|
||||||
|
[{k, v}] = emqttd_vm:get_ets_object(test).
|
||||||
|
|
||||||
|
get_port_types(_Config) ->
|
||||||
|
emqttd_vm:get_port_types().
|
||||||
|
|
||||||
|
get_port_info(_Config) ->
|
||||||
|
emqttd_vm:get_port_info().
|
||||||
|
|
||||||
|
scheduler_usage(_Config) ->
|
||||||
|
emqttd_vm:scheduler_usage(5000).
|
||||||
|
|
||||||
|
get_memory(_Config) ->
|
||||||
|
emqttd_vm:get_memory().
|
||||||
|
|
||||||
|
microsecs(_Config) ->
|
||||||
|
emqttd_vm:microsecs().
|
||||||
|
|
||||||
|
schedulers(_Config) ->
|
||||||
|
emqttd_vm:schedulers().
|
||||||
|
|
||||||
|
get_process_group_leader_info(_Config) ->
|
||||||
|
emqttd_vm:get_process_group_leader_info(self()).
|
||||||
|
|
||||||
|
get_process_limit(_Config) ->
|
||||||
|
emqttd_vm:get_process_limit().
|
Loading…
Reference in New Issue