Skip to content

Commit 9743422

Browse files
Merge pull request #2320 from rabbitmq/rabbitmq-cli-408
Introduce rabbit_upgrade_preparation
2 parents f057013 + 8df8191 commit 9743422

File tree

2 files changed

+174
-0
lines changed

2 files changed

+174
-0
lines changed

src/rabbit_upgrade_preparation.erl

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at https://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2007-2020 VMware, Inc. or its affiliates. All rights reserved.
15+
%%
16+
17+
-module(rabbit_upgrade_preparation).
18+
19+
-export([await_online_quorum_plus_one/1, await_online_synchronised_mirrors/1]).
20+
21+
%%
22+
%% API
23+
%%
24+
25+
-define(SAMPLING_INTERVAL, 200).
26+
27+
await_online_quorum_plus_one(Timeout) ->
28+
Iterations = ceil(Timeout / ?SAMPLING_INTERVAL),
29+
do_await_safe_online_quorum(Iterations).
30+
31+
32+
await_online_synchronised_mirrors(Timeout) ->
33+
Iterations = ceil(Timeout / ?SAMPLING_INTERVAL),
34+
do_await_online_synchronised_mirrors(Iterations).
35+
36+
37+
%%
38+
%% Implementation
39+
%%
40+
41+
do_await_safe_online_quorum(0) ->
42+
false;
43+
do_await_safe_online_quorum(IterationsLeft) ->
44+
case rabbit_quorum_queue:list_with_minimum_quorum() of
45+
[] -> true;
46+
List when is_list(List) ->
47+
timer:sleep(?SAMPLING_INTERVAL),
48+
do_await_safe_online_quorum(IterationsLeft - 1)
49+
end.
50+
51+
52+
do_await_online_synchronised_mirrors(0) ->
53+
false;
54+
do_await_online_synchronised_mirrors(IterationsLeft) ->
55+
case rabbit_amqqueue:list_local_mirrored_classic_without_synchronised_mirrors() of
56+
[] -> true;
57+
List when is_list(List) ->
58+
timer:sleep(?SAMPLING_INTERVAL),
59+
do_await_online_synchronised_mirrors(IterationsLeft - 1)
60+
end.

test/upgrade_preparation_SUITE.erl

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
%% The contents of this file are subject to the Mozilla Public License
2+
%% Version 1.1 (the "License"); you may not use this file except in
3+
%% compliance with the License. You may obtain a copy of the License
4+
%% at https://www.mozilla.org/MPL/
5+
%%
6+
%% Software distributed under the License is distributed on an "AS IS"
7+
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
8+
%% the License for the specific language governing rights and
9+
%% limitations under the License.
10+
%%
11+
%% The Original Code is RabbitMQ.
12+
%%
13+
%% The Initial Developer of the Original Code is GoPivotal, Inc.
14+
%% Copyright (c) 2020 VMware, Inc. or its affiliates. All rights reserved.
15+
%%
16+
17+
-module(upgrade_preparation_SUITE).
18+
19+
-include_lib("common_test/include/ct.hrl").
20+
-include_lib("eunit/include/eunit.hrl").
21+
-include_lib("amqp_client/include/amqp_client.hrl").
22+
23+
-compile(export_all).
24+
25+
all() ->
26+
[
27+
{group, clustered}
28+
].
29+
30+
groups() ->
31+
[
32+
{clustered, [], [
33+
await_quorum_plus_one
34+
]}
35+
].
36+
37+
38+
%% -------------------------------------------------------------------
39+
%% Test Case
40+
%% -------------------------------------------------------------------
41+
42+
init_per_suite(Config) ->
43+
rabbit_ct_helpers:log_environment(),
44+
rabbit_ct_helpers:run_setup_steps(Config).
45+
46+
end_per_suite(Config) ->
47+
rabbit_ct_helpers:run_teardown_steps(Config).
48+
49+
init_per_group(Group, Config) ->
50+
Config1 = rabbit_ct_helpers:set_config(Config, [
51+
{rmq_nodes_count, 3},
52+
{rmq_nodename_suffix, Group}
53+
]),
54+
rabbit_ct_helpers:run_steps(Config1,
55+
rabbit_ct_broker_helpers:setup_steps() ++
56+
rabbit_ct_client_helpers:setup_steps()).
57+
58+
end_per_group(_Group, Config) ->
59+
rabbit_ct_helpers:run_steps(Config,
60+
rabbit_ct_client_helpers:teardown_steps() ++
61+
rabbit_ct_broker_helpers:teardown_steps()).
62+
63+
64+
init_per_testcase(TestCase, Config) ->
65+
rabbit_ct_helpers:testcase_started(Config, TestCase).
66+
67+
end_per_testcase(TestCase, Config) ->
68+
rabbit_ct_helpers:testcase_finished(Config, TestCase).
69+
70+
71+
72+
%%
73+
%% Test Cases
74+
%%
75+
76+
-define(WAITING_INTERVAL, 10000).
77+
78+
await_quorum_plus_one(Config) ->
79+
catch delete_queues(),
80+
[A, B, _C] = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
81+
Ch = rabbit_ct_client_helpers:open_channel(Config, A),
82+
declare(Ch, <<"qq.1">>, [{<<"x-queue-type">>, longstr, <<"quorum">>}]),
83+
timer:sleep(100),
84+
?assert(await_quorum_plus_one(Config, 0)),
85+
86+
ok = rabbit_ct_broker_helpers:stop_node(Config, B),
87+
?assertNot(await_quorum_plus_one(Config, 0)),
88+
89+
ok = rabbit_ct_broker_helpers:start_node(Config, B),
90+
?assert(await_quorum_plus_one(Config, 0)).
91+
92+
%%
93+
%% Implementation
94+
%%
95+
96+
declare(Ch, Q) ->
97+
declare(Ch, Q, []).
98+
99+
declare(Ch, Q, Args) ->
100+
amqp_channel:call(Ch, #'queue.declare'{queue = Q,
101+
durable = true,
102+
auto_delete = false,
103+
arguments = Args}).
104+
105+
delete_queues() ->
106+
[rabbit_amqqueue:delete(Q, false, false, <<"tests">>) || Q <- rabbit_amqqueue:list()].
107+
108+
await_quorum_plus_one(Config, Node) ->
109+
await_quorum_plus_one(Config, Node, ?WAITING_INTERVAL).
110+
111+
await_quorum_plus_one(Config, Node, Timeout) ->
112+
rabbit_ct_broker_helpers:rpc(Config, Node,
113+
rabbit_upgrade_preparation, await_online_quorum_plus_one, [Timeout], Timeout + 500).
114+

0 commit comments

Comments
 (0)