Skip to content

Commit 090d118

Browse files
HTTP API tests for injected default queue type
1 parent 765f3d7 commit 090d118

File tree

4 files changed

+146
-2
lines changed

4 files changed

+146
-2
lines changed

deps/rabbit/src/rabbit_queue_type.erl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
feature_flag_name/1,
2424
to_binary/1,
2525
default/0,
26+
default_alias/0,
2627
fallback/0,
2728
inject_dqt/1,
2829
vhosts_with_dqt/1,
@@ -357,6 +358,10 @@ default() ->
357358
fallback()),
358359
rabbit_data_coercion:to_atom(V).
359360

361+
-spec default_alias() -> binary().
362+
default_alias() ->
363+
short_alias_of(default()).
364+
360365
-spec to_binary(module()) -> binary().
361366
to_binary(rabbit_classic_queue) ->
362367
<<"classic">>;

deps/rabbitmq_ct_helpers/src/rabbit_ct_broker_helpers.erl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
add_vhost/2,
112112
add_vhost/3,
113113
add_vhost/4,
114+
update_vhost_metadata/3,
114115
delete_vhost/2,
115116
delete_vhost/3,
116117
delete_vhost/4,
@@ -1602,6 +1603,9 @@ add_vhost(Config, Node, VHost) ->
16021603
add_vhost(Config, Node, VHost, Username) ->
16031604
catch rpc(Config, Node, rabbit_vhost, add, [VHost, Username]).
16041605

1606+
update_vhost_metadata(Config, VHost, Meta) ->
1607+
catch rpc(Config, 0, rabbit_vhost, update_metadata, [VHost, Meta, <<"acting-user">>]).
1608+
16051609
delete_vhost(Config, VHost) ->
16061610
delete_vhost(Config, 0, VHost).
16071611

deps/rabbitmq_management/src/rabbit_mgmt_wm_overview.erl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ to_json(ReqData, Context = #context{user = User = #user{tags = Tags}}) ->
5353
{erlang_full_version, erlang_full_version()},
5454
{release_series_support_status, rabbit_release_series:readable_support_status()},
5555
{disable_stats, rabbit_mgmt_util:disable_stats(ReqData)},
56+
{default_queue_type, rabbit_queue_type:default_alias()},
5657
{is_op_policy_updating_enabled, not rabbit_mgmt_features:is_op_policy_updating_disabled()},
5758
{enable_queue_totals, rabbit_mgmt_util:enable_queue_totals(ReqData)}],
5859
try

deps/rabbitmq_management/test/rabbit_mgmt_http_SUITE.erl

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ all() ->
5252
{group, definitions_group1_without_prefix},
5353
{group, definitions_group2_without_prefix},
5454
{group, definitions_group3_without_prefix},
55-
{group, definitions_group4_without_prefix}
55+
{group, definitions_group4_without_prefix},
56+
{group, default_queue_type_without_prefix}
5657
].
5758

5859
groups() ->
@@ -66,7 +67,8 @@ groups() ->
6667
{definitions_group1_without_prefix, [], definitions_group1_tests()},
6768
{definitions_group2_without_prefix, [], definitions_group2_tests()},
6869
{definitions_group3_without_prefix, [], definitions_group3_tests()},
69-
{definitions_group4_without_prefix, [], definitions_group4_tests()}
70+
{definitions_group4_without_prefix, [], definitions_group4_tests()},
71+
{default_queue_type_without_prefix, [], default_queue_type_group_tests()}
7072
].
7173

7274
some_tests() ->
@@ -104,6 +106,14 @@ definitions_group4_tests() ->
104106
definitions_vhost_test
105107
].
106108

