@@ -53,7 +53,9 @@ groups() ->
5353 {mock , [], [
5454 insufficient_credit ,
5555 incoming_heartbeat ,
56- multi_transfer_without_delivery_id
56+ multi_transfer_without_delivery_id ,
57+ set_sender_capabilities ,
58+ set_receiver_capabilities
5759 ]}
5860 ].
5961
@@ -914,6 +916,135 @@ incoming_heartbeat(Config) ->
914916 end ,
915917 demonitor (MockRef ).
916918
919+ set_sender_capabilities (Config ) ->
920+ Hostname = ? config (mock_host , Config ),
921+ Port = ? config (mock_port , Config ),
922+
923+ OpenStep = fun ({0 = Ch , # 'v1_0.open' {}, _Pay }) ->
924+ {Ch , [# 'v1_0.open' {
925+ container_id = {utf8 , <<" mock" >>},
926+ % % The server doesn't expect any heartbeats from us (client).
927+ idle_time_out = {uint , 0 }}]}
928+ end ,
929+
930+ BeginStep = fun ({0 = Ch , # 'v1_0.begin' {}, _Pay }) ->
931+ {Ch , [# 'v1_0.begin' {remote_channel = {ushort , Ch },
932+ next_outgoing_id = {uint , 1 },
933+ incoming_window = {uint , 1000 },
934+ outgoing_window = {uint , 1000 }}
935+ ]}
936+ end ,
937+ AttachStep = fun ({0 = Ch , # 'v1_0.attach' {role = false ,
938+ name = Name ,
939+ source = # 'v1_0.source' {
940+
941+ },
942+ target = # 'v1_0.target' {
943+ capabilities = {symbol , <<" capability-1" >>}}}, <<>>}) ->
944+ {Ch , [# 'v1_0.attach' {name = Name ,
945+ handle = {uint , 99 },
946+ role = true }]}
947+ end ,
948+ Steps = [fun mock_server :recv_amqp_header_step /1 ,
949+ fun mock_server :send_amqp_header_step /1 ,
950+ mock_server :amqp_step (OpenStep ),
951+ mock_server :amqp_step (BeginStep ),
952+ mock_server :amqp_step (AttachStep )],
953+
954+ ok = mock_server :set_steps (? config (mock_server , Config ), Steps ),
955+
956+ Cfg = #{address => Hostname , port => Port , sasl => none , notify => self ()},
957+ {ok , Connection } = amqp10_client :open_connection (Cfg ),
958+ {ok , Session } = amqp10_client :begin_session_sync (Connection ),
959+ AttachArgs = #{name => <<" mock1-sender" >>,
960+ role => {sender , #{address => <<" test" >>,
961+ durable => none ,
962+ capabilities => <<" capability-1" >>}},
963+ snd_settle_mode => mixed ,
964+ rcv_settle_mode => first },
965+ {ok , Sender } = amqp10_client :attach_link (Session , AttachArgs ),
966+ await_link (Sender , attached , attached_timeout ),
967+ Msg = amqp10_msg :new (<<" mock-tag" >>, <<" banana" >>, true ),
968+ {error , insufficient_credit } = amqp10_client :send_msg (Sender , Msg ),
969+
970+ ok = amqp10_client :end_session (Session ),
971+ ok = amqp10_client :close_connection (Connection ),
972+ ok .
973+
974+ set_receiver_capabilities (Config ) ->
975+ Hostname = ? config (mock_host , Config ),
976+ Port = ? config (mock_port , Config ),
977+
978+ OpenStep = fun ({0 = Ch , # 'v1_0.open' {}, _Pay }) ->
979+ {Ch , [# 'v1_0.open' {container_id = {utf8 , <<" mock" >>}}]}
980+ end ,
981+ BeginStep = fun ({0 = Ch , # 'v1_0.begin' {}, _Pay }) ->
982+ {Ch , [# 'v1_0.begin' {remote_channel = {ushort , Ch },
983+ next_outgoing_id = {uint , 1 },
984+ incoming_window = {uint , 1000 },
985+ outgoing_window = {uint , 1000 }}
986+ ]}
987+ end ,
988+ AttachStep = fun ({0 = Ch , # 'v1_0.attach' {role = true ,
989+ name = Name ,
990+ source = # 'v1_0.source' {
991+ capabilities = {symbol , <<" capability-1" >>}}
992+ }, <<>>}) ->
993+ {Ch , [# 'v1_0.attach' {name = Name ,
994+ handle = {uint , 99 },
995+ initial_delivery_count = {uint , 1 },
996+ role = false }
997+ ]}
998+ end ,
999+
1000+ LinkCreditStep = fun ({0 = Ch , # 'v1_0.flow' {}, <<>>}) ->
1001+ {Ch , {multi , [[# 'v1_0.transfer' {handle = {uint , 99 },
1002+ delivery_id = {uint , 12 },
1003+ more = true },
1004+ # 'v1_0.data' {content = <<" hello " >>}],
1005+ [# 'v1_0.transfer' {handle = {uint , 99 },
1006+ % delivery_id can be omitted
1007+ % for continuation frames
1008+ delivery_id = undefined ,
1009+ settled = undefined ,
1010+ more = false },
1011+ # 'v1_0.data' {content = <<" world" >>}]
1012+ ]}}
1013+ end ,
1014+ Steps = [fun mock_server :recv_amqp_header_step /1 ,
1015+ fun mock_server :send_amqp_header_step /1 ,
1016+ mock_server :amqp_step (OpenStep ),
1017+ mock_server :amqp_step (BeginStep ),
1018+ mock_server :amqp_step (AttachStep ),
1019+ mock_server :amqp_step (LinkCreditStep )
1020+ ],
1021+
1022+ ok = mock_server :set_steps (? config (mock_server , Config ), Steps ),
1023+
1024+ Cfg = #{address => Hostname , port => Port , sasl => none , notify => self ()},
1025+ {ok , Connection } = amqp10_client :open_connection (Cfg ),
1026+ {ok , Session } = amqp10_client :begin_session_sync (Connection ),
1027+ AttachArgs = #{name => <<" mock1-received" >>,
1028+ role => {receiver , #{address => <<" test" >>,
1029+ durable => none ,
1030+ capabilities => <<" capability-1" >>}, self ()},
1031+ snd_settle_mode => setlled ,
1032+ rcv_settle_mode => first ,
1033+ filter => #{},
1034+ properties => #{}},
1035+ {ok , Receiver } = amqp10_client :attach_link (Session , AttachArgs ),
1036+ amqp10_client :flow_link_credit (Receiver , 100 , 50 ),
1037+ receive
1038+ {amqp10_msg , Receiver , _InMsg } ->
1039+ ok
1040+ after 2000 ->
1041+ exit (delivery_timeout )
1042+ end ,
1043+
1044+ ok = amqp10_client :end_session (Session ),
1045+ ok = amqp10_client :close_connection (Connection ),
1046+ ok .
1047+
9171048% %% HELPERS
9181049% %%
9191050
0 commit comments