-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
quorum_queue_SUITE.erl
4632 lines (4003 loc) · 198 KB
/
quorum_queue_SUITE.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%% This Source Code Form is subject to the terms of the Mozilla Public
%% License, v. 2.0. If a copy of the MPL was not distributed with this
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
%%
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
-module(quorum_queue_SUITE).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("amqp_client/include/amqp_client.hrl").
-include_lib("rabbitmq_ct_helpers/include/rabbit_assert.hrl").
-import(queue_utils, [wait_for_messages_ready/3,
wait_for_messages_pending_ack/3,
wait_for_messages_total/3,
wait_for_messages/2,
dirty_query/3,
ra_name/1]).
-import(clustering_utils, [
assert_cluster_status/2,
assert_clustered/1
]).
-compile([nowarn_export_all, export_all]).
-define(NET_TICKTIME_S, 5).
-define(DEFAULT_AWAIT, 10_000).
suite() ->
[{timetrap, 5 * 60_000}].
all() ->
[
{group, single_node},
{group, unclustered},
{group, clustered}
].
groups() ->
[
{single_node, [], all_tests() ++
memory_tests() ++
[node_removal_is_quorum_critical,
format]},
{unclustered, [], [
{uncluster_size_2, [], [add_member]}
]},
{clustered, [], [
{cluster_size_2, [], [add_member_2,
add_member_not_running,
add_member_classic,
add_member_wrong_type,
add_member_already_a_member,
add_member_not_found,
delete_member_not_running,
delete_member_classic,
delete_member_wrong_type,
delete_member_queue_not_found,
delete_member,
delete_member_not_a_member,
delete_member_member_already_deleted,
node_removal_is_quorum_critical]
++ memory_tests()},
{cluster_size_3, [], [
cleanup_data_dir,
channel_handles_ra_event,
declare_during_node_down,
simple_confirm_availability_on_leader_change,
publishing_to_unavailable_queue,
confirm_availability_on_leader_change,
recover_from_single_failure,
recover_from_multiple_failures,
leadership_takeover,
delete_declare,
delete_member_during_node_down,
metrics_cleanup_on_leadership_takeover,
metrics_cleanup_on_leader_crash,
consume_in_minority,
reject_after_leader_transfer,
shrink_all,
rebalance,
node_removal_is_not_quorum_critical,
leader_locator_client_local,
leader_locator_balanced,
leader_locator_balanced_maintenance,
leader_locator_balanced_random_maintenance,
leader_locator_policy,
status,
format,
add_member_2,
single_active_consumer_priority_take_over,
single_active_consumer_priority,
force_shrink_member_to_current_member,
force_all_queues_shrink_member_to_current_member,
force_vhost_queues_shrink_member_to_current_member,
policy_repair,
gh_12635,
replica_states
]
++ all_tests()},
{cluster_size_5, [], [start_queue,
start_queue_concurrent,
quorum_cluster_size_3,
quorum_cluster_size_7,
node_removal_is_not_quorum_critical,
select_nodes_with_least_replicas,
select_nodes_with_least_replicas_node_down
]},
{clustered_with_partitions, [],
[
reconnect_consumer_and_publish,
reconnect_consumer_and_wait,
reconnect_consumer_and_wait_channel_down
]}
]}
].
all_tests() ->
[
declare_args,
declare_invalid_properties,
declare_server_named,
declare_invalid_arg_1,
declare_invalid_arg_2,
declare_invalid_arg_3,
relaxed_argument_equivalence_checks_on_qq_redeclare,
consume_invalid_arg_1,
consume_invalid_arg_2,
start_queue,
long_name,
stop_queue,
restart_queue,
restart_all_types,
stop_start_rabbit_app,
publish_and_restart,
subscribe_should_fail_when_global_qos_true,
dead_letter_to_classic_queue,
dead_letter_with_memory_limit,
dead_letter_to_quorum_queue,
dead_letter_from_classic_to_quorum_queue,
dead_letter_policy,
cleanup_queue_state_on_channel_after_publish,
cleanup_queue_state_on_channel_after_subscribe,
sync_queue,
cancel_sync_queue,
idempotent_recover,
server_system_recover,
vhost_with_quorum_queue_is_deleted,
vhost_with_default_queue_type_declares_quorum_queue,
node_wide_default_queue_type_declares_quorum_queue,
delete_immediately_by_resource,
consume_redelivery_count,
subscribe_redelivery_count,
message_bytes_metrics,
queue_length_limit_drop_head,
queue_length_limit_reject_publish,
queue_length_limit_policy_cleared,
subscribe_redelivery_limit,
subscribe_redelivery_limit_disable,
subscribe_redelivery_limit_many,
subscribe_redelivery_policy,
subscribe_redelivery_limit_with_dead_letter,
purge,
consumer_metrics,
invalid_policy,
pre_existing_invalid_policy,
delete_if_empty,
delete_if_unused,
queue_ttl,
peek,
oldest_entry_timestamp,
peek_with_wrong_queue_type,
message_ttl,
message_ttl_policy,
per_message_ttl,
per_message_ttl_mixed_expiry,
per_message_ttl_expiration_too_high,
consumer_priorities,
cancel_consumer_gh_3729,
cancel_consumer_gh_12424,
cancel_and_consume_with_same_tag,
validate_messages_on_queue,
amqpl_headers,
priority_queue_fifo,
priority_queue_2_1_ratio,
requeue_multiple_true,
requeue_multiple_false
].
memory_tests() ->
[
memory_alarm_rolls_wal,
reclaim_memory_with_wrong_queue_type
].
-define(SUPNAME, ra_server_sup_sup).
%% -------------------------------------------------------------------
%% Testsuite setup/teardown.
%% -------------------------------------------------------------------
init_per_suite(Config0) ->
rabbit_ct_helpers:log_environment(),
Config1 = rabbit_ct_helpers:merge_app_env(
Config0, {rabbit, [{quorum_tick_interval, 256}]}),
rabbit_ct_helpers:run_setup_steps(Config1, []).
end_per_suite(Config) ->
rabbit_ct_helpers:run_teardown_steps(Config).
init_per_group(clustered, Config) ->
rabbit_ct_helpers:set_config(Config, [{rmq_nodes_clustered, true}]);
init_per_group(unclustered, Config) ->
rabbit_ct_helpers:set_config(Config, [{rmq_nodes_clustered, false}]);
init_per_group(clustered_with_partitions, Config0) ->
case rabbit_ct_helpers:is_mixed_versions() of
true ->
{skip, "clustered_with_partitions is too unreliable in mixed mode"};
false ->
Config1 = rabbit_ct_helpers:run_setup_steps(
Config0,
[fun rabbit_ct_broker_helpers:configure_dist_proxy/1]),
Config2 = rabbit_ct_helpers:set_config(Config1,
[{net_ticktime, ?NET_TICKTIME_S}]),
Config2
end;
init_per_group(Group, Config) ->
ClusterSize = case Group of
single_node -> 1;
uncluster_size_2 -> 2;
cluster_size_2 -> 2;
cluster_size_3 -> 3;
cluster_size_5 -> 5
end,
IsMixed = rabbit_ct_helpers:is_mixed_versions(),
case ClusterSize of
2 when IsMixed ->
{skip, "cluster size 2 isn't mixed versions compatible"};
_ ->
Config1 = rabbit_ct_helpers:set_config(Config,
[{rmq_nodes_count, ClusterSize},
{rmq_nodename_suffix, Group},
{tcp_ports_base, {skip_n_nodes, ClusterSize}},
{net_ticktime, ?NET_TICKTIME_S}
]),
Ret = rabbit_ct_helpers:run_steps(Config1,
[fun merge_app_env/1 ] ++
rabbit_ct_broker_helpers:setup_steps()),
case Ret of
{skip, _} ->
Ret;
Config2 ->
Res = rabbit_ct_broker_helpers:enable_feature_flag(
Config2, 'rabbitmq_4.0.0'),
ct:pal("rabbitmq_4.0.0 enable result ~p", [Res]),
ok = rabbit_ct_broker_helpers:rpc(
Config2, 0, application, set_env,
[rabbit, channel_tick_interval, 100]),
Config2
end
end.
end_per_group(clustered, Config) ->
Config;
end_per_group(unclustered, Config) ->
Config;
end_per_group(clustered_with_partitions, Config) ->
Config;
end_per_group(_, Config) ->
rabbit_ct_helpers:run_steps(Config,
rabbit_ct_broker_helpers:teardown_steps()).
init_per_testcase(Testcase, Config) when Testcase == reconnect_consumer_and_publish;
Testcase == reconnect_consumer_and_wait;
Testcase == reconnect_consumer_and_wait_channel_down ->
Config1 = rabbit_ct_helpers:testcase_started(Config, Testcase),
Q = rabbit_data_coercion:to_binary(Testcase),
Config2 = rabbit_ct_helpers:set_config(Config1,
[{rmq_nodes_count, 3},
{rmq_nodename_suffix, Testcase},
{tcp_ports_base, {skip_n_nodes, 3}},
{queue_name, Q},
{alt_queue_name, <<Q/binary, "_alt">>}
]),
rabbit_ct_helpers:run_steps(
Config2,
rabbit_ct_broker_helpers:setup_steps() ++
rabbit_ct_client_helpers:setup_steps());
init_per_testcase(Testcase, Config) ->
ClusterSize = ?config(rmq_nodes_count, Config),
IsMixed = rabbit_ct_helpers:is_mixed_versions(),
case Testcase of
node_removal_is_not_quorum_critical when IsMixed ->
{skip, "node_removal_is_not_quorum_critical isn't mixed versions compatible"};
simple_confirm_availability_on_leader_change when IsMixed ->
{skip, "simple_confirm_availability_on_leader_change isn't mixed versions compatible"};
confirm_availability_on_leader_change when IsMixed ->
{skip, "confirm_availability_on_leader_change isn't mixed versions compatible"};
recover_from_single_failure when IsMixed ->
%% In a 3.8/3.9 cluster this will pass only if the failure occurs on the 3.8 node
{skip, "recover_from_single_failure isn't mixed versions compatible"};
shrink_all when IsMixed ->
%% In a 3.8/3.9 cluster only the first shrink will work as expected
{skip, "skrink_all isn't mixed versions compatible"};
delete_immediately_by_resource when IsMixed andalso ClusterSize == 3 ->
{skip, "delete_immediately_by_resource isn't mixed versions compatible"};
queue_ttl when IsMixed andalso ClusterSize == 3 ->
{skip, "queue_ttl isn't mixed versions compatible"};
start_queue when IsMixed andalso ClusterSize == 5 ->
{skip, "start_queue isn't mixed versions compatible"};
start_queue_concurrent when IsMixed andalso ClusterSize == 5 ->
{skip, "start_queue_concurrent isn't mixed versions compatible"};
leader_locator_client_local when IsMixed ->
{skip, "leader_locator_client_local isn't mixed versions compatible because "
"delete_declare isn't mixed versions reliable"};
leader_locator_balanced_random_maintenance when IsMixed ->
{skip, "leader_locator_balanced_random_maintenance isn't mixed versions compatible because "
"delete_declare isn't mixed versions reliable"};
reclaim_memory_with_wrong_queue_type when IsMixed ->
{skip, "reclaim_memory_with_wrong_queue_type isn't mixed versions compatible"};
peek_with_wrong_queue_type when IsMixed ->
{skip, "peek_with_wrong_queue_type isn't mixed versions compatible"};
_ ->
Config1 = rabbit_ct_helpers:testcase_started(Config, Testcase),
rabbit_ct_broker_helpers:rpc(Config, 0, ?MODULE, delete_queues, []),
Q = rabbit_data_coercion:to_binary(Testcase),
Config2 = rabbit_ct_helpers:set_config(Config1,
[{queue_name, Q},
{alt_queue_name, <<Q/binary, "_alt">>},
{alt_2_queue_name, <<Q/binary, "_alt_2">>}
]),
rabbit_ct_helpers:run_steps(Config2, rabbit_ct_client_helpers:setup_steps())
end.
merge_app_env(Config) ->
rabbit_ct_helpers:merge_app_env(
rabbit_ct_helpers:merge_app_env(Config,
{rabbit, [{core_metrics_gc_interval, 100}]}),
{ra, [{min_wal_roll_over_interval, 30000}]}).
end_per_testcase(Testcase, Config) when Testcase == reconnect_consumer_and_publish;
Testcase == reconnect_consumer_and_wait;
Testcase == reconnect_consumer_and_wait_channel_down ->
Config1 = rabbit_ct_helpers:run_steps(Config,
rabbit_ct_client_helpers:teardown_steps() ++
rabbit_ct_broker_helpers:teardown_steps()),
rabbit_ct_helpers:testcase_finished(Config1, Testcase);
end_per_testcase(Testcase, Config) ->
% catch delete_queues(),
Config1 = rabbit_ct_helpers:run_steps(
Config,
rabbit_ct_client_helpers:teardown_steps()),
rabbit_ct_helpers:testcase_finished(Config1, Testcase).
%% -------------------------------------------------------------------
%% Testcases.
%% -------------------------------------------------------------------
declare_args(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
{<<"x-max-length">>, long, 2000},
{<<"x-max-length-bytes">>, long, 2000}]),
assert_queue_type(Server, LQ, rabbit_quorum_queue),
DQ = <<"classic-declare-args-q">>,
declare(Ch, DQ, [{<<"x-queue-type">>, longstr, <<"classic">>}]),
assert_queue_type(Server, DQ, rabbit_classic_queue),
DQ2 = <<"classic-q2">>,
declare(Ch, DQ2),
assert_queue_type(Server, DQ2, rabbit_classic_queue).
declare_invalid_properties(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
LQ = ?config(queue_name, Config),
?assertExit(
{{shutdown, {server_initiated_close, 406, _}}, _},
amqp_channel:call(
rabbit_ct_client_helpers:open_channel(Config, Server),
#'queue.declare'{queue = LQ,
auto_delete = true,
durable = true,
arguments = [{<<"x-queue-type">>, longstr, <<"quorum">>}]})),
?assertExit(
{{shutdown, {server_initiated_close, 406, _}}, _},
amqp_channel:call(
rabbit_ct_client_helpers:open_channel(Config, Server),
#'queue.declare'{queue = LQ,
exclusive = true,
durable = true,
arguments = [{<<"x-queue-type">>, longstr, <<"quorum">>}]})),
?assertExit(
{{shutdown, {server_initiated_close, 406, _}}, _},
amqp_channel:call(
rabbit_ct_client_helpers:open_channel(Config, Server),
#'queue.declare'{queue = LQ,
durable = false,
arguments = [{<<"x-queue-type">>, longstr, <<"quorum">>}]})).
declare_server_named(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
?assertExit(
{{shutdown, {server_initiated_close, 406, _}}, _},
declare(rabbit_ct_client_helpers:open_channel(Config, Server),
<<"">>, [{<<"x-queue-type">>, longstr, <<"quorum">>}])).
declare_invalid_arg_1(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
Q = ?config(queue_name, Config),
ExpectedError = <<"PRECONDITION_FAILED - invalid arg 'x-queue-mode' for queue "
"'declare_invalid_arg_1' in vhost '/' of queue type rabbit_quorum_queue">>,
?assertExit(
{{shutdown, {server_initiated_close, 406, ExpectedError}}, _},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>},
%% only available in classic queues
{<<"x-queue-mode">>, longstr, <<"default">>}])).
declare_invalid_arg_2(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
Q = ?config(queue_name, Config),
ExpectedError = <<"PRECONDITION_FAILED - invalid arg 'x-queue-type' for queue 'declare_invalid_arg_2'"
" in vhost '/': \"unsupported queue type 'fake-queue-type'\"">>,
?assertExit(
{{shutdown, {server_initiated_close, 406, ExpectedError}}, _},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"fake-queue-type">>}])).
declare_invalid_arg_3(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
Q = ?config(queue_name, Config),
ExpectedError = <<"PRECONDITION_FAILED - invalid arg 'x-max-length' for queue 'declare_invalid_arg_3'"
" in vhost '/': {value_negative,-5}">>,
?assertExit(
{{shutdown, {server_initiated_close, 406, ExpectedError}}, _},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>},
{<<"x-max-length">>, long, -5}])).
relaxed_argument_equivalence_checks_on_qq_redeclare(Config) ->
ok = rabbit_ct_broker_helpers:rpc(Config, 0, application, set_env,
[rabbit, quorum_relaxed_checks_on_redeclaration, true]),
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
VHost = <<"redeclarevhost">>,
User = ?config(rmq_username, Config),
ok = rabbit_ct_broker_helpers:add_vhost(Config, Node, VHost, User),
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node, VHost),
{ok, Ch} = amqp_connection:open_channel(Conn),
Q = atom_to_binary(?FUNCTION_NAME, utf8),
%% Declare a quorum queue
?assertEqual({'queue.declare_ok', Q, 0, 0},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>},
{<<"x-expires">>, long, 1000}])),
%% re-declare it as a classic queue, which is OK on this node because we've opted in
?assertEqual({'queue.declare_ok', Q, 0, 0},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"classic">>},
{<<"x-expires">>, long, 1000}])),
%% re-declare it as classic queue with classic only arguments ignored: OK
?assertEqual({'queue.declare_ok', Q, 0, 0},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"classic">>},
{<<"x-max-priority">>, byte, 5},
{<<"x-expires">>, long, 1000}])),
%% re-declare it as a classic queue, with shared arguments not part of original queue: this should fail
?assertExit(
{{shutdown, {server_initiated_close, 406, _}}, _},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"classic">>},
{<<"x-message-ttl">>, long, 5},
{<<"x-expires">>, long, 1000}])),
ok = rabbit_ct_broker_helpers:delete_vhost(Config, VHost),
ok = rabbit_ct_broker_helpers:rpc(Config, 0, application, set_env,
[rabbit, quorum_relaxed_checks_on_redeclaration, false]),
ok.
consume_invalid_arg_1(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
Q = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', Q, 0, 0},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
ExpectedError = <<"PRECONDITION_FAILED - invalid arg 'x-stream-offset' for queue "
"'consume_invalid_arg_1' in vhost '/' of queue type rabbit_quorum_queue">>,
?assertExit(
{{shutdown, {server_initiated_close, 406, ExpectedError}}, _},
amqp_channel:subscribe(Ch, #'basic.consume'{
queue = Q,
arguments = [{<<"x-stream-offset">>, longstr, <<"last">>}],
no_ack = false,
consumer_tag = <<"ctag">>},
self())).
consume_invalid_arg_2(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
Q = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', Q, 0, 0},
declare(Ch, Q, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
ExpectedError = <<"PRECONDITION_FAILED - invalid arg 'x-priority' for queue 'consume_invalid_arg_2'"
" in vhost '/': \"expected integer, got longstr\"">>,
?assertExit(
{{shutdown, {server_initiated_close, 406, ExpectedError}}, _},
amqp_channel:subscribe(Ch, #'basic.consume'{
queue = Q,
arguments = [{<<"x-priority">>, longstr, <<"important">>}],
no_ack = false,
consumer_tag = <<"ctag">>},
self())).
start_queue(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
Children = length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% Check that the application and one ra node are up
?awaitMatch({ra, _, _},
lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, [])),
?DEFAULT_AWAIT),
Expected = Children + 1,
?awaitMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
?DEFAULT_AWAIT),
%% Test declare an existing queue
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% Test declare with same arguments
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% Test declare an existing queue with different arguments
?assertExit(_, declare(Ch, LQ, [])),
%% Check that the application and process are still up
?assertMatch({ra, _, _}, lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, []))),
?assertMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME]))),
ok.
long_name(Config) ->
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
%% 64 + chars
VHost = <<"long_name_vhost____________________________________">>,
QName = atom_to_binary(?FUNCTION_NAME, utf8),
User = ?config(rmq_username, Config),
ok = rabbit_ct_broker_helpers:add_vhost(Config, Node, VHost, User),
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node,
VHost),
{ok, Ch} = amqp_connection:open_channel(Conn),
%% long name
LongName = binary:copy(QName, 240 div byte_size(QName)),
?assertEqual({'queue.declare_ok', LongName, 0, 0},
declare(Ch, LongName,
[{<<"x-queue-type">>, longstr, <<"quorum">>}])),
ok.
start_queue_concurrent(Config) ->
Servers = rabbit_ct_broker_helpers:get_node_configs(Config, nodename),
LQ = ?config(queue_name, Config),
Self = self(),
[begin
_ = spawn_link(fun () ->
{Conn, Ch} = rabbit_ct_client_helpers:open_connection_and_channel(Config, Server),
%% Test declare an existing queue
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ,
[{<<"x-queue-type">>,
longstr,
<<"quorum">>}])),
timer:sleep(100),
rabbit_ct_client_helpers:close_connection_and_channel(Conn, Ch),
Self ! {done, Server}
end)
end || Server <- Servers],
[begin
receive {done, Server} -> ok
after 10000 -> exit({await_done_timeout, Server})
end
end || Server <- Servers],
ok.
quorum_cluster_size_3(Config) ->
case rabbit_ct_helpers:is_mixed_versions() of
true ->
{skip, "quorum_cluster_size_3 test isn't mixed version reliable"};
false ->
quorum_cluster_size_x(Config, 3, 3)
end.
quorum_cluster_size_7(Config) ->
quorum_cluster_size_x(Config, 7, 5).
quorum_cluster_size_x(Config, Max, Expected) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
QQ = ?config(queue_name, Config),
RaName = ra_name(QQ),
?assertEqual({'queue.declare_ok', QQ, 0, 0},
declare(Ch, QQ, [{<<"x-queue-type">>, longstr, <<"quorum">>},
{<<"x-quorum-initial-group-size">>, long, Max}])),
?awaitMatch({ok, Members, _} when length(Members) == Expected,
ra:members({RaName, Server}),
?DEFAULT_AWAIT),
?awaitMatch(MembersQ when length(MembersQ) == Expected,
begin
Info = rpc:call(Server, rabbit_quorum_queue, infos,
[rabbit_misc:r(<<"/">>, queue, QQ)]),
proplists:get_value(members, Info)
end, ?DEFAULT_AWAIT).
stop_queue(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
%% The stream coordinator is also a ra process, we need to ensure the quorum tests
%% are not affected by any other ra cluster that could be added in the future
Children = length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% Check that the application and one ra node are up
?awaitMatch({ra, _, _},
lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, [])),
?DEFAULT_AWAIT),
Expected = Children + 1,
?awaitMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
?DEFAULT_AWAIT),
%% Delete the quorum queue
?assertMatch(#'queue.delete_ok'{}, amqp_channel:call(Ch, #'queue.delete'{queue = LQ})),
%% Check that the application and process are down
?awaitMatch(Children,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
30000),
?awaitMatch({ra, _, _},
lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, [])),
?DEFAULT_AWAIT).
restart_queue(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
%% The stream coordinator is also a ra process, we need to ensure the quorum tests
%% are not affected by any other ra cluster that could be added in the future
Children = length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
ok = rabbit_ct_broker_helpers:stop_node(Config, Server),
ok = rabbit_ct_broker_helpers:start_node(Config, Server),
%% Check that the application and one ra node are up
%% The node has just been restarted, let's give it a bit of time to be ready if needed
?awaitMatch({ra, _, _},
lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, [])),
?DEFAULT_AWAIT),
Expected = Children + 1,
?assertMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME]))),
Ch2 = rabbit_ct_client_helpers:open_channel(Config, Server),
delete_queues(Ch2, [LQ]).
idempotent_recover(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% kill default vhost to trigger recovery
[{_, SupWrapperPid, _, _} | _] = rpc:call(Server, supervisor,
which_children,
[rabbit_vhost_sup_sup]),
[{_, Pid, _, _} | _] = rpc:call(Server, supervisor,
which_children,
[SupWrapperPid]),
%% kill the vhost process to trigger recover
rpc:call(Server, erlang, exit, [Pid, kill]),
%% validate quorum queue is still functional
?awaitMatch({ok, _, _},
begin
RaName = ra_name(LQ),
ra:members({RaName, Server})
end, ?DEFAULT_AWAIT),
%% validate vhosts are running - or rather validate that at least one
%% vhost per cluster is running
?awaitMatch(true,
begin
Is = rpc:call(Server, rabbit_vhost,info_all, []),
lists:all(fun (I) ->
#{cluster_state := ServerStatuses} = maps:from_list(I),
maps:get(Server, maps:from_list(ServerStatuses)) =:= running
end, Is)
end, ?DEFAULT_AWAIT),
ok.
server_system_recover(Config) ->
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
LQ = ?config(queue_name, Config),
?assertEqual({'queue.declare_ok', LQ, 0, 0},
declare(Ch, LQ, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
RaName = ra_name(LQ),
_ = ra:members({RaName, Server}),
EtsPid = ct_rpc:call(Server, erlang, whereis, [ra_log_ets]),
?assert(is_pid(EtsPid)),
true = ct_rpc:call(Server, erlang, exit, [EtsPid, kill]),
%% validate quorum queue is still functional
?awaitMatch({ok, _, _},
begin
%% there is a small chance that a quorum queue process will crash
%% due to missing ETS table, in this case we need to keep
%% retrying awaiting the restart
catch ra:members({RaName, Server})
end, ?DEFAULT_AWAIT),
ok.
vhost_with_quorum_queue_is_deleted(Config) ->
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
VHost = <<"vhost2">>,
QName = atom_to_binary(?FUNCTION_NAME, utf8),
RaName = binary_to_atom(<<VHost/binary, "_", QName/binary>>, utf8),
User = ?config(rmq_username, Config),
ok = rabbit_ct_broker_helpers:add_vhost(Config, Node, VHost, User),
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node,
VHost),
{ok, Ch} = amqp_connection:open_channel(Conn),
?assertEqual({'queue.declare_ok', QName, 0, 0},
declare(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
UId = rpc:call(Node, ra_directory, where_is, [quorum_queues, RaName]),
?assert(UId =/= undefined),
ok = rabbit_ct_broker_helpers:delete_vhost(Config, VHost),
%% validate quorum queues got deleted
undefined = rpc:call(Node, ra_directory, where_is, [quorum_queues, RaName]),
ok.
vhost_with_default_queue_type_declares_quorum_queue(Config) ->
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
VHost = atom_to_binary(?FUNCTION_NAME, utf8),
QName = atom_to_binary(?FUNCTION_NAME, utf8),
User = ?config(rmq_username, Config),
AddVhostArgs = [VHost, #{default_queue_type => <<"quorum">>}, User],
ok = rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_vhost, add,
AddVhostArgs),
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node, VHost),
{ok, Ch} = amqp_connection:open_channel(Conn),
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
assert_queue_type(Node, VHost, QName, rabbit_quorum_queue),
%% declaring again without a queue arg is ok
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
%% also using an explicit queue type should be ok
?assertEqual({'queue.declare_ok', QName, 0, 0},
declare(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% passive should work without x-queue-type
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare_passive(Ch, QName, [])),
%% passive with x-queue-type also should work
?assertEqual({'queue.declare_ok', QName, 0, 0},
declare_passive(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
%% declaring an exclusive queue should declare a classic queue
QNameEx = iolist_to_binary([QName, <<"_exclusive">>]),
?assertEqual({'queue.declare_ok', QNameEx, 0, 0},
amqp_channel:call(Ch, #'queue.declare'{queue = QNameEx,
exclusive = true,
durable = true,
arguments = []})),
assert_queue_type(Node, VHost, QNameEx, rabbit_classic_queue),
%% transient declares should also fall back to classic queues
QNameTr = iolist_to_binary([QName, <<"_transient">>]),
?assertEqual({'queue.declare_ok', QNameTr, 0, 0},
amqp_channel:call(Ch, #'queue.declare'{queue = QNameTr,
exclusive = false,
durable = false,
arguments = []})),
assert_queue_type(Node, VHost, QNameTr, rabbit_classic_queue),
%% auto-delete declares should also fall back to classic queues
QNameAd = iolist_to_binary([QName, <<"_delete">>]),
?assertEqual({'queue.declare_ok', QNameAd, 0, 0},
amqp_channel:call(Ch, #'queue.declare'{queue = QNameAd,
exclusive = false,
auto_delete = true,
durable = true,
arguments = []})),
assert_queue_type(Node, VHost, QNameAd, rabbit_classic_queue),
amqp_connection:close(Conn),
ok.
node_wide_default_queue_type_declares_quorum_queue(Config) ->
case rabbit_ct_helpers:is_mixed_versions() of
true ->
{skip, "node_wide_default_queue_type_declares_quorum_queue test isn't mixed version compatible"};
false ->
node_wide_default_queue_type_declares_quorum_queue0(Config)
end.
node_wide_default_queue_type_declares_quorum_queue0(Config) ->
Node = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
rpc:call(Node, application, set_env, [rabbit, default_queue_type, rabbit_quorum_queue]),
VHost = atom_to_binary(?FUNCTION_NAME, utf8),
QName = atom_to_binary(?FUNCTION_NAME, utf8),
User = ?config(rmq_username, Config),
AddVhostArgs = [VHost, #{}, User],
ok = rabbit_ct_broker_helpers:rpc(Config, Node, rabbit_vhost, add,
AddVhostArgs),
ok = rabbit_ct_broker_helpers:set_full_permissions(Config, User, VHost),
Conn = rabbit_ct_client_helpers:open_unmanaged_connection(Config, Node, VHost),
{ok, Ch} = amqp_connection:open_channel(Conn),
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
assert_queue_type(Node, VHost, QName, rabbit_quorum_queue),
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare(Ch, QName, [])),
?assertEqual({'queue.declare_ok', QName, 0, 0},
declare(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
?assertEqual({'queue.declare_ok', QName, 0, 0}, declare_passive(Ch, QName, [])),
?assertEqual({'queue.declare_ok', QName, 0, 0},
declare_passive(Ch, QName, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
amqp_connection:close(Conn),
rpc:call(Node, application, set_env, [rabbit, default_queue_type, rabbit_classic_queue]),
ok.
restart_all_types(Config) ->
%% Test the node restart with both types of queues (quorum and classic) to
%% ensure there are no regressions
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
%% The stream coordinator is also a ra process, we need to ensure the quorum tests
%% are not affected by any other ra cluster that could be added in the future
Children = rpc:call(Server, supervisor, which_children, [?SUPNAME]),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
QQ1 = <<"restart_all_types-qq1">>,
?assertEqual({'queue.declare_ok', QQ1, 0, 0},
declare(Ch, QQ1, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
QQ2 = <<"restart_all_types-qq2">>,
?assertEqual({'queue.declare_ok', QQ2, 0, 0},
declare(Ch, QQ2, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
CQ1 = <<"restart_all_types-classic1">>,
?assertEqual({'queue.declare_ok', CQ1, 0, 0}, declare(Ch, CQ1, [])),
rabbit_ct_client_helpers:publish(Ch, CQ1, 1),
CQ2 = <<"restart_all_types-classic2">>,
?assertEqual({'queue.declare_ok', CQ2, 0, 0}, declare(Ch, CQ2, [])),
rabbit_ct_client_helpers:publish(Ch, CQ2, 1),
ok = rabbit_ct_broker_helpers:stop_node(Config, Server),
ok = rabbit_ct_broker_helpers:start_node(Config, Server),
%% Check that the application and two ra nodes are up. Queues are restored
%% after the broker is marked as "ready", that's why we need to wait for
%% the condition.
?awaitMatch({ra, _, _},
lists:keyfind(ra, 1,
rpc:call(Server, application, which_applications, [])),
?DEFAULT_AWAIT),
Expected = length(Children) + 2,
?awaitMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
60000),
%% Check the classic queues restarted correctly
Ch2 = rabbit_ct_client_helpers:open_channel(Config, Server),
{#'basic.get_ok'{}, #amqp_msg{}} =
amqp_channel:call(Ch2, #'basic.get'{queue = CQ1, no_ack = false}),
{#'basic.get_ok'{}, #amqp_msg{}} =
amqp_channel:call(Ch2, #'basic.get'{queue = CQ2, no_ack = false}),
delete_queues(Ch2, [QQ1, QQ2, CQ1, CQ2]).
delete_queues(Ch, Queues) ->
[amqp_channel:call(Ch, #'queue.delete'{queue = Q}) || Q <- Queues],
ok.
stop_start_rabbit_app(Config) ->
%% Test start/stop of rabbit app with both types of queues (quorum and
%% classic) to ensure there are no regressions
Server = rabbit_ct_broker_helpers:get_node_config(Config, 0, nodename),
%% The stream coordinator is also a ra process, we need to ensure the quorum tests
%% are not affected by any other ra cluster that could be added in the future
Children = length(rpc:call(Server, supervisor, which_children, [?SUPNAME])),
Ch = rabbit_ct_client_helpers:open_channel(Config, Server),
QQ1 = <<"stop_start_rabbit_app-qq">>,
?assertEqual({'queue.declare_ok', QQ1, 0, 0},
declare(Ch, QQ1, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
QQ2 = <<"quorum-q2">>,
?assertEqual({'queue.declare_ok', QQ2, 0, 0},
declare(Ch, QQ2, [{<<"x-queue-type">>, longstr, <<"quorum">>}])),
CQ1 = <<"stop_start_rabbit_app-classic">>,
?assertEqual({'queue.declare_ok', CQ1, 0, 0}, declare(Ch, CQ1, [])),
rabbit_ct_client_helpers:publish(Ch, CQ1, 1),
CQ2 = <<"stop_start_rabbit_app-classic2">>,
?assertEqual({'queue.declare_ok', CQ2, 0, 0}, declare(Ch, CQ2, [])),
rabbit_ct_client_helpers:publish(Ch, CQ2, 1),
?assertEqual(ok, rabbit_control_helper:command(stop_app, Server)),
%% Check the ra application has stopped (thus its supervisor and queues)
rabbit_ct_helpers:await_condition(
fun() ->
Apps = rpc:call(Server, application, which_applications, []),
%% we expect the app to NOT be running
case lists:keyfind(ra, 1, Apps) of
false -> true;
{ra, _, _} -> false
end
end, 30000),
?assertEqual(ok, rabbit_control_helper:command(start_app, Server)),
%% Check that the application and two ra nodes are up
rabbit_ct_helpers:await_condition(
fun() ->
Apps = rpc:call(Server, application, which_applications, []),
case lists:keyfind(ra, 1, Apps) of
false -> false;
{ra, _, _} -> true
end
end, 30000),
Expected = Children + 2,
?assertMatch(Expected,
length(rpc:call(Server, supervisor, which_children, [?SUPNAME]))),
%% Check the classic queues restarted correctly
Ch2 = rabbit_ct_client_helpers:open_channel(Config, Server),
{#'basic.get_ok'{}, #amqp_msg{}} =
amqp_channel:call(Ch2, #'basic.get'{queue = CQ1, no_ack = false}),
{#'basic.get_ok'{}, #amqp_msg{}} =
amqp_channel:call(Ch2, #'basic.get'{queue = CQ2, no_ack = false}),
delete_queues(Ch2, [QQ1, QQ2, CQ1, CQ2]).
publish_confirm(Ch, QName) ->
publish_confirm(Ch, QName, 2500).
publish_confirm(Ch, QName, Timeout) ->
publish(Ch, QName),
amqp_channel:register_confirm_handler(Ch, self()),
ct:pal("waiting for confirms from ~ts", [QName]),
receive
#'basic.ack'{} ->
ct:pal("CONFIRMED! ~ts", [QName]),
ok;
#'basic.nack'{} ->
ct:pal("NOT CONFIRMED! ~ts", [QName]),
fail
after Timeout ->
flush(1),
exit(confirm_timeout)