|
| 1 | +%% This Source Code Form is subject to the terms of the Mozilla Public |
| 2 | +%% License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 | +%% file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 | +%% |
| 5 | +%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved. |
| 6 | + |
| 7 | +-module(classic_queue_SUITE). |
| 8 | + |
| 9 | +-include_lib("eunit/include/eunit.hrl"). |
| 10 | +-include_lib("amqp_client/include/amqp_client.hrl"). |
| 11 | + |
| 12 | +-compile([nowarn_export_all, export_all]). |
| 13 | + |
| 14 | + |
| 15 | +all() -> |
| 16 | + [ |
| 17 | + {group, cluster_size_3} |
| 18 | + ]. |
| 19 | + |
| 20 | +groups() -> |
| 21 | + [ |
| 22 | + {cluster_size_3, [], [ |
| 23 | + leader_locator_client_local, |
| 24 | + leader_locator_balanced, |
| 25 | + locator_deprecated |
| 26 | + ] |
| 27 | + }]. |
| 28 | + |
| 29 | +%% ------------------------------------------------------------------- |
| 30 | +%% Testsuite setup/teardown. |
| 31 | +%% ------------------------------------------------------------------- |
| 32 | + |
| 33 | +init_per_suite(Config) -> |
| 34 | + rabbit_ct_helpers:log_environment(), |
| 35 | + rabbit_ct_helpers:run_setup_steps(Config, []). |
| 36 | + |
| 37 | +end_per_suite(Config) -> |
| 38 | + rabbit_ct_helpers:run_teardown_steps(Config). |
| 39 | + |
| 40 | +init_per_group(Group, Config) -> |
| 41 | + Config1 = rabbit_ct_helpers:set_config(Config, |
| 42 | + [ |
| 43 | + {rmq_nodename_suffix, Group}, |
| 44 | + {rmq_nodes_count, 3}, |
| 45 | + {rmq_nodes_clustered, true}, |
| 46 | + {tcp_ports_base, {skip_n_nodes, 3}} |
| 47 | + ]), |
| 48 | + Config2 = rabbit_ct_helpers:run_steps( |
| 49 | + Config1, |
| 50 | + rabbit_ct_broker_helpers:setup_steps() ++ |
| 51 | + rabbit_ct_client_helpers:setup_steps()), |
| 52 | + Config2. |
| 53 | + |
| 54 | +end_per_group(_, Config) -> |
| 55 | + rabbit_ct_helpers:run_steps(Config, |
| 56 | + rabbit_ct_client_helpers:teardown_steps() ++ |
| 57 | + rabbit_ct_broker_helpers:teardown_steps()). |
| 58 | + |
| 59 | +%% ------------------------------------------------------------------- |
| 60 | +%% Testcases. |
| 61 | +%% ------------------------------------------------------------------- |
| 62 | + |
| 63 | +leader_locator_client_local(Config) -> |
| 64 | + case rabbit_ct_helpers:is_mixed_versions() of |
| 65 | + true -> |
| 66 | + {skip, "x-queue-leader-locator is only supported by CQs in 4.0+"}; |
| 67 | + false -> |
| 68 | + |
| 69 | + Servers = rabbit_ct_broker_helpers:get_node_configs(Config, nodename), |
| 70 | + Q = <<"q1">>, |
| 71 | + |
| 72 | + [begin |
| 73 | + Ch = rabbit_ct_client_helpers:open_channel(Config, Server), |
| 74 | + ?assertEqual({'queue.declare_ok', Q, 0, 0}, |
| 75 | + declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"classic">>}, |
| 76 | + {<<"x-queue-leader-locator">>, longstr, <<"client-local">>}])), |
| 77 | + {ok, Leader0} = rabbit_ct_broker_helpers:rpc(Config, Server, rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]), |
| 78 | + Leader = amqqueue:qnode(Leader0), |
| 79 | + ?assertEqual(Server, Leader), |
| 80 | + ?assertMatch(#'queue.delete_ok'{}, |
| 81 | + amqp_channel:call(Ch, #'queue.delete'{queue = Q})) |
| 82 | + end || Server <- Servers] end. |
| 83 | + |
| 84 | +leader_locator_balanced(Config) -> |
| 85 | + case rabbit_ct_helpers:is_mixed_versions() of |
| 86 | + true -> |
| 87 | + {skip, "x-queue-leader-locator is only supported by CQs in 4.0+"}; |
| 88 | + false -> |
| 89 | + test_leader_locator(Config, <<"x-queue-leader-locator">>, [<<"balanced">>]) |
| 90 | + end. |
| 91 | + |
| 92 | +%% This test can be delted once we remove x-queue-master-locator support |
| 93 | +locator_deprecated(Config) -> |
| 94 | + test_leader_locator(Config, <<"x-queue-master-locator">>, [<<"least-leaders">>, |
| 95 | + <<"random">>, |
| 96 | + <<"min-masters">>]). |
| 97 | + |
| 98 | +test_leader_locator(Config, Argument, Strategies) -> |
| 99 | + Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename), |
| 100 | + Ch = rabbit_ct_client_helpers:open_channel(Config, Server), |
| 101 | + Qs = [<<"q1">>, <<"q2">>, <<"q3">>], |
| 102 | + |
| 103 | + [begin |
| 104 | + Leaders = [begin |
| 105 | + ?assertMatch({'queue.declare_ok', Q, 0, 0}, |
| 106 | + declare(Ch, Q, |
| 107 | + [{<<"x-queue-type">>, longstr, <<"classic">>}, |
| 108 | + {Argument, longstr, Strategy}])), |
| 109 | + |
| 110 | + {ok, Leader0} = rabbit_ct_broker_helpers:rpc(Config, Server, rabbit_amqqueue, lookup, [rabbit_misc:r(<<"/">>, queue, Q)]), |
| 111 | + Leader = amqqueue:qnode(Leader0), |
| 112 | + Leader |
| 113 | + end || Q <- Qs], |
| 114 | + ?assertEqual(3, sets:size(sets:from_list(Leaders))), |
| 115 | + |
| 116 | + [?assertMatch(#'queue.delete_ok'{}, |
| 117 | + amqp_channel:call(Ch, #'queue.delete'{queue = Q})) |
| 118 | + || Q <- Qs] |
| 119 | + end || Strategy <- Strategies ]. |
| 120 | + |
| 121 | +declare(Ch, Q) -> |
| 122 | + declare(Ch, Q, []). |
| 123 | + |
| 124 | +declare(Ch, Q, Args) -> |
| 125 | + amqp_channel:call(Ch, #'queue.declare'{queue = Q, |
| 126 | + durable = true, |
| 127 | + auto_delete = false, |
| 128 | + arguments = Args}). |
| 129 | + |
| 130 | +delete_queues() -> |
| 131 | + [rabbit_amqqueue:delete(Q, false, false, <<"dummy">>) |
| 132 | + || Q <- rabbit_amqqueue:list()]. |
| 133 | + |
0 commit comments