test: add node query tests and some more
This commit is contained in:
parent
0e9289e48c
commit
9e954585ae
|
@ -67,7 +67,7 @@ t_cluster_query(_Config) ->
|
||||||
|
|
||||||
%% assert: AllPage = Page1 + Page2 + Page3 + Page4
|
%% assert: AllPage = Page1 + Page2 + Page3 + Page4
|
||||||
%% !!!Note: this equation requires that the queried tables must be ordered_set
|
%% !!!Note: this equation requires that the queried tables must be ordered_set
|
||||||
{200, ClientsPage2} = query_clients(Node1, #{<<"page">> => 2, <<"limit">> => 5}),
|
{200, ClientsPage2} = query_clients(Node1, #{<<"page">> => <<"2">>, <<"limit">> => 5}),
|
||||||
{200, ClientsPage3} = query_clients(Node2, #{<<"page">> => 3, <<"limit">> => 5}),
|
{200, ClientsPage3} = query_clients(Node2, #{<<"page">> => 3, <<"limit">> => 5}),
|
||||||
{200, ClientsPage4} = query_clients(Node1, #{<<"page">> => 4, <<"limit">> => 5}),
|
{200, ClientsPage4} = query_clients(Node1, #{<<"page">> => 4, <<"limit">> => 5}),
|
||||||
GetClientIds = fun(L) -> lists:map(fun(#{clientid := Id}) -> Id end, L) end,
|
GetClientIds = fun(L) -> lists:map(fun(#{clientid := Id}) -> Id end, L) end,
|
||||||
|
@ -79,6 +79,72 @@ t_cluster_query(_Config) ->
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
%% Scroll past count
|
||||||
|
{200, ClientsPage10} = query_clients(Node1, #{<<"page">> => <<"10">>, <<"limit">> => 5}),
|
||||||
|
?assertEqual(
|
||||||
|
#{data => [], meta => #{page => 10, limit => 5, count => 20, hasnext => false}},
|
||||||
|
ClientsPage10
|
||||||
|
),
|
||||||
|
|
||||||
|
%% Node queries
|
||||||
|
{200, ClientsNode2} = query_clients(Node1, #{<<"node">> => Node2}),
|
||||||
|
?assertEqual({200, ClientsNode2}, query_clients(Node2, #{<<"node">> => Node2})),
|
||||||
|
?assertMatch(
|
||||||
|
#{page := 1, limit := 100, count := 10},
|
||||||
|
maps:get(meta, ClientsNode2)
|
||||||
|
),
|
||||||
|
?assertMatch(10, length(maps:get(data, ClientsNode2))),
|
||||||
|
|
||||||
|
{200, ClientsNode2Page1} = query_clients(Node2, #{<<"node">> => Node2, <<"limit">> => 5}),
|
||||||
|
{200, ClientsNode2Page2} = query_clients(Node1, #{
|
||||||
|
<<"node">> => Node2, <<"page">> => <<"2">>, <<"limit">> => 5
|
||||||
|
}),
|
||||||
|
{200, ClientsNode2Page3} = query_clients(Node2, #{
|
||||||
|
<<"node">> => Node2, <<"page">> => 3, <<"limit">> => 5
|
||||||
|
}),
|
||||||
|
{200, ClientsNode2Page4} = query_clients(Node1, #{
|
||||||
|
<<"node">> => Node2, <<"page">> => 4, <<"limit">> => 5
|
||||||
|
}),
|
||||||
|
?assertEqual(
|
||||||
|
GetClientIds(maps:get(data, ClientsNode2)),
|
||||||
|
GetClientIds(
|
||||||
|
lists:append([
|
||||||
|
maps:get(data, Page)
|
||||||
|
|| Page <- [
|
||||||
|
ClientsNode2Page1,
|
||||||
|
ClientsNode2Page2,
|
||||||
|
ClientsNode2Page3,
|
||||||
|
ClientsNode2Page4
|
||||||
|
]
|
||||||
|
])
|
||||||
|
)
|
||||||
|
),
|
||||||
|
|
||||||
|
%% Scroll past count
|
||||||
|
{200, ClientsNode2Page10} = query_clients(Node1, #{
|
||||||
|
<<"node">> => Node2, <<"page">> => <<"10">>, <<"limit">> => 5
|
||||||
|
}),
|
||||||
|
?assertEqual(
|
||||||
|
#{data => [], meta => #{page => 10, limit => 5, count => 10, hasnext => false}},
|
||||||
|
ClientsNode2Page10
|
||||||
|
),
|
||||||
|
|
||||||
|
%% Query with bad params
|
||||||
|
?assertEqual(
|
||||||
|
{400, #{
|
||||||
|
code => <<"INVALID_PARAMETER">>,
|
||||||
|
message => <<"page_limit_invalid">>
|
||||||
|
}},
|
||||||
|
query_clients(Node1, #{<<"page">> => -1})
|
||||||
|
),
|
||||||
|
?assertEqual(
|
||||||
|
{400, #{
|
||||||
|
code => <<"INVALID_PARAMETER">>,
|
||||||
|
message => <<"page_limit_invalid">>
|
||||||
|
}},
|
||||||
|
query_clients(Node1, #{<<"node">> => Node1, <<"page">> => -1})
|
||||||
|
),
|
||||||
|
|
||||||
%% exact match can return non-zero total
|
%% exact match can return non-zero total
|
||||||
{200, ClientsNode1} = query_clients(Node2, #{<<"username">> => <<"corenode1@127.0.0.1">>}),
|
{200, ClientsNode1} = query_clients(Node2, #{<<"username">> => <<"corenode1@127.0.0.1">>}),
|
||||||
?assertMatch(
|
?assertMatch(
|
||||||
|
@ -87,11 +153,11 @@ t_cluster_query(_Config) ->
|
||||||
),
|
),
|
||||||
|
|
||||||
%% fuzzy searching can't return total
|
%% fuzzy searching can't return total
|
||||||
{200, ClientsNode2} = query_clients(Node2, #{<<"like_username">> => <<"corenode2">>}),
|
{200, ClientsFuzzyNode2} = query_clients(Node2, #{<<"like_username">> => <<"corenode2">>}),
|
||||||
MetaNode2 = maps:get(meta, ClientsNode2),
|
MetaNode2 = maps:get(meta, ClientsFuzzyNode2),
|
||||||
?assertNotMatch(#{count := _}, MetaNode2),
|
?assertNotMatch(#{count := _}, MetaNode2),
|
||||||
?assertMatch(#{hasnext := false}, MetaNode2),
|
?assertMatch(#{hasnext := false}, MetaNode2),
|
||||||
?assertMatch(10, length(maps:get(data, ClientsNode2))),
|
?assertMatch(10, length(maps:get(data, ClientsFuzzyNode2))),
|
||||||
|
|
||||||
_ = lists:foreach(fun(C) -> emqtt:disconnect(C) end, ClientLs1),
|
_ = lists:foreach(fun(C) -> emqtt:disconnect(C) end, ClientLs1),
|
||||||
_ = lists:foreach(fun(C) -> emqtt:disconnect(C) end, ClientLs2)
|
_ = lists:foreach(fun(C) -> emqtt:disconnect(C) end, ClientLs2)
|
||||||
|
|
Loading…
Reference in New Issue