diff options
| author | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2010-09-28 17:33:00 +0100 |
|---|---|---|
| committer | Vlad Alexandru Ionescu <vlad@rabbitmq.com> | 2010-09-28 17:33:00 +0100 |
| commit | bb46ac03bf9098acd25264deec76dd14f9fdee8a (patch) | |
| tree | 1f85809c6f0a724324074c2dcea1caa166b55b52 /src | |
| parent | c5fcc9702bcba6fe192bc35dd6b7e31b594d6b68 (diff) | |
| download | rabbitmq-server-git-bb46ac03bf9098acd25264deec76dd14f9fdee8a.tar.gz | |
using recursive split; more tests
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_exchange_type_topic.erl | 18 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 89 |
2 files changed, 69 insertions, 38 deletions
diff --git a/src/rabbit_exchange_type_topic.erl b/src/rabbit_exchange_type_topic.erl index 8e6918d038..bbd5d35780 100644 --- a/src/rabbit_exchange_type_topic.erl +++ b/src/rabbit_exchange_type_topic.erl @@ -108,6 +108,7 @@ which_matches(X, Key) -> trie_match(X, Words) -> trie_match(X, root, Words). + trie_match(X, Node, []) -> FinalRes = trie_bindings(X, Node), HashRes = case trie_child(X, Node, "#") of @@ -137,6 +138,7 @@ trie_match_skip_any(X, Node, [_ | RestW] = Words) -> follow_down(X, Words) -> follow_down(X, root, Words). + follow_down(_X, CurNode, []) -> {ok, CurNode}; follow_down(X, CurNode, [W | RestW]) -> @@ -158,6 +160,7 @@ follow_down_create(X, Words) -> follow_down_get_path(X, Words) -> follow_down_get_path(X, root, Words, [{root, none}]). + follow_down_get_path(_, _, [], PathAcc) -> PathAcc; follow_down_get_path(X, CurNode, [W | RestW], PathAcc) -> @@ -198,8 +201,10 @@ trie_bindings(X, Node) -> trie_add_edge(X, FromNode, ToNode, W) -> trie_edge_op(X, FromNode, ToNode, W, fun mnesia:write/3). + trie_remove_edge(X, FromNode, ToNode, W) -> trie_edge_op(X, FromNode, ToNode, W, fun mnesia:delete_object/3). + trie_edge_op(X, FromNode, ToNode, W, Op) -> ok = Op(rabbit_topic_trie_edge, #topic_trie_edge{trie_edge = #trie_edge{exchange_name = X, @@ -210,8 +215,10 @@ trie_edge_op(X, FromNode, ToNode, W, Op) -> trie_add_binding(X, Node, Q) -> trie_binding_op(X, Node, Q, fun mnesia:write/3). + trie_remove_binding(X, Node, Q) -> trie_binding_op(X, Node, Q, fun mnesia:delete_object/3). + trie_binding_op(X, Node, Q, Op) -> ok = Op(rabbit_topic_trie_binding, #topic_trie_binding{trie_binding = #trie_binding{exchange_name = X, @@ -271,4 +278,13 @@ new_node() -> rabbit_guid:guid(). split_topic_key(Key) -> - string:tokens(binary_to_list(Key), "."). + split_topic_key(Key, [], []). + +split_topic_key(<<>>, [], []) -> + []; +split_topic_key(<<>>, RevWordAcc, RevResAcc) -> + lists:reverse([lists:reverse(RevWordAcc) | RevResAcc]); +split_topic_key(<<$., Rest/binary>>, RevWordAcc, RevResAcc) -> + split_topic_key(Rest, [], [lists:reverse(RevWordAcc) | RevResAcc]); +split_topic_key(<<C:8, Rest/binary>>, RevWordAcc, RevResAcc) -> + split_topic_key(Rest, [C | RevWordAcc], RevResAcc). diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index fb0faebbf3..0308f5397f 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -581,19 +581,6 @@ sequence_with_content(Sequence) -> rabbit_framing_amqp_0_9_1), Sequence). -test_topic_expect_match(#exchange{name = XName}, List) -> - lists:foreach( - fun({Key, Expected}) -> - Res = rabbit_exchange_type_topic:which_matches( - XName, list_to_binary(Key)), - ExpectedRes = lists:map( - fun(Q) -> #resource{virtual_host = <<"/">>, - kind = queue, - name = list_to_binary(Q)} - end, Expected), - true = (lists:usort(ExpectedRes) =:= lists:usort(Res)) - end, List). - test_topic_matching() -> XName = #resource{virtual_host = <<"/">>, kind = exchange, @@ -631,27 +618,37 @@ test_topic_matching() -> {"", "t17"}, {"*.*.*", "t18"}, {"vodka.martini", "t19"}, - {"a.b.c", "t20"}]), + {"a.b.c", "t20"}, + {"*.#", "t21"}, + {"#.*.#", "t22"}, + {"*.#.#", "t23"}, + {"#.#.#", "t24"}, + {"*", "t25"}]), lists:foreach(fun(B) -> rabbit_exchange_type_topic:add_binding(X, B) end, Bindings), %% test some matches test_topic_expect_match(X, - [{"a.b.c", ["t1", "t2", "t5", "t6", "t10", "t11", "t12", "t18", "t20"]}, - {"a.b", ["t3", "t5", "t6", "t7", "t8", "t9", "t11", "t12", "t15"]}, - {"a.b.b", ["t3", "t5", "t6", "t7", "t11", "t12", "t14", "t18"]}, - {"", ["t5", "t6", "t17"]}, - {"b.c.c", ["t5", "t6", "t18"]}, - {"a.a.a.a.a", ["t5", "t6", "t11", "t12"]}, - {"vodka.gin", ["t5", "t6", "t8"]}, - {"vodka.martini", ["t5", "t6", "t8", "t19"]}, - {"b.b.c", ["t5", "t6", "t10", "t13", "t18"]}, - {"nothing.here.at.all", ["t5", "t6"]}, - {"un_der_sc.ore", ["t5", "t6", "t8"]}]), + [{"a.b.c", ["t1", "t2", "t5", "t6", "t10", "t11", "t12", "t18", "t20", + "t21", "t22", "t23", "t24"]}, + {"a.b", ["t3", "t5", "t6", "t7", "t8", "t9", "t11", "t12", "t15", + "t21", "t22", "t23", "t24"]}, + {"a.b.b", ["t3", "t5", "t6", "t7", "t11", "t12", "t14", "t18", "t21", + "t22", "t23", "t24"]}, + {"", ["t5", "t6", "t17", "t24"]}, + {"b.c.c", ["t5", "t6", "t18", "t21", "t22", "t23", "t24"]}, + {"a.a.a.a.a", ["t5", "t6", "t11", "t12", "t21", "t22", "t23", "t24"]}, + {"vodka.gin", ["t5", "t6", "t8", "t21", "t22", "t23", "t24"]}, + {"vodka.martini", ["t5", "t6", "t8", "t19", "t21", "t22", "t23", + "t24"]}, + {"b.b.c", ["t5", "t6", "t10", "t13", "t18", "t21", "t22", "t23", + "t24"]}, + {"nothing.here.at.all", ["t5", "t6", "t21", "t22", "t23", "t24"]}, + {"oneword", ["t5", "t6", "t21", "t22", "t23", "t24", "t25"]}]), %% remove some bindings RemovedBindings = [lists:nth(1, Bindings), lists:nth(5, Bindings), - lists:nth(11, Bindings)], + lists:nth(11, Bindings), lists:nth(21, Bindings)], rabbit_exchange_type_topic:remove_bindings(X, RemovedBindings), RemainingBindings = ordsets:to_list( ordsets:subtract(ordsets:from_list(Bindings), @@ -659,17 +656,20 @@ test_topic_matching() -> %% test some matches test_topic_expect_match(X, - [{"a.b.c", ["t2", "t6", "t10", "t12", "t18", "t20"]}, - {"a.b", ["t3", "t6", "t7", "t8", "t9", "t12", "t15"]}, - {"a.b.b", ["t3", "t6", "t7", "t12", "t14", "t18"]}, - {"", ["t6", "t17"]}, - {"b.c.c", ["t6", "t18"]}, - {"a.a.a.a.a", ["t6", "t12"]}, - {"vodka.gin", ["t6", "t8"]}, - {"vodka.martini", ["t6", "t8", "t19"]}, - {"b.b.c", ["t6", "t10", "t13", "t18"]}, - {"nothing.here.at.all", ["t6"]}, - {"un_der_sc.ore", ["t6", "t8"]}]), + [{"a.b.c", ["t2", "t6", "t10", "t12", "t18", "t20", "t22", "t23", + "t24"]}, + {"a.b", ["t3", "t6", "t7", "t8", "t9", "t12", "t15", "t22", "t23", + "t24"]}, + {"a.b.b", ["t3", "t6", "t7", "t12", "t14", "t18", "t22", "t23", + "t24"]}, + {"", ["t6", "t17", "t24"]}, + {"b.c.c", ["t6", "t18", "t22", "t23", "t24"]}, + {"a.a.a.a.a", ["t6", "t12", "t22", "t23", "t24"]}, + {"vodka.gin", ["t6", "t8", "t22", "t23", "t24"]}, + {"vodka.martini", ["t6", "t8", "t19", "t22", "t23", "t24"]}, + {"b.b.c", ["t6", "t10", "t13", "t18", "t22", "t23", "t24"]}, + {"nothing.here.at.all", ["t6", "t22", "t23", "t24"]}, + {"oneword", ["t6", "t22", "t23", "t24", "t25"]}]), %% remove the entire exchange rabbit_exchange_type_topic:delete(X, RemainingBindings), @@ -677,6 +677,21 @@ test_topic_matching() -> test_topic_expect_match(X, [{"a.b.c", []}, {"b.b.c", []}, {"", []}]), passed. +test_topic_expect_match(#exchange{name = XName}, List) -> + lists:foreach( + fun({Key, Expected}) -> + io:format("~p ~p~n", [Key, Expected]), + Res = rabbit_exchange_type_topic:which_matches( + XName, list_to_binary(Key)), + io:format("Res: ~p~n", [Res]), + ExpectedRes = lists:map( + fun(Q) -> #resource{virtual_host = <<"/">>, + kind = queue, + name = list_to_binary(Q)} + end, Expected), + true = (lists:usort(ExpectedRes) =:= lists:usort(Res)) + end, List). + test_app_management() -> %% starting, stopping, status ok = control_action(stop_app, []), |
