2017-01-03 00:31:59 +08:00
|
|
|
%% The contents of this file are subject to the Mozilla Public License
|
|
|
|
|
%% Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
|
%% compliance with the License. You may obtain a copy of the License at
|
|
|
|
|
%% http://www.mozilla.org/MPL/
|
|
|
|
|
%%
|
|
|
|
|
%% Software distributed under the License is distributed on an "AS IS"
|
|
|
|
|
%% basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
|
|
|
|
|
%% License for the specific language governing rights and limitations
|
|
|
|
|
%% under the License.
|
|
|
|
|
%%
|
|
|
|
|
%% The Original Code is RabbitMQ.
|
|
|
|
|
%%
|
|
|
|
|
%% The Initial Developer of the Original Code is GoPivotal, Inc.
|
|
|
|
|
%% Copyright (c) 2017 Pivotal Software, Inc. All rights reserved.
|
|
|
|
|
%%
|
|
|
|
|
|
|
|
|
|
-module(system_SUITE).
|
|
|
|
|
|
|
|
|
|
-include_lib("common_test/include/ct.hrl").
|
2017-01-09 20:17:52 +08:00
|
|
|
-include_lib("eunit/include/eunit.hrl").
|
2017-01-03 00:31:59 +08:00
|
|
|
|
2017-01-11 23:07:14 +08:00
|
|
|
-include_lib("amqp10_common/include/amqp10_framing.hrl").
|
|
|
|
|
|
2017-01-03 00:31:59 +08:00
|
|
|
-include("amqp10_client.hrl").
|
|
|
|
|
|
|
|
|
|
-compile(export_all).
|
|
|
|
|
|
|
|
|
|
-define(UNAUTHORIZED_USER, <<"test_user_no_perm">>).
|
|
|
|
|
|
|
|
|
|
%% The latch constant defines how many processes are spawned in order
|
|
|
|
|
%% to run certain functionality in parallel. It follows the standard
|
|
|
|
|
%% countdown latch pattern.
|
|
|
|
|
-define(LATCH, 100).
|
|
|
|
|
|
|
|
|
|
%% The wait constant defines how long a consumer waits before it
|
|
|
|
|
%% unsubscribes
|
|
|
|
|
-define(WAIT, 200).
|
|
|
|
|
|
|
|
|
|
%% How to long wait for a process to die after an expected failure
|
|
|
|
|
-define(PROCESS_EXIT_TIMEOUT, 5000).
|
|
|
|
|
|
|
|
|
|
all() ->
|
|
|
|
|
[
|
2017-01-09 20:17:52 +08:00
|
|
|
{group, rabbitmq},
|
|
|
|
|
{group, activemq}
|
2017-01-03 00:31:59 +08:00
|
|
|
].
|
|
|
|
|
|
|
|
|
|
groups() ->
|
|
|
|
|
[
|
2017-03-28 18:21:03 +08:00
|
|
|
{rabbitmq, [], shared()},
|
|
|
|
|
{activemq, [], shared()},
|
2017-01-24 00:12:59 +08:00
|
|
|
{mock, [], [
|
2017-02-16 18:57:22 +08:00
|
|
|
insufficient_credit,
|
|
|
|
|
incoming_heartbeat
|
2017-01-24 00:12:59 +08:00
|
|
|
]}
|
2017-01-03 00:31:59 +08:00
|
|
|
].
|
|
|
|
|
|
2017-03-28 18:21:03 +08:00
|
|
|
shared() ->
|
|
|
|
|
[
|
|
|
|
|
open_close_connection,
|
|
|
|
|
basic_roundtrip,
|
|
|
|
|
early_transfer,
|
|
|
|
|
split_transfer,
|
|
|
|
|
transfer_unsettled,
|
|
|
|
|
subscribe,
|
|
|
|
|
outgoing_heartbeat
|
|
|
|
|
].
|
|
|
|
|
|
2017-01-03 00:31:59 +08:00
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
%% Testsuite setup/teardown.
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
init_per_suite(Config) ->
|
|
|
|
|
rabbit_ct_helpers:log_environment(),
|
2017-01-09 20:17:52 +08:00
|
|
|
rabbit_ct_helpers:run_setup_steps(Config,
|
2017-01-03 00:31:59 +08:00
|
|
|
[
|
|
|
|
|
fun start_amqp10_client_app/1
|
|
|
|
|
]).
|
|
|
|
|
|
|
|
|
|
end_per_suite(Config) ->
|
2017-01-09 20:17:52 +08:00
|
|
|
rabbit_ct_helpers:run_teardown_steps(Config,
|
2017-01-03 00:31:59 +08:00
|
|
|
[
|
|
|
|
|
fun stop_amqp10_client_app/1
|
2017-01-09 20:17:52 +08:00
|
|
|
]).
|
2017-01-03 00:31:59 +08:00
|
|
|
|
|
|
|
|
start_amqp10_client_app(Config) ->
|
2017-01-11 23:07:14 +08:00
|
|
|
?assertMatch({ok, _}, application:ensure_all_started(amqp10_client)),
|
2017-01-03 00:31:59 +08:00
|
|
|
Config.
|
|
|
|
|
|
|
|
|
|
stop_amqp10_client_app(Config) ->
|
2017-01-11 23:07:14 +08:00
|
|
|
ok = application:stop(amqp10_client),
|
2017-01-03 00:31:59 +08:00
|
|
|
Config.
|
|
|
|
|
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
%% Groups.
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
2017-01-09 20:17:52 +08:00
|
|
|
init_per_group(rabbitmq, Config) ->
|
|
|
|
|
rabbit_ct_helpers:run_steps(
|
|
|
|
|
Config,
|
|
|
|
|
rabbit_ct_broker_helpers:setup_steps());
|
|
|
|
|
init_per_group(activemq, Config) ->
|
|
|
|
|
rabbit_ct_helpers:run_steps(
|
|
|
|
|
Config,
|
2017-01-24 00:12:59 +08:00
|
|
|
activemq_ct_helpers:setup_steps());
|
|
|
|
|
init_per_group(mock, Config) ->
|
|
|
|
|
rabbit_ct_helpers:set_config(Config, [{mock_port, 21000},
|
|
|
|
|
{mock_host, "localhost"}
|
|
|
|
|
]).
|
2017-01-09 20:17:52 +08:00
|
|
|
|
|
|
|
|
end_per_group(rabbitmq, Config) ->
|
|
|
|
|
rabbit_ct_helpers:run_steps(
|
|
|
|
|
Config,
|
|
|
|
|
rabbit_ct_broker_helpers:teardown_steps());
|
|
|
|
|
end_per_group(activemq, Config) ->
|
|
|
|
|
rabbit_ct_helpers:run_steps(
|
|
|
|
|
Config,
|
2017-01-24 00:12:59 +08:00
|
|
|
activemq_ct_helpers:teardown_steps());
|
|
|
|
|
end_per_group(mock, Config) ->
|
|
|
|
|
Config.
|
2017-01-03 00:31:59 +08:00
|
|
|
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
%% Test cases.
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
2017-01-24 00:12:59 +08:00
|
|
|
init_per_testcase(_Test, Config) ->
|
|
|
|
|
case lists:keyfind(mock_port, 1, Config) of
|
|
|
|
|
{_, Port} ->
|
|
|
|
|
M = mock_server:start(Port),
|
|
|
|
|
rabbit_ct_helpers:set_config(Config, {mock_server, M});
|
|
|
|
|
_ -> Config
|
|
|
|
|
end.
|
2017-01-03 00:31:59 +08:00
|
|
|
|
2017-01-24 00:12:59 +08:00
|
|
|
end_per_testcase(_Test, Config) ->
|
|
|
|
|
case lists:keyfind(mock_server, 1, Config) of
|
|
|
|
|
{_, M} -> mock_server:stop(M);
|
|
|
|
|
_ -> Config
|
|
|
|
|
end.
|
2017-01-03 00:31:59 +08:00
|
|
|
|
|
|
|
|
%% -------------------------------------------------------------------
|
|
|
|
|
|
2017-01-24 00:12:59 +08:00
|
|
|
open_close_connection(Config) ->
|
|
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
2017-01-24 18:09:06 +08:00
|
|
|
OpnConf = #{address => Hostname, port => Port,
|
2017-01-24 18:49:56 +08:00
|
|
|
notify => self(),
|
2017-01-24 18:09:06 +08:00
|
|
|
container_id => <<"open_close_connection_container">>},
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(Hostname, Port),
|
|
|
|
|
{ok, Connection2} = amqp10_client:open_connection(OpnConf),
|
|
|
|
|
receive
|
|
|
|
|
{amqp10_event, {connection, Connection2, opened}} -> ok
|
|
|
|
|
after 5000 -> connection_timeout
|
|
|
|
|
end,
|
|
|
|
|
ok = amqp10_client:close_connection(Connection2),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection).
|
2017-01-24 00:12:59 +08:00
|
|
|
|
2017-01-12 20:38:14 +08:00
|
|
|
basic_roundtrip(Config) ->
|
2017-01-03 00:31:59 +08:00
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
2017-01-09 20:17:52 +08:00
|
|
|
ct:pal("Opening connection to ~s:~b", [Hostname, Port]),
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(Hostname, Port),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session(Connection),
|
2017-03-24 18:51:52 +08:00
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link(Session,
|
|
|
|
|
<<"banana-sender">>,
|
|
|
|
|
<<"test">>),
|
2017-03-28 18:21:03 +08:00
|
|
|
await_link({sender, <<"banana-sender">>}, attached, link_attach_timeout),
|
|
|
|
|
|
2017-01-11 23:27:26 +08:00
|
|
|
Msg = amqp10_msg:new(<<"my-tag">>, <<"banana">>, true),
|
2017-03-25 00:19:43 +08:00
|
|
|
ok = amqp10_client:send_msg(Sender, Msg),
|
2017-03-25 01:39:43 +08:00
|
|
|
ok = amqp10_client:detach_link(Sender),
|
2017-03-28 18:21:03 +08:00
|
|
|
await_link({sender, <<"banana-sender">>}, detached, link_detach_timeout),
|
|
|
|
|
|
|
|
|
|
{error, link_not_found} = amqp10_client:detach_link(Sender),
|
2017-03-25 00:19:43 +08:00
|
|
|
{ok, Receiver} = amqp10_client:attach_receiver_link(Session,
|
|
|
|
|
<<"banana-receiver">>,
|
|
|
|
|
<<"test">>),
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, OutMsg} = amqp10_client:get_msg(Receiver),
|
|
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection),
|
2017-03-24 18:51:52 +08:00
|
|
|
?assertEqual([<<"banana">>], amqp10_msg:body(OutMsg)),
|
|
|
|
|
ok.
|
2017-01-12 20:38:14 +08:00
|
|
|
|
2017-03-28 18:21:03 +08:00
|
|
|
% a message is sent before the link attach is guaranteed to
|
|
|
|
|
% have completed and link credit granted
|
|
|
|
|
% also queue a link detached immediately after transfer
|
|
|
|
|
early_transfer(Config) ->
|
|
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
|
|
|
|
{ok, Connection} = amqp10_client:open_connection(Hostname, Port),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session(Connection),
|
|
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link(Session,
|
|
|
|
|
<<"early-transfer">>,
|
|
|
|
|
<<"test">>),
|
|
|
|
|
|
|
|
|
|
Msg = amqp10_msg:new(<<"my-tag">>, <<"banana">>, true),
|
|
|
|
|
% TODO: this is a timing issue - should use mock here really
|
|
|
|
|
{error, half_attached} = amqp10_client:send_msg(Sender, Msg),
|
|
|
|
|
% wait for credit
|
|
|
|
|
await_link({sender, <<"early-transfer">>}, credited, credited_timeout),
|
|
|
|
|
ok = amqp10_client:detach_link(Sender),
|
|
|
|
|
% attach then immediately detach
|
|
|
|
|
LinkName = <<"early-transfer2">>,
|
|
|
|
|
{ok, Sender2} = amqp10_client:attach_sender_link(Session, LinkName,
|
|
|
|
|
<<"test">>),
|
|
|
|
|
{error, half_attached} = amqp10_client:detach_link(Sender2),
|
|
|
|
|
await_link({sender, <<"early-transfer2">>}, credited, credited_timeout),
|
|
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection),
|
|
|
|
|
ok.
|
|
|
|
|
|
2017-01-12 20:38:14 +08:00
|
|
|
split_transfer(Config) ->
|
|
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
|
|
|
|
ct:pal("Opening connection to ~s:~b", [Hostname, Port]),
|
|
|
|
|
Conf = #{address => Hostname, port => Port, max_frame_size => 512},
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(Conf),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session(Connection),
|
2017-01-12 20:38:14 +08:00
|
|
|
Data = list_to_binary(string:chars(64, 1000)),
|
2017-03-28 18:21:03 +08:00
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link_sync(Session, <<"data-sender">>,
|
|
|
|
|
<<"test">>),
|
2017-01-12 20:38:14 +08:00
|
|
|
Msg = amqp10_msg:new(<<"my-tag">>, Data, true),
|
2017-03-25 00:19:43 +08:00
|
|
|
ok = amqp10_client:send_msg(Sender, Msg),
|
|
|
|
|
{ok, Receiver} = amqp10_client:attach_receiver_link(Session,
|
|
|
|
|
<<"data-receiver">>,
|
|
|
|
|
<<"test">>),
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, OutMsg} = amqp10_client:get_msg(Receiver),
|
|
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection),
|
2017-01-12 20:38:14 +08:00
|
|
|
?assertEqual([Data], amqp10_msg:body(OutMsg)).
|
2017-01-18 18:44:19 +08:00
|
|
|
|
|
|
|
|
transfer_unsettled(Config) ->
|
|
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
|
|
|
|
Conf = #{address => Hostname, port => Port},
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(Conf),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session(Connection),
|
2017-01-18 18:44:19 +08:00
|
|
|
Data = list_to_binary(string:chars(64, 1000)),
|
2017-03-28 18:21:03 +08:00
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link_sync(Session,
|
|
|
|
|
<<"data-sender">>,
|
|
|
|
|
<<"test">>, unsettled),
|
2017-03-25 00:19:43 +08:00
|
|
|
DeliveryTag = <<"my-tag">>,
|
|
|
|
|
Msg = amqp10_msg:new(DeliveryTag, Data, false),
|
|
|
|
|
ok = amqp10_client:send_msg(Sender, Msg),
|
|
|
|
|
ok = await_disposition(DeliveryTag),
|
2017-03-28 18:21:03 +08:00
|
|
|
{ok, Receiver} = amqp10_client:attach_receiver_link(Session,
|
|
|
|
|
<<"data-receiver">>,
|
2017-02-18 01:39:01 +08:00
|
|
|
<<"test">>, unsettled),
|
|
|
|
|
{ok, OutMsg} = amqp10_client:get_msg(Receiver),
|
|
|
|
|
ok = amqp10_client:accept_msg(Receiver, OutMsg),
|
|
|
|
|
{error, timeout} = amqp10_client:get_msg(Receiver, 1000),
|
|
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection),
|
2017-01-19 01:03:02 +08:00
|
|
|
?assertEqual([Data], amqp10_msg:body(OutMsg)).
|
2017-01-21 01:38:54 +08:00
|
|
|
|
2017-01-24 19:38:41 +08:00
|
|
|
subscribe(Config) ->
|
2017-01-21 01:38:54 +08:00
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
2017-01-24 19:38:41 +08:00
|
|
|
QueueName = <<"test-sub">>,
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(Hostname, Port),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session(Connection),
|
2017-03-28 18:21:03 +08:00
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link_sync(Session,
|
|
|
|
|
<<"sub-sender">>,
|
|
|
|
|
QueueName),
|
2017-03-25 00:19:43 +08:00
|
|
|
Tag1 = <<"t1">>,
|
|
|
|
|
Tag2 = <<"t2">>,
|
|
|
|
|
Msg1 = amqp10_msg:new(Tag1, <<"banana">>, false),
|
|
|
|
|
Msg2 = amqp10_msg:new(Tag2, <<"banana">>, false),
|
|
|
|
|
ok = amqp10_client:send_msg(Sender, Msg1),
|
|
|
|
|
ok = await_disposition(Tag1),
|
|
|
|
|
ok = amqp10_client:send_msg(Sender, Msg2),
|
|
|
|
|
ok = await_disposition(Tag2),
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Receiver} = amqp10_client:attach_receiver_link(Session, <<"sub-receiver">>,
|
2017-01-24 19:38:41 +08:00
|
|
|
QueueName, unsettled),
|
2017-02-18 01:39:01 +08:00
|
|
|
ok = amqp10_client:flow_link_credit(Receiver, 2),
|
2017-01-24 19:38:41 +08:00
|
|
|
|
|
|
|
|
ok = receive_one(Receiver),
|
|
|
|
|
ok = receive_one(Receiver),
|
|
|
|
|
timeout = receive_one(Receiver),
|
2017-01-21 01:38:54 +08:00
|
|
|
|
2017-02-18 01:39:01 +08:00
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection).
|
2017-01-24 00:12:59 +08:00
|
|
|
|
|
|
|
|
|
2017-01-24 00:35:03 +08:00
|
|
|
insufficient_credit(Config) ->
|
2017-01-24 00:12:59 +08:00
|
|
|
Hostname = ?config(mock_host, Config),
|
|
|
|
|
Port = ?config(mock_port, Config),
|
|
|
|
|
OpenStep = fun({0 = Ch, #'v1_0.open'{}, _Pay}) ->
|
|
|
|
|
{Ch, [#'v1_0.open'{container_id = {utf8, <<"mock">>}}]}
|
|
|
|
|
end,
|
|
|
|
|
BeginStep = fun({1 = Ch, #'v1_0.begin'{}, _Pay}) ->
|
|
|
|
|
{Ch, [#'v1_0.begin'{remote_channel = {ushort, 1},
|
|
|
|
|
next_outgoing_id = {uint, 1},
|
|
|
|
|
incoming_window = {uint, 1000},
|
|
|
|
|
outgoing_window = {uint, 1000}}
|
|
|
|
|
]}
|
|
|
|
|
end,
|
2017-01-24 00:35:03 +08:00
|
|
|
AttachStep = fun({1 = Ch, #'v1_0.attach'{role = false,
|
|
|
|
|
name = Name}, <<>>}) ->
|
2017-01-24 00:12:59 +08:00
|
|
|
{Ch, [#'v1_0.attach'{name = Name,
|
|
|
|
|
handle = {uint, 99},
|
|
|
|
|
role = true}]}
|
|
|
|
|
end,
|
2017-02-16 18:57:22 +08:00
|
|
|
Steps = [fun mock_server:recv_amqp_header_step/1,
|
2017-01-24 00:12:59 +08:00
|
|
|
fun mock_server:send_amqp_header_step/1,
|
|
|
|
|
mock_server:amqp_step(OpenStep),
|
|
|
|
|
mock_server:amqp_step(BeginStep),
|
2017-02-16 18:57:22 +08:00
|
|
|
mock_server:amqp_step(AttachStep)],
|
2017-01-24 00:12:59 +08:00
|
|
|
|
|
|
|
|
ok = mock_server:set_steps(?config(mock_server, Config), Steps),
|
|
|
|
|
|
2017-02-18 01:39:01 +08:00
|
|
|
Cfg = #{address => Hostname, port => Port, sasl => none, notify => self()},
|
|
|
|
|
{ok, Connection} = amqp10_client:open_connection(Cfg),
|
|
|
|
|
{ok, Session} = amqp10_client:begin_session_sync(Connection),
|
|
|
|
|
{ok, Sender} = amqp10_client:attach_sender_link(Session, <<"mock1-sender">>,
|
|
|
|
|
<<"test">>),
|
2017-01-24 00:35:03 +08:00
|
|
|
Msg = amqp10_msg:new(<<"mock-tag">>, <<"banana">>, true),
|
2017-02-18 01:39:01 +08:00
|
|
|
{error, insufficient_credit} = amqp10_client:send_msg(Sender, Msg),
|
2017-01-24 00:35:03 +08:00
|
|
|
|
2017-02-18 01:39:01 +08:00
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection),
|
2017-01-24 00:12:59 +08:00
|
|
|
ok.
|
2017-01-24 19:38:41 +08:00
|
|
|
|
|
|
|
|
|
2017-02-16 18:57:22 +08:00
|
|
|
outgoing_heartbeat(Config) ->
|
|
|
|
|
Hostname = ?config(rmq_hostname, Config),
|
|
|
|
|
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
|
|
|
|
|
CConf = #{address => Hostname, port => Port,
|
|
|
|
|
idle_time_out => 5000},
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(CConf),
|
2017-02-16 18:57:22 +08:00
|
|
|
timer:sleep(35 * 1000), % activemq defaults to 15s I believe
|
|
|
|
|
% check we can still establish a session
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Session} = amqp10_client:begin_session_sync(Connection),
|
|
|
|
|
ok = amqp10_client:end_session(Session),
|
|
|
|
|
ok = amqp10_client:close_connection(Connection).
|
2017-02-16 18:57:22 +08:00
|
|
|
|
|
|
|
|
incoming_heartbeat(Config) ->
|
|
|
|
|
Hostname = ?config(mock_host, Config),
|
|
|
|
|
Port = ?config(mock_port, Config),
|
|
|
|
|
OpenStep = fun({0 = Ch, #'v1_0.open'{}, _Pay}) ->
|
|
|
|
|
{Ch, [#'v1_0.open'{container_id = {utf8, <<"mock">>},
|
|
|
|
|
idle_time_out = {uint, 0}}]}
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
|
|
CloseStep = fun({0 = Ch, #'v1_0.close'{error = _TODO}, _Pay}) ->
|
|
|
|
|
{Ch, [#'v1_0.close'{}]}
|
|
|
|
|
end,
|
|
|
|
|
Steps = [fun mock_server:recv_amqp_header_step/1,
|
|
|
|
|
fun mock_server:send_amqp_header_step/1,
|
|
|
|
|
mock_server:amqp_step(OpenStep),
|
|
|
|
|
mock_server:amqp_step(CloseStep)],
|
|
|
|
|
Mock = {_, MockPid} = ?config(mock_server, Config),
|
|
|
|
|
MockRef = monitor(process, MockPid),
|
|
|
|
|
ok = mock_server:set_steps(Mock, Steps),
|
|
|
|
|
CConf = #{address => Hostname, port => Port, sasl => none,
|
|
|
|
|
idle_time_out => 1000, notify => self()},
|
2017-02-18 01:39:01 +08:00
|
|
|
{ok, Connection} = amqp10_client:open_connection(CConf),
|
2017-02-16 18:57:22 +08:00
|
|
|
receive
|
2017-02-18 01:39:01 +08:00
|
|
|
{amqp10_event, {connection, Connection,
|
|
|
|
|
{closed, {resource_limit_exceeded, <<"remote idle-time-out">>}}}} ->
|
2017-02-16 18:57:22 +08:00
|
|
|
ok
|
|
|
|
|
after 5000 ->
|
|
|
|
|
exit(incoming_heartbeat_assert)
|
|
|
|
|
end,
|
|
|
|
|
demonitor(MockRef).
|
2017-01-24 19:38:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
%%% HELPERS
|
2017-02-18 01:39:01 +08:00
|
|
|
%%%
|
2017-01-24 19:38:41 +08:00
|
|
|
|
|
|
|
|
receive_one(Receiver) ->
|
2017-02-18 01:39:01 +08:00
|
|
|
Handle = amqp10_client:link_handle(Receiver),
|
2017-01-24 19:38:41 +08:00
|
|
|
receive
|
2017-02-18 01:39:01 +08:00
|
|
|
{amqp10_msg, Handle, Msg} ->
|
|
|
|
|
amqp10_client:accept_msg(Receiver, Msg)
|
2017-01-24 19:38:41 +08:00
|
|
|
after 2000 ->
|
|
|
|
|
timeout
|
|
|
|
|
end.
|
2017-02-07 19:22:34 +08:00
|
|
|
|
2017-03-25 00:19:43 +08:00
|
|
|
await_disposition(DeliveryTag) ->
|
2017-02-07 19:22:34 +08:00
|
|
|
receive
|
2017-03-25 00:19:43 +08:00
|
|
|
{amqp10_disposition, {accepted, DeliveryTag}} -> ok
|
2017-02-07 19:22:34 +08:00
|
|
|
after 3000 -> exit(dispostion_timeout)
|
|
|
|
|
end.
|
2017-03-28 18:21:03 +08:00
|
|
|
|
|
|
|
|
await_link(Who, What, Err) ->
|
|
|
|
|
receive
|
|
|
|
|
{amqp10_event, {link, Who, What}} ->
|
|
|
|
|
ok
|
|
|
|
|
after 5000 -> exit(Err)
|
|
|
|
|
end.
|