From 0ba8d3e11db5dccdaca47a32ab6b8ba5cc0dcee9 Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Wed, 6 Dec 2017 20:13:27 +0800 Subject: [PATCH 1/3] Depends on develop branch of esockd and mochiweb --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index d529cdbc5..1c919bb1e 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ dep_goldrush = git https://github.com/basho/goldrush 0.1.9 dep_gproc = git https://github.com/uwiger/gproc dep_getopt = git https://github.com/jcomellas/getopt v0.8.2 dep_lager = git https://github.com/basho/lager master -dep_esockd = git https://github.com/emqtt/esockd master +dep_esockd = git https://github.com/emqtt/esockd develop dep_ekka = git https://github.com/emqtt/ekka master -dep_mochiweb = git https://github.com/emqtt/mochiweb master +dep_mochiweb = git https://github.com/emqtt/mochiweb develop dep_pbkdf2 = git https://github.com/emqtt/pbkdf2 2.0.1 dep_lager_syslog = git https://github.com/basho/lager_syslog dep_bcrypt = git https://github.com/smarkets/erlang-bcrypt master From 896088b7e8d41524e8580354262156b6a0863444 Mon Sep 17 00:00:00 2001 From: HuangDan Date: Wed, 6 Dec 2017 21:09:03 +0800 Subject: [PATCH 2/3] Router test cases migration from emqttd_SUITE to emqttd_route_SUITE --- test/emqttd_SUITE.erl | 52 ---------------------------------- test/emqttd_router_SUITE.erl | 54 ++++++++++++++++++++++++++++++++---- 2 files changed, 48 insertions(+), 58 deletions(-) diff --git a/test/emqttd_SUITE.erl b/test/emqttd_SUITE.erl index 76a8e7614..c5794e5b0 100644 --- a/test/emqttd_SUITE.erl +++ b/test/emqttd_SUITE.erl @@ -58,7 +58,6 @@ all() -> [{group, protocol}, {group, pubsub}, - {group, router}, {group, session}, {group, broker}, {group, metrics}, @@ -81,10 +80,6 @@ groups() -> t_local_subscribe, t_shared_subscribe, 'pubsub#', 'pubsub+']}, - {router, [sequence], - [router_add_del, - router_print, - router_unused]}, {session, [sequence], [start_session]}, {broker, [sequence], @@ -291,53 +286,6 @@ loop_recv(Topic, Timeout, Acc) -> Timeout -> {ok, Acc} end. -%%-------------------------------------------------------------------- -%% Router Test -%%-------------------------------------------------------------------- - -router_add_del(_) -> - %% Add - emqttd_router:add_route(<<"#">>), - emqttd_router:add_route(<<"a/b/c">>), - emqttd_router:add_route(<<"+/#">>), - Routes = [R1, R2 | _] = [ - #mqtt_route{topic = <<"#">>, node = node()}, - #mqtt_route{topic = <<"+/#">>, node = node()}, - #mqtt_route{topic = <<"a/b/c">>, node = node()}], - Routes = lists:sort(emqttd_router:match(<<"a/b/c">>)), - - %% Batch Add - lists:foreach(fun(R) -> emqttd_router:add_route(R) end, Routes), - Routes = lists:sort(emqttd_router:match(<<"a/b/c">>)), - - %% Del - emqttd_router:del_route(<<"a/b/c">>), - [R1, R2] = lists:sort(emqttd_router:match(<<"a/b/c">>)), - {atomic, []} = mnesia:transaction(fun emqttd_trie:lookup/1, [<<"a/b/c">>]), - - %% Batch Del - R3 = #mqtt_route{topic = <<"#">>, node = 'a@127.0.0.1'}, - emqttd_router:add_route(R3), - emqttd_router:del_route(R1), - emqttd_router:del_route(R2), - emqttd_router:del_route(R3), - [] = lists:sort(emqttd_router:match(<<"a/b/c">>)). - -router_print(_) -> - Routes = [#mqtt_route{topic = <<"a/b/c">>, node = node()}, - #mqtt_route{topic = <<"#">>, node = node()}, - #mqtt_route{topic = <<"+/#">>, node = node()}], - lists:foreach(fun(R) -> emqttd_router:add_route(R) end, Routes), - emqttd_router:print(<<"a/b/c">>), - emqttd_router:del_route(<<"+/#">>), - emqttd_router:del_route(<<"a/b/c">>), - emqttd_router:del_route(<<"#">>). - -router_unused(_) -> - gen_server:call(emqttd_router, bad_call), - gen_server:cast(emqttd_router, bad_msg), - emqttd_router ! bad_info. - recv_loop(Msgs) -> receive {dispatch, _Topic, Msg} -> diff --git a/test/emqttd_router_SUITE.erl b/test/emqttd_router_SUITE.erl index addd36288..415550ec3 100644 --- a/test/emqttd_router_SUITE.erl +++ b/test/emqttd_router_SUITE.erl @@ -34,7 +34,8 @@ groups() -> t_add_del_route, t_match_route, t_print, - t_has_route]}, + t_has_route, + router_unused]}, {local_route, [sequence], [t_get_local_topics, t_add_del_local_route, @@ -86,11 +87,6 @@ t_match_route(_) -> #mqtt_route{topic = <<"a/b/c">>, node = Node}], lists:sort(?R:match(<<"a/b/c">>))). -t_print(_) -> - ?R:add_route(<<"topic">>), - ?R:add_route(<<"topic/#">>), - ?R:print(<<"topic">>). - t_has_route(_) -> ?R:add_route(<<"devices/+/messages">>), ?assert(?R:has_route(<<"devices/+/messages">>)). @@ -130,3 +126,49 @@ clear_tables() -> ?R:clean_local_routes(), lists:foreach(fun mnesia:clear_table/1, [mqtt_route, mqtt_trie, mqtt_trie_node]). +%%-------------------------------------------------------------------- +%% Router Test +%%-------------------------------------------------------------------- + +router_add_del(_) -> + %% Add + ?R:add_route(<<"#">>), + ?R:add_route(<<"a/b/c">>), + ?R:add_route(<<"+/#">>), + Routes = [R1, R2 | _] = [ + #mqtt_route{topic = <<"#">>, node = node()}, + #mqtt_route{topic = <<"+/#">>, node = node()}, + #mqtt_route{topic = <<"a/b/c">>, node = node()}], + Routes = lists:sort(?R:match(<<"a/b/c">>)), + + %% Batch Add + lists:foreach(fun(R) -> ?R:add_route(R) end, Routes), + Routes = lists:sort(?R:match(<<"a/b/c">>)), + + %% Del + ?R:del_route(<<"a/b/c">>), + [R1, R2] = lists:sort(?R:match(<<"a/b/c">>)), + {atomic, []} = mnesia:transaction(fun emqttd_trie:lookup/1, [<<"a/b/c">>]), + + %% Batch Del + R3 = #mqtt_route{topic = <<"#">>, node = 'a@127.0.0.1'}, + ?R:add_route(R3), + ?R:del_route(R1), + ?R:del_route(R2), + ?R:del_route(R3), + [] = lists:sort(?R:match(<<"a/b/c">>)). + +t_print(_) -> + Routes = [#mqtt_route{topic = <<"a/b/c">>, node = node()}, + #mqtt_route{topic = <<"#">>, node = node()}, + #mqtt_route{topic = <<"+/#">>, node = node()}], + lists:foreach(fun(R) -> ?R:add_route(R) end, Routes), + ?R:print(<<"a/b/c">>), + ?R:del_route(<<"+/#">>), + ?R:del_route(<<"a/b/c">>), + ?R:del_route(<<"#">>). + +router_unused(_) -> + gen_server:call(emqttd_router, bad_call), + gen_server:cast(emqttd_router, bad_msg), + emqttd_router ! bad_info. From ceafaad6b7c0a4269359e3f8fd046784656f6da7 Mon Sep 17 00:00:00 2001 From: HuangDan Date: Wed, 6 Dec 2017 21:22:36 +0800 Subject: [PATCH 3/3] Update deps branch --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f3407dd9e..55dfd711e 100644 --- a/Makefile +++ b/Makefile @@ -8,9 +8,9 @@ dep_goldrush = git https://github.com/basho/goldrush 0.1.9 dep_gproc = git https://github.com/uwiger/gproc dep_getopt = git https://github.com/jcomellas/getopt v0.8.2 dep_lager = git https://github.com/basho/lager master -dep_esockd = git https://github.com/emqtt/esockd develop +dep_esockd = git https://github.com/emqtt/esockd v5.1 dep_ekka = git https://github.com/emqtt/ekka master -dep_mochiweb = git https://github.com/emqtt/mochiweb develop +dep_mochiweb = git https://github.com/emqtt/mochiweb v4.2.0 dep_pbkdf2 = git https://github.com/emqtt/pbkdf2 2.0.1 dep_lager_syslog = git https://github.com/basho/lager_syslog dep_bcrypt = git https://github.com/smarkets/erlang-bcrypt master