summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorkjnilsson <knilsson@pivotal.io>2019-02-19 09:29:38 +0000
committerkjnilsson <knilsson@pivotal.io>2019-02-19 09:29:38 +0000
commited13f5398197f5ff735c2c1b97519ecc0d22dd6f (patch)
tree31c89e8f707334fd49bc8ffc75148f8fc860d6c9 /test
parent8e6701b310679eb1b05e4a80ab42e6e1b1af0768 (diff)
downloadrabbitmq-server-git-ed13f5398197f5ff735c2c1b97519ecc0d22dd6f.tar.gz
Add cluster size to shrink result
Also add rabbitmq-queue integration test for shrink command. [#162782789]
Diffstat (limited to 'test')
-rw-r--r--test/quorum_queue_SUITE.erl8
-rw-r--r--test/rabbitmq_queues_cli_SUITE.erl156
2 files changed, 160 insertions, 4 deletions
diff --git a/test/quorum_queue_SUITE.erl b/test/quorum_queue_SUITE.erl
index 430dfb229b..320970a90f 100644
--- a/test/quorum_queue_SUITE.erl
+++ b/test/quorum_queue_SUITE.erl
@@ -643,14 +643,14 @@ shrink_all(Config) ->
timer:sleep(500),
Result = rpc:call(Server0, rabbit_quorum_queue, shrink_all, [Server2]),
ct:pal("shring all result ~p", [Result]),
- ?assertMatch([{_, ok}, {_, ok}], Result),
+ ?assertMatch([{_, {ok, 2}}, {_, {ok, 2}}], Result),
Result1 = rpc:call(Server0, rabbit_quorum_queue, shrink_all, [Server1]),
ct:pal("shring all result ~p", [Result1]),
- ?assertMatch([{_, ok}, {_, ok}], Result1),
+ ?assertMatch([{_, {ok, 1}}, {_, {ok, 1}}], Result1),
Result2 = rpc:call(Server0, rabbit_quorum_queue, shrink_all, [Server0]),
ct:pal("shring all result ~p", [Result2]),
- ?assertMatch([{_, {error, last_node}},
- {_, {error, last_node}}], Result2),
+ ?assertMatch([{_, {error, 1, last_node}},
+ {_, {error, 1, last_node}}], Result2),
ok.
diff --git a/test/rabbitmq_queues_cli_SUITE.erl b/test/rabbitmq_queues_cli_SUITE.erl
new file mode 100644
index 0000000000..e7ec2cab4f
--- /dev/null
+++ b/test/rabbitmq_queues_cli_SUITE.erl
@@ -0,0 +1,156 @@
+%% The contents of this file are subject to the Mozilla Public License
+%% Version 1.1 (the "License"); you may not use this file except in
+%% compliance with the License. You may obtain a copy of the License
+%% at http://www.mozilla.org/MPL/
+%%
+%% Software distributed under the License is distributed on an "AS IS"
+%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
+%% the License for the specific language governing rights and
+%% limitations under the License.
+%%
+%% The Original Code is RabbitMQ.
+%%
+%% The Initial Developer of the Original Code is GoPivotal, Inc.
+%% Copyright (c) 2017-2019 Pivotal Software, Inc. All rights reserved.
+%%
+-module(rabbitmq_queues_cli_SUITE).
+
+-include_lib("common_test/include/ct.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("amqp_client/include/amqp_client.hrl").
+
+-compile(export_all).
+
+all() ->
+ [
+ {group, tests}
+ ].
+
+groups() ->
+ [
+ {tests, [], [
+ shrink
+ ]}
+ ].
+
+init_per_suite(Config) ->
+ rabbit_ct_helpers:log_environment(),
+ rabbit_ct_helpers:run_setup_steps(Config).
+
+end_per_suite(Config) ->
+ rabbit_ct_helpers:run_teardown_steps(Config).
+
+init_per_group(tests, Config0) ->
+ NumNodes = 3,
+ Config1 = rabbit_ct_helpers:set_config(
+ Config0, [{rmq_nodes_count, NumNodes},
+ {rmq_nodes_clustered, true}]),
+ rabbit_ct_helpers:run_steps(Config1,
+ rabbit_ct_broker_helpers:setup_steps() ++
+ rabbit_ct_client_helpers:setup_steps()
+ ).
+
+end_per_group(tests, Config) ->
+ rabbit_ct_helpers:run_steps(Config,
+ rabbit_ct_client_helpers:teardown_steps() ++
+ rabbit_ct_broker_helpers:teardown_steps()).
+
+init_per_testcase(Testcase, Config0) ->
+ ensure_rabbitmq_queues_cmd(
+ rabbit_ct_helpers:testcase_started(Config0, Testcase)).
+
+end_per_testcase(Testcase, Config0) ->
+ rabbit_ct_helpers:testcase_finished(Config0, Testcase).
+
+shrink(Config) ->
+ NodeConfig = rabbit_ct_broker_helpers:get_node_config(Config, 2),
+ Nodename2 = ?config(nodename, NodeConfig),
+ Ch = rabbit_ct_client_helpers:open_channel(Config, Nodename2),
+ %% declare a quorum queue
+ QName = "shrink1",
+ #'queue.declare_ok'{} = declare_qq(Ch, QName),
+ {ok, Out1} = rabbitmq_queues(Config, 0, ["shrink", Nodename2]),
+ ?assertMatch(#{{"/", "shrink1"} := {2, ok}}, parse_result(Out1)),
+ Nodename1 = rabbit_ct_broker_helpers:get_node_config(Config, 1, nodename),
+ {ok, Out2} = rabbitmq_queues(Config, 0, ["shrink", Nodename1]),
+ ?assertMatch(#{{"/", "shrink1"} := {1, ok}}, parse_result(Out2)),
+ Nodename0 = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
+ {ok, Out3} = rabbitmq_queues(Config, 0, ["shrink", Nodename0]),
+ ?assertMatch(#{{"/", "shrink1"} := {1, error}}, parse_result(Out3)),
+ ok.
+
+parse_result(S) ->
+ %% strip preamble and header
+ [_, _ |Lines] = string:split(S, "\n", all),
+ maps:from_list(
+ [{{Vhost, QName},
+ {erlang:list_to_integer(Size), case Result of
+ "ok" -> ok;
+ _ -> error
+ end}}
+ || [Vhost, QName, Size, Result] <-
+ [string:split(L, "\t", all) || L <- Lines]]).
+
+declare_qq(Ch, Q) ->
+ Args = [{<<"x-queue-type">>, longstr, <<"quorum">>}],
+ amqp_channel:call(Ch, #'queue.declare'{queue = list_to_binary(Q),
+ durable = true,
+ auto_delete = false,
+ arguments = Args}).
+ensure_rabbitmq_queues_cmd(Config) ->
+ RabbitmqQueues = case rabbit_ct_helpers:get_config(Config, rabbitmq_queues_cmd) of
+ undefined ->
+ SrcDir = ?config(rabbit_srcdir, Config),
+ R = filename:join(SrcDir, "scripts/rabbitmq-queues"),
+ ct:pal(?LOW_IMPORTANCE, "Using rabbitmq-queues at ~p~n", [R]),
+ case filelib:is_file(R) of
+ true -> R;
+ false -> false
+ end;
+ R ->
+ ct:pal(?LOW_IMPORTANCE,
+ "Using rabbitmq-queues from rabbitmq_queues_cmd: ~p~n", [R]),
+ R
+ end,
+ Error = {skip, "rabbitmq-queues required, " ++
+ "please set 'rabbitmqctl_cmd' in ct config"},
+ case RabbitmqQueues of
+ false ->
+ Error;
+ _ ->
+ Cmd = [RabbitmqQueues],
+ case rabbit_ct_helpers:exec(Cmd, [drop_stdout]) of
+ {error, 64, _} ->
+ rabbit_ct_helpers:set_config(Config,
+ {rabbitmq_queues_cmd,
+ RabbitmqQueues});
+ {error, Code, Reason} ->
+ ct:pal(?LOW_IMPORTANCE, "Exec failed with exit code ~d: ~p", [Code, Reason]),
+ Error;
+ _ ->
+ Error
+ end
+ end.
+
+rabbitmq_queues(Config, Node, Args) ->
+ RabbitmqQueues = ?config(rabbitmq_queues_cmd, Config),
+ NodeConfig = rabbit_ct_broker_helpers:get_node_config(Config, Node),
+ Nodename = ?config(nodename, NodeConfig),
+ Env0 = [
+ {"RABBITMQ_PID_FILE", ?config(pid_file, NodeConfig)},
+ {"RABBITMQ_MNESIA_DIR", ?config(mnesia_dir, NodeConfig)},
+ {"RABBITMQ_PLUGINS_DIR", ?config(plugins_dir, NodeConfig)},
+ {"RABBITMQ_ENABLED_PLUGINS_FILE",
+ ?config(enabled_plugins_file, NodeConfig)}
+ ],
+ Ret = rabbit_ct_helpers:get_config(
+ NodeConfig, enabled_feature_flags_list_file),
+ Env = case Ret of
+ undefined ->
+ Env0;
+ EnabledFeatureFlagsFile ->
+ Env0 ++
+ [{"RABBITMQ_FEATURE_FLAGS_FILE", EnabledFeatureFlagsFile}]
+ end,
+ Cmd = [RabbitmqQueues, "-n", Nodename | Args],
+ rabbit_ct_helpers:exec(Cmd, [{env, Env}]).