1111-include_lib (" eunit/include/eunit.hrl" ).
1212-include_lib (" amqp_client/include/amqp_client.hrl" ).
1313
14+ -compile (nowarn_export_all ).
1415-compile (export_all ).
1516
1617all () ->
@@ -22,6 +23,7 @@ all() ->
2223groups () ->
2324 [
2425 {tests , [], [
26+ reliable_send_receive_with_outcomes ,
2527 roundtrip_quorum_queue_with_drain ,
2628 message_headers_conversion
2729 ]},
@@ -68,6 +70,75 @@ end_per_testcase(Testcase, Config) ->
6870% %% TESTS
6971% %%
7072
73+ reliable_send_receive_with_outcomes (Config ) ->
74+ Outcomes = [accepted ,
75+ modified ,
76+ rejected ,
77+ released ],
78+ [begin
79+ ct :pal (" ~s testing ~s " , [? FUNCTION_NAME , Outcome ]),
80+ reliable_send_receive (Config , Outcome )
81+ end || Outcome <- Outcomes ],
82+ ok .
83+
84+ reliable_send_receive (Config , Outcome ) ->
85+ Container = atom_to_binary (? FUNCTION_NAME , utf8 ),
86+ OutcomeBin = atom_to_binary (Outcome , utf8 ),
87+ QName = <<Container /binary , OutcomeBin /binary >>,
88+ % % declare a quorum queue
89+ Ch = rabbit_ct_client_helpers :open_channel (Config , 0 ),
90+ amqp_channel :call (Ch , # 'queue.declare' {queue = QName ,
91+ durable = true ,
92+ arguments = [{<<" x-queue-type" >>,
93+ longstr , <<" quorum" >>}]}),
94+ rabbit_ct_client_helpers :close_channel (Ch ),
95+ % % reliable send and consume
96+ Host = ? config (rmq_hostname , Config ),
97+ Port = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_amqp ),
98+ Address = <<" /amq/queue/" , QName /binary >>,
99+
100+ OpnConf = #{address => Host ,
101+ port => Port ,
102+ container_id => Container ,
103+ sasl => {plain , <<" guest" >>, <<" guest" >>}},
104+ {ok , Connection } = amqp10_client :open_connection (OpnConf ),
105+ {ok , Session } = amqp10_client :begin_session (Connection ),
106+ SenderLinkName = <<" test-sender" >>,
107+ {ok , Sender } = amqp10_client :attach_sender_link (Session ,
108+ SenderLinkName ,
109+ Address ),
110+ ok = wait_for_credit (Sender ),
111+ DTag1 = <<" dtag-1" >>,
112+ % % create an unsettled message,
113+ % % link will be in "mixed" mode by default
114+ Msg1 = amqp10_msg :new (DTag1 , <<" body-1" >>, false ),
115+ ok = amqp10_client :send_msg (Sender , Msg1 ),
116+ ok = wait_for_settlement (DTag1 ),
117+
118+ ok = amqp10_client :detach_link (Sender ),
119+ ok = amqp10_client :close_connection (Connection ),
120+ flush (" post sender close" ),
121+
122+ {ok , Connection2 } = amqp10_client :open_connection (OpnConf ),
123+ {ok , Session2 } = amqp10_client :begin_session (Connection2 ),
124+ ReceiverLinkName = <<" test-receiver" >>,
125+ {ok , Receiver } = amqp10_client :attach_receiver_link (Session2 ,
126+ ReceiverLinkName ,
127+ Address ,
128+ unsettled ),
129+ {ok , Msg } = amqp10_client :get_msg (Receiver ),
130+
131+ ct :pal (" got ~p " , [amqp10_msg :body (Msg )]),
132+
133+ ok = amqp10_client :settle_msg (Receiver , Msg , Outcome ),
134+
135+ flush (" post accept" ),
136+
137+ ok = amqp10_client :detach_link (Receiver ),
138+ ok = amqp10_client :close_connection (Connection2 ),
139+
140+ ok .
141+
71142roundtrip_quorum_queue_with_drain (Config ) ->
72143 Host = ? config (rmq_hostname , Config ),
73144 Port = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_amqp ),
@@ -83,7 +154,7 @@ roundtrip_quorum_queue_with_drain(Config) ->
83154 port => Port ,
84155 container_id => atom_to_binary (? FUNCTION_NAME , utf8 ),
85156 sasl => {plain , <<" guest" >>, <<" guest" >>}},
86-
157+
87158 {ok , Connection } = amqp10_client :open_connection (OpnConf ),
88159 {ok , Session } = amqp10_client :begin_session (Connection ),
89160 SenderLinkName = <<" test-sender" >>,
@@ -141,18 +212,18 @@ message_headers_conversion(Config) ->
141212 amqp_channel :call (Ch , # 'queue.declare' {queue = QName ,
142213 durable = true ,
143214 arguments = [{<<" x-queue-type" >>, longstr , <<" quorum" >>}]}),
144-
215+
145216 rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,[rabbitmq_amqp1_0 , convert_amqp091_headers_to_app_props , true ]),
146217 rabbit_ct_broker_helpers :rpc (Config , 0 , application , set_env ,[rabbitmq_amqp1_0 , convert_app_props_to_amqp091_headers , true ]),
147-
218+
148219 OpnConf = #{address => Host ,
149220 port => Port ,
150221 container_id => atom_to_binary (? FUNCTION_NAME , utf8 ),
151222 sasl => {plain , <<" guest" >>, <<" guest" >>}},
152-
223+
153224 {ok , Connection } = amqp10_client :open_connection (OpnConf ),
154225 {ok , Session } = amqp10_client :begin_session (Connection ),
155-
226+
156227 amqp10_to_amqp091_header_conversion (Session , Ch , QName , Address ),
157228
158229 amqp091_to_amqp10_header_conversion (Session , Ch , QName , Address ),
@@ -173,7 +244,7 @@ amqp10_to_amqp091_header_conversion(Session,Ch, QName, Address) ->
173244 wait_for_accepts (1 ),
174245
175246 {ok , Headers } = amqp091_get_msg_headers (Ch , QName ),
176-
247+
177248 ? assertEqual ({bool , true }, rabbit_misc :table_lookup (Headers , <<" x-bool" >>)),
178249 ? assertEqual ({unsignedint , 3 }, rabbit_misc :table_lookup (Headers , <<" x-int" >>)),
179250 ? assertEqual ({longstr , <<" string-value" >>}, rabbit_misc :table_lookup (Headers , <<" x-string" >>)).
@@ -252,22 +323,35 @@ open_and_close_connection(OpnConf) ->
252323 ok = amqp10_client :close_connection (Connection ).
253324
254325% before we can send messages we have to wait for credit from the server
255- wait_for_credit (Sender ) ->
326+ wait_for_credit (Sender ) ->
327+ receive
328+ {amqp10_event , {link , Sender , credited }} ->
329+ flush (? FUNCTION_NAME ),
330+ ok
331+ after 5000 ->
332+ flush (" wait_for_credit timed out" ),
333+ ct :fail (credited_timeout )
334+ end .
335+
336+ wait_for_settlement (Tag ) ->
256337 receive
257- {amqp10_event , {link , Sender , credited }} ->
338+ {amqp10_disposition , {accepted , Tag }} ->
339+ flush (? FUNCTION_NAME ),
258340 ok
259341 after 5000 ->
260- flush (" Credit timed out" ),
261- exit (credited_timeout )
342+ flush (" wait_for_settlement timed out" ),
343+ ct : fail (credited_timeout )
262344 end .
263345
264346wait_for_accepts (0 ) -> ok ;
265- wait_for_accepts (N ) ->
266- receive
267- {amqp10_disposition ,{accepted ,_ }} -> wait_for_accepts (N - 1 )
268- after 250 ->
269- ok
347+ wait_for_accepts (N ) ->
348+ receive
349+ {amqp10_disposition ,{accepted ,_ }} ->
350+ wait_for_accepts (N - 1 )
351+ after 250 ->
352+ ok
270353 end .
354+
271355delete_queue (Config , QName ) ->
272356 Ch = rabbit_ct_client_helpers :open_channel (Config , 0 ),
273357 _ = amqp_channel :call (Ch , # 'queue.delete' {queue = QName }),
0 commit comments