@@ -52,7 +52,8 @@ all() ->
52
52
{group , definitions_group1_without_prefix },
53
53
{group , definitions_group2_without_prefix },
54
54
{group , definitions_group3_without_prefix },
55
- {group , definitions_group4_without_prefix }
55
+ {group , definitions_group4_without_prefix },
56
+ {group , default_queue_type_without_prefix }
56
57
].
57
58
58
59
groups () ->
@@ -66,7 +67,8 @@ groups() ->
66
67
{definitions_group1_without_prefix , [], definitions_group1_tests ()},
67
68
{definitions_group2_without_prefix , [], definitions_group2_tests ()},
68
69
{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 ()}
70
72
].
71
73
72
74
some_tests () ->
@@ -104,6 +106,14 @@ definitions_group4_tests() ->
104
106
definitions_vhost_test
105
107
].
106
108
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
+
107
117
all_tests () -> [
108
118
cli_redirect_test ,
109
119
api_redirect_test ,
@@ -4118,10 +4128,124 @@ cluster_and_node_tags_test(Config) ->
4118
4128
? assertEqual (ExpectedTags , NodeTags ),
4119
4129
passed .
4120
4130
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
+
4121
4235
% % -------------------------------------------------------------------
4122
4236
% % Helpers.
4123
4237
% % -------------------------------------------------------------------
4124
4238
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
+
4125
4249
msg (Key , Headers , Body ) ->
4126
4250
msg (Key , Headers , Body , <<" string" >>).
4127
4251
@@ -4214,3 +4338,13 @@ await_condition(Fun) ->
4214
4338
false
4215
4339
end
4216
4340
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