109+
default_queue_type_group_tests() ->
110+
[
111+
default_queue_type_fallback_in_overview_test,
112+
default_queue_type_with_value_configured_in_overview_test,
113+
default_queue_types_in_vhost_list_test,
114+
default_queue_type_of_one_vhost_test
115+
].
116+
107117
all_tests() -> [
108118
cli_redirect_test,
109119
api_redirect_test,
@@ -4118,10 +4128,124 @@ cluster_and_node_tags_test(Config) ->
41184128
?assertEqual(ExpectedTags, NodeTags),
41194129
passed.
41204130

4131+
default_queue_type_fallback_in_overview_test(Config) ->
4132+
Overview = http_get(Config, "/overview"),
4133+
DQT = maps:get(default_queue_type, Overview),
4134+
?assertEqual(<<"classic">>, DQT).
4135+
4136+
default_queue_type_with_value_configured_in_overview_test(Config) ->
4137+
Overview = with_default_queue_type(Config, rabbit_quorum_queue,
4138+
fun(Cfg) ->
4139+
http_get(Cfg, "/overview")
4140+
end),
4141+
4142+
DQT = maps:get(default_queue_type, Overview),
4143+
?assertEqual(<<"quorum">>, DQT).
4144+
4145+
default_queue_types_in_vhost_list_test(Config) ->
4146+
TestName = rabbit_data_coercion:to_binary(?FUNCTION_NAME),
4147+
VHost1 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 1])),
4148+
VHost2 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 2])),
4149+
VHost3 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 3])),
4150+
VHost4 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 4])),
4151+
4152+
VHosts = #{
4153+
VHost1 => undefined,
4154+
VHost2 => <<"classic">>,
4155+
VHost3 => <<"quorum">>,
4156+
VHost4 => <<"stream">>
4157+
},
4158+
4159+
try
4160+
begin
4161+
lists:foreach(
4162+
fun({V, QT}) ->
4163+
rabbit_ct_broker_helpers:add_vhost(Config, V),
4164+
rabbit_ct_broker_helpers:set_full_permissions(Config, V),
4165+
rabbit_ct_broker_helpers:update_vhost_metadata(Config, V, #{
4166+
default_queue_type => QT
4167+
})
4168+
end, maps:to_list(VHosts)),
4169+
4170+
List = http_get(Config, "/vhosts"),
4171+
ct:pal("GET /api/vhosts returned: ~tp", [List]),
4172+
VH1 = find_map_by_name(VHost1, List),
4173+
?assertEqual(<<"classic">>, maps:get(default_queue_type, VH1)),
4174+
4175+
VH2 = find_map_by_name(VHost2, List),
4176+
?assertEqual(<<"classic">>, maps:get(default_queue_type, VH2)),
4177+
4178+
VH3 = find_map_by_name(VHost3, List),
4179+
?assertEqual(<<"quorum">>, maps:get(default_queue_type, VH3)),
4180+
4181+
VH4 = find_map_by_name(VHost4, List),
4182+
?assertEqual(<<"stream">>, maps:get(default_queue_type, VH4))
4183+
end
4184+
after
4185+
lists:foreach(
4186+
fun(V) ->
4187+
rabbit_ct_broker_helpers:delete_vhost(Config, V)
4188+
end, maps:keys(VHosts))
4189+
end.
4190+
4191+
default_queue_type_of_one_vhost_test(Config) ->
4192+
TestName = rabbit_data_coercion:to_binary(?FUNCTION_NAME),
4193+
VHost1 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 1])),
4194+
VHost2 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 2])),
4195+
VHost3 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 3])),
4196+
VHost4 = rabbit_data_coercion:to_binary(io_lib:format("~ts-~b", [TestName, 4])),
4197+
4198+
VHosts = #{
4199+
VHost1 => undefined,
4200+
VHost2 => <<"classic">>,
4201+
VHost3 => <<"quorum">>,
4202+
VHost4 => <<"stream">>
4203+
},
4204+
4205+
try
4206+
begin
4207+
lists:foreach(
4208+
fun({V, QT}) ->
4209+
rabbit_ct_broker_helpers:add_vhost(Config, V),
4210+
rabbit_ct_broker_helpers:set_full_permissions(Config, V),
4211+
rabbit_ct_broker_helpers:update_vhost_metadata(Config, V, #{
4212+
default_queue_type => QT
4213+
})
4214+
end, maps:to_list(VHosts)),
4215+
4216+
VH1 = http_get(Config, io_lib:format("/vhosts/~ts", [VHost1])),
4217+
?assertEqual(<<"classic">>, maps:get(default_queue_type, VH1)),
4218+
4219+
VH2 = http_get(Config, io_lib:format("/vhosts/~ts", [VHost2])),
4220+
?assertEqual(<<"classic">>, maps:get(default_queue_type, VH2)),
4221+
4222+
VH3 = http_get(Config, io_lib:format("/vhosts/~ts", [VHost3])),
4223+
?assertEqual(<<"quorum">>, maps:get(default_queue_type, VH3)),
4224+
4225+
VH4 = http_get(Config, io_lib:format("/vhosts/~ts", [VHost4])),
4226+
?assertEqual(<<"stream">>, maps:get(default_queue_type, VH4))
4227+
end
4228+
after
4229+
lists:foreach(
4230+
fun(V) ->
4231+
rabbit_ct_broker_helpers:delete_vhost(Config, V)
4232+
end, maps:keys(VHosts))
4233+
end.
4234+
41214235
%% -------------------------------------------------------------------
41224236
%% Helpers.
41234237
%% -------------------------------------------------------------------
41244238

4239+
%% Finds a map by its <<"name">> key in an HTTP API response.
4240+
-spec find_map_by_name(binary(), [#{binary() => any()}]) -> #{binary() => any()} | undefined.
4241+
find_map_by_name(NameToFind, List) ->
4242+
case lists:filter(fun(#{name := Name}) ->
4243+
Name =:= NameToFind
4244+
end, List) of
4245+
[] -> undefined;
4246+
[Val] -> Val
4247+
end.
4248+
41254249
msg(Key, Headers, Body) ->
41264250
msg(Key, Headers, Body, <<"string">>).
41274251

@@ -4214,3 +4338,13 @@ await_condition(Fun) ->
42144338
false
42154339
end
42164340
end, ?COLLECT_INTERVAL * 100).
4341+
4342+
4343+
clear_default_queue_type(Config) ->
4344+
rpc(Config, application, unset_env, [rabbit, default_queue_type]).
4345+
4346+
with_default_queue_type(Config, DQT, Fun) ->
4347+
rpc(Config, application, set_env, [rabbit, default_queue_type, DQT]),
4348+
ToReturn = Fun(Config),
4349+
rpc(Config, application, unset_env, [rabbit, default_queue_type]),
4350+
ToReturn.

0 commit comments

Comments
 (0)