@@ -275,61 +275,38 @@ amqp_attach_sub_batch(Config) ->
275275% % -------------------------------------------------------------------
276276
277277publish_via_stream_protocol (Stream , Config ) ->
278- % % There is no open source Erlang RabbitMQ Stream client.
279- % % Therefore, we have to build the Stream protocol commands manually.
280-
281- StreamPort = rabbit_ct_broker_helpers :get_node_config (Config , 0 , tcp_port_stream ),
282- {ok , S } = gen_tcp :connect (" localhost" , StreamPort , [{active , false }, {mode , binary }]),
283-
284- C0 = rabbit_stream_core :init (0 ),
285- PeerPropertiesFrame = rabbit_stream_core :frame ({request , 1 , {peer_properties , #{}}}),
286- ok = gen_tcp :send (S , PeerPropertiesFrame ),
287- {{response , 1 , {peer_properties , _ , _ }}, C1 } = receive_stream_commands (S , C0 ),
288-
289- ok = gen_tcp :send (S , rabbit_stream_core :frame ({request , 1 , sasl_handshake })),
290- {{response , _ , {sasl_handshake , _ , _ }}, C2 } = receive_stream_commands (S , C1 ),
291- Username = <<" guest" >>,
292- Password = <<" guest" >>,
293- Null = 0 ,
294- PlainSasl = <<Null :8 , Username /binary , Null :8 , Password /binary >>,
295- ok = gen_tcp :send (S , rabbit_stream_core :frame ({request , 2 , {sasl_authenticate , <<" PLAIN" >>, PlainSasl }})),
296- {{response , 2 , {sasl_authenticate , _ }}, C3 } = receive_stream_commands (S , C2 ),
297- {{tune , DefaultFrameMax , _ }, C4 } = receive_stream_commands (S , C3 ),
298-
299- ok = gen_tcp :send (S , rabbit_stream_core :frame ({response , 0 , {tune , DefaultFrameMax , 0 }})),
300- ok = gen_tcp :send (S , rabbit_stream_core :frame ({request , 3 , {open , <<" /" >>}})),
301- {{response , 3 , {open , _ , _ConnectionProperties }}, C5 } = receive_stream_commands (S , C4 ),
302-
303- CreateStreamFrame = rabbit_stream_core :frame ({request , 1 , {create_stream , Stream , #{}}}),
304- ok = gen_tcp :send (S , CreateStreamFrame ),
305- {{response , 1 , {create_stream , _ }}, C6 } = receive_stream_commands (S , C5 ),
278+ {ok , S , C0 } = stream_test_utils :connect (Config , 0 ),
279+
280+ {ok , C1 } = stream_test_utils :create_stream (S , C0 , Stream ),
306281
307282 PublisherId = 99 ,
308- DeclarePublisherFrame = rabbit_stream_core :frame ({request , 1 , {declare_publisher , PublisherId , <<>>, Stream }}),
309- ok = gen_tcp :send (S , DeclarePublisherFrame ),
310- {{response , 1 , {declare_publisher , _ }}, C7 } = receive_stream_commands (S , C6 ),
283+ {ok , C2 } = stream_test_utils :declare_publisher (S , C1 , Stream , PublisherId ),
311284
285+ <<<<<<< HEAD
312286 M1 = simple_entry (1 , <<" m1" >>),
313287 M2 = simple_entry (2 , <<" m2" >>),
314288 M3 = simple_entry (3 , <<" m3" >>),
289+ =======
290+ M1 = stream_test_utils :simple_entry (1 , <<" m1" >>),
291+ M2 = stream_test_utils :simple_entry (2 , <<" m2" >>, # 'v1_0.application_properties' {
292+ content = [{{utf8 , <<" my key" >>},
293+ {utf8 , <<" my value" >>}}]}),
294+ M3 = stream_test_utils :simple_entry (3 , <<" m3" >>),
295+ >>>>>>> 9 bb7530d04 (Move client - side stream protocol test helpers to a separate module )
315296 Messages1 = [M1 , M2 , M3 ],
316- PublishFrame1 = rabbit_stream_core :frame ({publish , PublisherId , length (Messages1 ), Messages1 }),
317- ok = gen_tcp :send (S , PublishFrame1 ),
318- {{publish_confirm , PublisherId , _ }, C8 } = receive_stream_commands (S , C7 ),
319-
320- UncompressedSubbatch = sub_batch_entry_uncompressed (4 , [<<" m4" >>, <<" m5" >>, <<" m6" >>]),
321- PublishFrame2 = rabbit_stream_core :frame ({publish , PublisherId , 3 , UncompressedSubbatch }),
322- ok = gen_tcp :send (S , PublishFrame2 ),
323- {{publish_confirm , PublisherId , _ }, C9 } = receive_stream_commands (S , C8 ),
324-
325- CompressedSubbatch = sub_batch_entry_compressed (5 , [<<" m7" >>, <<" m8" >>, <<" m9" >>]),
326- PublishFrame3 = rabbit_stream_core :frame ({publish , PublisherId , 3 , CompressedSubbatch }),
327- ok = gen_tcp :send (S , PublishFrame3 ),
328- {{publish_confirm , PublisherId , _ }, C10 } = receive_stream_commands (S , C9 ),
329-
330- M10 = simple_entry (6 , <<" m10" >>),
331- M11 = simple_entry (7 , <<" m11" >>),
297+
298+ {ok , _ , C3 } = stream_test_utils :publish_entries (S , C2 , PublisherId , length (Messages1 ), Messages1 ),
299+
300+ UncompressedSubbatch = stream_test_utils :sub_batch_entry_uncompressed (4 , [<<" m4" >>, <<" m5" >>, <<" m6" >>]),
301+ {ok , _ , C4 } = stream_test_utils :publish_entries (S , C3 , PublisherId , 3 , UncompressedSubbatch ),
302+
303+ CompressedSubbatch = stream_test_utils :sub_batch_entry_compressed (5 , [<<" m7" >>, <<" m8" >>, <<" m9" >>]),
304+ {ok , _ , C5 } = stream_test_utils :publish_entries (S , C4 , PublisherId , 3 , CompressedSubbatch ),
305+
306+ M10 = stream_test_utils :simple_entry (6 , <<" m10" >>),
307+ M11 = stream_test_utils :simple_entry (7 , <<" m11" >>),
332308 Messages2 = [M10 , M11 ],
309+ <<<<<<< HEAD
333310 PublishFrame4 = rabbit_stream_core :frame ({publish , PublisherId , length (Messages2 ), Messages2 }),
334311 ok = gen_tcp :send (S , PublishFrame4 ),
335312 {{publish_confirm , PublisherId , _ }, _C11 } = receive_stream_commands (S , C10 ).
@@ -363,6 +340,9 @@ sub_batch_entry_compressed(Sequence, Bodies) ->
363340 CompressedLen = byte_size (Compressed ),
364341 <<Sequence :64 , 1 :1 , 1 :3 , 0 :4 , (length (Bodies )):16 , (byte_size (Uncompressed )):32 ,
365342 CompressedLen :32 , Compressed :CompressedLen /binary >>.
343+ =======
344+ {ok , _ , _C6 } = stream_test_utils :publish_entries (S , C5 , PublisherId , length (Messages2 ), Messages2 ).
345+ >>>>>>> 9 bb7530d04 (Move client - side stream protocol test helpers to a separate module )
366346
367347connection_config (Config ) ->
368348 Host = ? config (rmq_hostname , Config ),
@@ -372,27 +352,6 @@ connection_config(Config) ->
372352 container_id => <<" my container" >>,
373353 sasl => {plain , <<" guest" >>, <<" guest" >>}}.
374354
375- receive_stream_commands (Sock , C0 ) ->
376- case rabbit_stream_core :next_command (C0 ) of
377- empty ->
378- case gen_tcp :recv (Sock , 0 , 5000 ) of
379- {ok , Data } ->
380- C1 = rabbit_stream_core :incoming_data (Data , C0 ),
381- case rabbit_stream_core :next_command (C1 ) of
382- empty ->
383- {ok , Data2 } = gen_tcp :recv (Sock , 0 , 5000 ),
384- rabbit_stream_core :next_command (
385- rabbit_stream_core :incoming_data (Data2 , C1 ));
386- Res ->
387- Res
388- end ;
389- {error , Err } ->
390- ct :fail (" error receiving stream data ~w " , [Err ])
391- end ;
392- Res ->
393- Res
394- end .
395-
396355receive_amqp_messages (Receiver , N ) ->
397356 receive_amqp_messages0 (Receiver , N , []).
398357
0 commit comments