Skip to content

Commit ae1156d

Browse files
committed
Add tests for QQ grow to target quorum cluster size command
1 parent c0c80fc commit ae1156d

File tree

2 files changed

+100
-3
lines changed

2 files changed

+100
-3
lines changed

deps/rabbit/test/quorum_queue_SUITE.erl

Lines changed: 73 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ groups() ->
115115
node_removal_is_not_quorum_critical,
116116
select_nodes_with_least_replicas,
117117
select_nodes_with_least_replicas_node_down,
118-
subscribe_from_each
118+
subscribe_from_each,
119+
grow_queue
119120

120121

121122
]},
@@ -1790,6 +1791,77 @@ dont_leak_file_handles(Config) ->
17901791
rabbit_ct_client_helpers:close_channel(C),
17911792
ok.
17921793

1794+
grow_queue(Config) ->
1795+
[Server0, Server1, _Server2, _Server3, _Server4] =
1796+
rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
1797+
1798+
Ch = rabbit_ct_client_helpers:open_channel(Config, Server0),
1799+
QQ = ?config(queue_name, Config),
1800+
AQ = ?config(alt_queue_name, Config),
1801+
?assertEqual({'queue.declare_ok', QQ, 0, 0},
1802+
declare(Ch, QQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
1803+
{<<"x-quorum-initial-group-size">>, long, 5}])),
1804+
?assertEqual({'queue.declare_ok', AQ, 0, 0},
1805+
declare(Ch, AQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
1806+
{<<"x-quorum-initial-group-size">>, long, 5}])),
1807+
1808+
QQs = [QQ, AQ],
1809+
MsgCount = 3,
1810+
1811+
[begin
1812+
RaName = ra_name(Q),
1813+
rabbit_ct_client_helpers:publish(Ch, Q, MsgCount),
1814+
wait_for_messages_ready([Server0], RaName, MsgCount),
1815+
{ok, Q0} = rpc:call(Server0, rabbit_amqqueue, lookup, [Q, <<"/">>]),
1816+
#{nodes := Nodes0} = amqqueue:get_type_state(Q0),
1817+
?assertEqual(5, length(Nodes0))
1818+
end || Q <- QQs],
1819+
1820+
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue,
1821+
force_all_queues_shrink_member_to_current_member, []),
1822+
1823+
TargetClusterSize_1 = 1,
1824+
assert_grown_queues(QQs, Server0, TargetClusterSize_1, MsgCount),
1825+
1826+
%% grow queues to node 'Server1'
1827+
TargetClusterSize_2 = 2,
1828+
rpc:call(Server0, rabbit_quorum_queue, grow, [Server1, <<"/">>, <<".*">>, all]),
1829+
assert_grown_queues(QQs, Server0, TargetClusterSize_2, MsgCount),
1830+
1831+
%% grow queues to quorum cluster size '2' has no effect
1832+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_2, <<"/">>, <<".*">>, all]),
1833+
assert_grown_queues(QQs, Server0, TargetClusterSize_2, MsgCount),
1834+
1835+
%% grow queues to quorum cluster size '3'
1836+
TargetClusterSize_3 = 3,
1837+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_3, <<"/">>, <<".*">>, all]),
1838+
assert_grown_queues(QQs, Server0, TargetClusterSize_3, MsgCount),
1839+
1840+
%% grow queues to quorum cluster size '5'
1841+
TargetClusterSize_5 = 5,
1842+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_5, <<"/">>, <<".*">>, all]),
1843+
assert_grown_queues(QQs, Server0, TargetClusterSize_5, MsgCount),
1844+
1845+
%% shrink all queues again
1846+
rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_quorum_queue,
1847+
force_all_queues_shrink_member_to_current_member, []),
1848+
1849+
assert_grown_queues(QQs, Server0, TargetClusterSize_1, MsgCount),
1850+
1851+
%% grow queues to quorum cluster size > '5' (limit = 5).
1852+
TargetClusterSize_10 = 10,
1853+
rpc:call(Server0, rabbit_quorum_queue, grow, [TargetClusterSize_10, <<"/">>, <<".*">>, all]),
1854+
assert_grown_queues(QQs, Server0, TargetClusterSize_5, MsgCount).
1855+
1856+
assert_grown_queues(Qs, Node, TargetClusterSize, MsgCount) ->
1857+
[begin
1858+
RaName = ra_name(Q),
1859+
wait_for_messages_ready([Node], RaName, MsgCount),
1860+
{ok, Q0} = rpc:call(Node, rabbit_amqqueue, lookup, [Q, <<"/">>]),
1861+
#{nodes := Nodes0} = amqqueue:get_type_state(Q0),
1862+
?assertEqual(TargetClusterSize, length(Nodes0))
1863+
end || Q <- Qs].
1864+
17931865
gh_12635(Config) ->
17941866
check_quorum_queues_v4_compat(Config),
17951867

deps/rabbitmq_cli/test/queues/grow_command_test.exs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,37 @@ defmodule RabbitMQ.CLI.Queues.Commands.GrowCommandTest do
8282
{:validation_failure, "voter status 'banana' is not recognised."}
8383
end
8484

85+
test "validate: when target quorum cluster size greater than zero, returns a success" do
86+
assert @command.validate([7, "all"], %{membership: "voter"}) == :ok
87+
end
88+
89+
test "validate: when target quorum cluster size is zero, returns failure" do
90+
assert @command.validate([0, "all"], %{membership: "voter"}) ==
91+
{:validation_failure, "target quorum cluster size '0' must be greater than 0."}
92+
end
93+
94+
test "validate: when target quorum cluster size is less than zero, returns failure" do
95+
assert @command.validate([-1, "all"], %{membership: "voter"}) ==
96+
{:validation_failure, "target quorum cluster size '-1' must be greater than 0."}
97+
end
98+
99+
@tag test_timeout: 3000
100+
test "run: targeting an unreachable node throws a badrpc when growing to a target node", context do
101+
assert match?(
102+
{:badrpc, _},
103+
@command.run(
104+
["target@node", "all"],
105+
Map.merge(context[:opts], %{node: :jake@thedog})
106+
)
107+
)
108+
end
109+
85110
@tag test_timeout: 3000
86-
test "run: targeting an unreachable node throws a badrpc", context do
111+
test "run: targeting an unreachable node throws a badrpc when growing to a target quorum cluster size", context do
87112
assert match?(
88113
{:badrpc, _},
89114
@command.run(
90-
["quorum-queue-a", "all"],
115+
[5, "all"],
91116
Map.merge(context[:opts], %{node: :jake@thedog})
92117
)
93118
)

0 commit comments

Comments
 (0)