Commits

Anonymous committed 4246ea1

Downgrade rabbitmq-erlang-client from arbitrary unknown revision to 1_6_0 tag. Make some tests pass.

Comments (0)

Files changed (22)

deps/rabbitmq-erlang-client/Makefile

 #
 
 EBIN_DIR=ebin
-export INCLUDE_DIR=include
-export INCLUDE_SERV_DIR=$(BROKER_SYMLINK)/include
-TEST_DIR=test
 SOURCE_DIR=src
+TEST_SOURCE_DIR=tests
+INCLUDE_DIR=include
 DIST_DIR=rabbitmq-erlang-client
 
+LOAD_PATH=ebin rabbitmq_server/ebin
+
 INCLUDES=$(wildcard $(INCLUDE_DIR)/*.hrl)
 SOURCES=$(wildcard $(SOURCE_DIR)/*.erl)
-TARGETS=$(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam, $(SOURCES))
-TEST_SOURCES=$(wildcard $(TEST_DIR)/*.erl)
-TEST_TARGETS=$(patsubst $(TEST_DIR)/%.erl, $(TEST_DIR)/%.beam, $(TEST_SOURCES))
+TEST_SOURCES=$(wildcard $(TEST_SOURCE_DIR)/*.erl)
+TARGETS=$(patsubst $(SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(SOURCES))
+TEST_TARGETS=$(patsubst $(TEST_SOURCE_DIR)/%.erl, $(EBIN_DIR)/%.beam,$(TEST_SOURCES))
 
-LOAD_PATH=$(EBIN_DIR) $(BROKER_SYMLINK)/ebin $(TEST_DIR)
-
-ifndef USE_SPECS
-# our type specs rely on features / bug fixes in dialyzer that are
-# only available in R12B-3 upwards
-#
-# NB: the test assumes that version number will only contain single digits
-export USE_SPECS=$(shell if [ $$(erl -noshell -eval 'io:format(erlang:system_info(version)), halt().') \> "5.6.2" ]; then echo "true"; else echo "false"; fi)
-endif
-
-ERLC_OPTS=-I $(INCLUDE_DIR) -I $(INCLUDE_SERV_DIR) -o $(EBIN_DIR) -Wall -v +debug_info $(shell [ $(USE_SPECS) = "true" ] && echo "-Duse_specs")
-
-LOG_BASE=/tmp
-LOG_IN_FILE=true
-ERL_WITH_BROKER=erl -pa $(LOAD_PATH) -mnesia dir tmp -boot start_sasl -s rabbit \
-	$(shell [ $(LOG_IN_FILE) = "true" ] && echo "-sasl sasl_error_logger '{file, \"'${LOG_BASE}'/rabbit-sasl.log\"}' -kernel error_logger '{file, \"'${LOG_BASE}'/rabbit.log\"}'")
-
-PLT=$(HOME)/.dialyzer_plt
-DIALYZER_CALL=dialyzer --plt $(PLT)
+ERLC_OPTS=-I $(INCLUDE_DIR) -o $(EBIN_DIR) -Wall -v +debug_info
 
 BROKER_DIR=../rabbitmq-server
 BROKER_SYMLINK=rabbitmq_server
 
+NODENAME=rabbit_test_direct
+MNESIA_DIR=/tmp/rabbitmq_$(NODENAME)_mnesia
+LOG_BASE=/tmp
+
+ERL_CALL=erl_call -sname $(NODENAME) -e
 
 all: compile
 
-compile: $(TARGETS)
+compile: $(EBIN_DIR) $(TARGETS)
 
-compile_tests: $(TEST_DIR)
-
-
-dialyze: $(TARGETS)
-	$(DIALYZER_CALL) -c $^
-
-dialyze_all: $(TARGETS) $(TEST_TARGETS)
-	$(DIALYZER_CALL) -c $^
-
-add_broker_to_plt: $(BROKER_SYMLINK)/ebin
-	$(DIALYZER_CALL) --add_to_plt -r $<
-
-$(TEST_TARGETS): $(TEST_DIR)
-
-.PHONY: $(TEST_DIR)
-$(TEST_DIR): $(BROKER_SYMLINK)
-	$(MAKE) -C $(TEST_DIR)
+compile_tests: $(EBIN_DIR) $(TEST_TARGETS)
 
 $(BROKER_SYMLINK):
 ifdef BROKER_DIR
 	ln -sf $(BROKER_DIR) $(BROKER_SYMLINK)
 endif
 
+$(EBIN_DIR):
+	mkdir -p $@
+
 $(EBIN_DIR)/%.beam: $(SOURCE_DIR)/%.erl $(INCLUDES) $(BROKER_SYMLINK)
-	mkdir -p $(EBIN_DIR); erlc $(ERLC_OPTS) $<
+	erlc $(ERLC_OPTS) $<
 
+$(EBIN_DIR)/%.beam: $(TEST_SOURCE_DIR)/%.erl $(INCLUDES) $(BROKER_SYMLINK)
+	erlc $(ERLC_OPTS) $<
 
-run: compile
+run:
 	erl -pa $(LOAD_PATH)
 
-run_with_broker: compile
-	$(ERL_WITH_BROKER)
 
+all_tests: test_network test_network_coverage test_direct test_direct_coverage
+	$(ERL_CALL) -q
 
-all_tests: compile compile_tests
-	echo $(ERL_WITH_BROKER)
-	$(ERL_WITH_BROKER) -eval 'network_client_SUITE:test(),direct_client_SUITE:test(),halt()'
-
-all_tests_coverage: compile compile_tests
-	$(ERL_WITH_BROKER) -eval 'rabbit_misc:enable_cover(),network_client_SUITE:test(),direct_client_SUITE:test(),rabbit_misc:report_cover(),halt()'
+tests_network: test_network test_network_coverage
+	$(ERL_CALL) -q
 
 test_network: compile compile_tests
-	$(ERL_WITH_BROKER) -eval 'network_client_SUITE:test(),halt().'
+	erl -pa $(LOAD_PATH) -noshell -eval 'network_client_test:test(),halt().'
 
 test_network_coverage: compile compile_tests
-	$(ERL_WITH_BROKER) -eval 'network_client_SUITE:test_coverage(),halt().'
+	erl -pa $(LOAD_PATH) -noshell -eval 'network_client_test:test_coverage(),halt().'
+
+tests_direct: test_direct test_direct_coverage
+	$(ERL_CALL) -q
+	rm -rf $(MNESIA_DIR)
 
 test_direct: compile compile_tests
-	$(ERL_WITH_BROKER) -eval 'direct_client_SUITE:test(),halt().'
+	erl -pa $(LOAD_PATH) -noshell -mnesia dir tmp -boot start_sasl -s rabbit -noshell \
+	-sasl sasl_error_logger '{file, "'${LOG_BASE}'/rabbit-sasl.log"}' \
+	-kernel error_logger '{file, "'${LOG_BASE}'/rabbit.log"}' \
+	-eval 'direct_client_test:test(),halt().'
 
 test_direct_coverage: compile compile_tests
-	$(ERL_WITH_BROKER) -eval 'direct_client_SUITE:test_coverage(),halt().'
-
+	erl -pa $(LOAD_PATH) -noshell -mnesia dir tmp -boot start_sasl -s rabbit -noshell \
+	-sasl sasl_error_logger '{file, "'${LOG_BASE}'/rabbit-sasl.log"}' \
+	-kernel error_logger '{file, "'${LOG_BASE}'/rabbit.log"}' \
+	-eval 'direct_client_test:test_coverage(),halt().'
 
 clean:
 	rm -f $(EBIN_DIR)/*.beam
 	rm -f rabbitmq_server erl_crash.dump
-	rm -fr cover dist tmp
-	$(MAKE) -C $(TEST_DIR) clean
+	rm -fr cover dist
 
 source_tarball:
 	mkdir -p dist/$(DIST_DIR)
-	cp -a README Makefile dist/$(DIST_DIR)/
-	mkdir -p dist/$(DIST_DIR)/$(SOURCE_DIR)
-	cp -a $(SOURCE_DIR)/*.erl dist/$(DIST_DIR)/$(SOURCE_DIR)/
-	mkdir -p dist/$(DIST_DIR)/$(INCLUDE_DIR)
-	cp -a $(INCLUDE_DIR)/*.hrl dist/$(DIST_DIR)/$(INCLUDE_DIR)/
-	mkdir -p dist/$(DIST_DIR)/$(TEST_DIR)
-	cp -a $(TEST_DIR)/*.erl dist/$(DIST_DIR)/$(TEST_DIR)/
-	cp -a $(TEST_DIR)/Makefile dist/$(DIST_DIR)/$(TEST_DIR)/
+	cp -a README Makefile src/*.erl include/*.hrl dist/$(DIST_DIR)
 	cd dist ; tar cvzf $(DIST_DIR).tar.gz $(DIST_DIR)
+

deps/rabbitmq-erlang-client/README

 
     $ make BROKER_DIR=PATH_TO_THE_SERVER
 
-Running the network and direct client tests
--------------------------------------------
-The direct client has to be run in the same Erlang VM instance as the
-RabbitMQ server. In order to use the makefile to run either the network or the
-direct client tests, you will need to shutdown any other running instance of
-RabbitMQ that you may have on your machine. This is because the Makefile targets
-for running the network or direct tests boot their own instance of RabbitMQ.
-To run these tests, use the either of the following targets:
+Running the network client tests
+--------------------------------
+In order to run the network client, you need to run the RabbitMQ
+server in a separate Erlang process (or use any other compliant AMQP
+server). Start your server as usual.
+
+After you have done this, you can run the unit tests:
 
     $ make test_network
+
+To get more examples of the API, look at the functions in the
+test_util module.
+
+Running the direct client tests
+-------------------------------
+The direct client has to be run in the same Erlang VM instance as the
+RabbitMQ server. In order to use the makefile to run the direct client tests,
+you will need to shutdown any other running instance of RabbitMQ that you may
+have on your machine. This is because the Makefile target for running the
+direct tests boots its own instance of RabbitMQ. To run these tests, use the
+following target.
+
     $ make test_direct
 
-Or to run both:
-
-    $ make all_tests
-
-The network client test can also be run from a separate Erlang VM instance from
-RabbitMQ server. You can start an instance of the server and then, in the
-rabbitmq-erlang-client folder, type
-
-    rabbitmq-erlang-client $ make compile_tests
-    rabbitmq-erlang-client $ make run
-    erl -pa ebin rabbitmq_server/ebin tests
-    Erlang (BEAM) emulator version 5.6.5 [source] [64-bit] [smp:4] \
-    [async-threads:0] [hipe] [kernel-poll:false]
-
-    Eshell V5.6.5  (abort with ^G)
-    1> network_client_SUITE:test().
-
-To get more examples of the API, look at the functions in the test_util module.
-
 Running the channel flow tests
 ------------------------------
 There are two tests for producer control flow. The first is a unit
 server. By default they are turned off. To turn them on, set the
 memory_alarms flag in the rabbit.app config file.
 
-First of all, in the *rabbitmq-erlang-client directory*, type
-
-    rabbitmq-erlang-client $ make compile_tests
-
-to make sure test modules are compiled.
-
 Because the unit test accesses memsup directly, it needs to use the
 direct API and hence needs to run in the same VM as the server. To do
-this from the *rabbitmq-erlang-client directory*, type
+this from the rabbitmq-erlang-client directory, run the following
+commmand (where SOME_DIRECTORY is some directory where you want mnesia
+to log its files):
 
-    rabbitmq-erlang-client $ make LOG_IN_FILE=false run_with_broker
+    $ erl -pa ebin rabbitmq_server/ebin -mnesia dir SOME_DIRECTORY \
+      -boot start_sasl -s rabbit
       
-When that has booted, you need to *wait one minute* for the memory
+When that has booted, you need to wait one minute for the memory
 alarms to become active. After that, you can run the following from
 the Erlang shell:
 
-    1> direct_client_SUITE:test_channel_flow().
+    1> direct_client_test:test_channel_flow().
 
     =INFO REPORT==== 17-Dec-2008::13:39:41 ===
     alarm_handler: {set,{system_memory_high_watermark,[]}}
 it produces log output which makes it difficult to enter in commands
 interactively (which you need to do to see the throttling).
 
-After *having booted* an *instance of the server* with alarms handlers
-turned on, run the following in the *rabbitmq-erlang-client directory*:
+After having booted an instance of the server with alarms handlers
+turned on, run the following in the rabbitmq-erlang-client directory:
 
-    rabbitmq-erlang-client $ make run
+    rabbitmq-erlang-client $ erl -pa rabbitmq_server/ebin/ ebin/
     Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] \
     [async-threads:0][kernel-poll:false]
 
     Producer (<0.39.0>) has sent about 5000 messages since it started
     Producer (<0.39.0>) has sent about 10000 messages since it started
       
-To throttle the producer, go to the *server shell* and turn the memory
+To throttle the producer, go to the server shell and turn the memory
 limit to some suitably low value:
     
     2> memsup:set_sysmem_high_watermark(0.01).
     ok
     
-Back in the *client shell*, you should see the following output:
+Back in the client shell, you should see the following output:
     .....
     Producer (<0.39.0>) has sent about 235000 messages since it started
     Producer throttling ON
     Producer (<0.39.0>) has woken up :-)
     Producer (<0.39.0>) has sent about 240000 messages since it started
     .....
-
-Make targets
-------------
-Interesting rabbitmq-erlang-client make targets include
-
-all
-    The default target. Builds the client (does not compile the tests).
-
-run
-    Builds the client and starts an Erlang shell with both the client and the
-    server in the load path.
-
-clean
-    Removes build products and wipes all files produced by any other
-    rabbitmq-erlang-client make targets or client errors.
-
-run_with_broker
-    Same as run, except that this make target also runs the broker when starting
-    the Erlang shell.
-
-dialyze
-    Analyses the client source code with dialyzer. Uses PLT file from default
-    location: ~/.dialyzer_plt. Use
-
-        $ make PLT=/path/to/plt dialyze
-
-    to override this. Add broker to PLT beforehand, otherwise you will a lot
-    of 'unknown function' warnings. See add_broker_to_plt make target.
-
-dialyze_all
-    Same as dialyze, except that this also analyses tests source code.
-
-add_broker_to_plt
-    Adds broker .beam files to default plt. Use
-
-        $ make PLT=/path/to/plt add_broker_to_plt
-
-    to override default plt location ( ~/.dialyzer_plt ).
-
-all_tests
-    Compiles client and client tests source code and runs network_client_SUITE
-    and direct_client_SUITE tests. During the testing, this make target runs an
-    instance of the broker, so make sure there is no other instance running.
-
-all_tests_coverage
-    Same as all_tests, except that the tests are run in coverage mode.
-
-source_tarball
-    Creates tarball of all the client source code.

deps/rabbitmq-erlang-client/include/amqp_client.hrl

                            channel_max,
                            heartbeat,
                            driver,
-                           port,
                            channels = dict:new() }).
 
 -record(channel_state, {number,

deps/rabbitmq-erlang-client/rabbit_common.app

-{application, rabbit_common,
- [{description, "RabbitMQ Common Libraries"},
-  {vsn, "1.6.0"},
-  {modules, [
-             rabbit_writer,
-             rabbit_reader,
-             rabbit_framing,
-             rabbit_framing_channel,
-             rabbit_binary_parser,
-             rabbit_binary_generator,
-             rabbit_channel,
-             rabbit_misc,
-             rabbit_heartbeat,
-             gen_server2
-  ]},
-  {registered, []},
-  {env, []},
-  {applications, [kernel, stdlib]}]}.

deps/rabbitmq-erlang-client/src/amqp_channel.erl

 
 -module(amqp_channel).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 -include_lib("stdlib/include/qlc.hrl").
 -include("amqp_client.hrl").
 
 
 %% Generic AMQP RPC mechanism that expects a pseudo synchronous response
 call(Channel, Method) ->
-    gen_server:call(Channel, {call, Method}, infinity).
+    gen_server:call(Channel, {call, Method}).
 
 %% Generic AMQP send mechanism with content
 call(Channel, Method, Content) ->
-    gen_server:call(Channel, {call, Method, Content}, infinity).
+    gen_server:call(Channel, {call, Method, Content}).
 
 %% Generic AMQP send mechanism that doesn't expect a response
 cast(Channel, Method) ->
 
 %% Registers a consumer pid with the channel
 subscribe(Channel, BasicConsume = #'basic.consume'{}, Consumer) ->
-    gen_server:call(Channel, {BasicConsume, Consumer}, infinity).
+    gen_server:call(Channel, {BasicConsume, Consumer}).
 
 
 %%---------------------------------------------------------------------------
                                               do2 = Do2}) ->
     NewRequestQueue =
         case queue:out(RequestQueue) of
-            {empty, _}              -> exit(empty_rpc_bottom_half);
-            {{value, {From, _}}, Q} -> gen_server:reply(From, Reply),
-                                       Q
+            {empty, {[], []}}        -> exit(empty_rpc_bottom_half);
+            {{value, {From, _}}, Q}  -> gen_server:reply(From, Reply),
+                                        Q
         end,
     case queue:is_empty(NewRequestQueue) of
         true  -> ok;
             error ->
                 case queue:out(Anon) of
                     {empty, _} ->
-                        exit({anonymous_queue_empty, ConsumerTag});
+                        exit(anonymous_queue_empty, ConsumerTag);
                     {{value, {F, C}}, NewAnon} ->
                         {F, C,
                          State#channel_state{anon_sub_requests = NewAnon}}

deps/rabbitmq-erlang-client/src/amqp_connection.erl

 
 -module(amqp_connection).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 -include("amqp_client.hrl").
 
 -behaviour(gen_server).
 -export([init/1, terminate/2, code_change/3, handle_call/3, handle_cast/2,
          handle_info/2]).
 -export([open_channel/1, open_channel/3]).
--export([start_direct/2, start_direct/3]).
--export([start_direct_link/2]).
--export([start_network/4, start_network/5]).
--export([start_network_link/4, start_network_link/5]).
--export([close/2]).
+-export([start/2, start/3, start/4, close/2]).
+-export([start_link/2, start_link/3, start_link/4]).
 
 %%---------------------------------------------------------------------------
 %% AMQP Connection API Methods
 
 %% Starts a direct connection to the Rabbit AMQP server, assuming that
 %% the server is running in the same process space.
-start_direct(User, Password) -> start_direct(User, Password, false).
-
-start_direct(User, Password, ProcLink) when is_boolean(ProcLink) ->
+start(User, Password) -> start(User, Password, false).
+start(User, Password, ProcLink) when is_boolean(ProcLink) ->
     InitialState = #connection_state{username = User,
                                      password = Password,
                                      vhostpath = <<"/">>},
     {ok, Pid} = start_internal(InitialState, amqp_direct_driver, ProcLink),
-    Pid.
-
-start_direct_link(User, Password) ->
-    start_direct(User, Password, true).
-
+    Pid;
 
 %% Starts a networked conection to a remote AMQP server.
-start_network(User, Password, Host, Port) ->
-    start_network(User, Password, Host, Port, <<"/">>, false).
+start(User, Password, Host) ->
+    start(User, Password, Host, <<"/">>, false).
 
-start_network(User, Password, Host, Port, VHost) ->
-    start_network(User, Password, Host, Port, VHost, false).
+start(User, Password, Host, VHost) ->
+    start(User, Password, Host, VHost, false).
 
-start_network(User, Password, Host, Port, VHost, ProcLink) ->
+start(User, Password, Host, VHost, ProcLink) ->
     InitialState = #connection_state{username = User,
                                      password = Password,
                                      serverhost = Host,
-                                     vhostpath = VHost,
-                                     port = Port},
+                                     vhostpath = VHost},
     {ok, Pid} = start_internal(InitialState, amqp_network_driver, ProcLink),
     Pid.
 
-start_network_link(User, Password, Host, Port) ->
-    start_network(User, Password, Host, Port, <<"/">>, true).
+start_link(User, Password) ->
+    start(User, Password, true).
 
-start_network_link(User, Password, Host, Port, VHost) ->
-    start_network(User, Password, Host, Port, VHost, true).
+start_link(User, Password, Host) ->
+    start(User, Password, Host, <<"/">>, true).
+
+start_link(User, Password, Host, VHost) ->
+    start(User, Password, Host, VHost, true).
 
 start_internal(InitialState, Driver, _Link = true) when is_atom(Driver) ->
     gen_server:start_link(?MODULE, [InitialState, Driver], []);
 open_channel(ConnectionPid, ChannelNumber, OutOfBand) ->
     gen_server:call(ConnectionPid,
                     {open_channel, ChannelNumber,
-                     amqp_util:binary(OutOfBand)}, infinity).
+                     amqp_util:binary(OutOfBand)}).
 
 %% Closes the AMQP connection
-close(ConnectionPid, Close) -> gen_server:call(ConnectionPid, Close, infinity).
+close(ConnectionPid, Close) -> gen_server:call(ConnectionPid, Close).
 
 %%---------------------------------------------------------------------------
 %% Internal plumbing
             do3               = fun(X, Y, Z) -> Driver:do(X, Y, Z) end,
             reader_pid        = ReaderPid,
             writer_pid        = WriterPid},
+    process_flag(trap_exit, true),
     {ok, ChannelPid} = gen_server:start_link(amqp_channel,
                                              [ChannelState], []),
     NewState = register_channel(Number, ChannelPid, State),
 %%---------------------------------------------------------------------------
 
 init([InitialState, Driver]) when is_atom(Driver) ->
-    process_flag(trap_exit, true),
     State = Driver:handshake(InitialState),
     {ok, State#connection_state{driver = Driver} }.
 
 handle_info( {'EXIT', _Pid, {socket_error, Reason}}, State) ->
     {stop, {socket_error, Reason}, State};
 
-handle_info( {'EXIT', _Pid, Reason = {unknown_message_type, _}}, State) ->
-    {stop, Reason, State};
-
-handle_info( {'EXIT', _Pid, Reason = connection_socket_closed_unexpectedly},
-             State) ->
-    {stop, Reason, State};
-
-handle_info( {'EXIT', _Pid, Reason = connection_timeout}, State) ->
-    {stop, Reason, State};
-
 handle_info( {'EXIT', Pid, Reason}, State) ->
     io:format("Connection: Handling exit from ~p --> ~p~n", [Pid, Reason]),
     {noreply, unregister_channel(Pid, State) }.

deps/rabbitmq-erlang-client/src/amqp_direct_driver.erl

 
 -module(amqp_direct_driver).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 -include("amqp_client.hrl").
 
 -export([handshake/1, open_channel/3, close_channel/1, close_connection/3]).
 handshake(ConnectionState = #connection_state{username = User,
                                               password = Pass,
                                               vhostpath = VHostPath}) ->
-    case lists:keymember(rabbit, 1, application:which_applications()) of
-        false -> throw(broker_not_found_in_vm);
-        true  -> ok
-    end,
     UserBin = amqp_util:binary(User),
     PassBin = amqp_util:binary(Pass),
     rabbit_access_control:user_pass_login(UserBin, PassBin),
-    rabbit_access_control:check_vhost_access(#user{username = UserBin,
-                                                   password = PassBin},
+    rabbit_access_control:check_vhost_access(#user{username = UserBin},
                                              VHostPath),
     ConnectionState.
 
 
 handle_broker_close(_State) ->
     ok.
+

deps/rabbitmq-erlang-client/src/amqp_network_driver.erl

 
 -module(amqp_network_driver).
 
--include_lib("rabbit_framing.hrl").
--include_lib("rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
 -include("amqp_client.hrl").
 
 -export([handshake/1, open_channel/3, close_channel/1, close_connection/3]).
 % Driver API Methods
 %---------------------------------------------------------------------------
 
-handshake(State = #connection_state{serverhost = Host, port = Port}) ->
-    case gen_tcp:connect(Host, Port, [binary, {packet, 0}, {active, false},
+handshake(State = #connection_state{serverhost = Host}) ->
+    case gen_tcp:connect(Host, 5672, [binary, {packet, 0}, {active, false},
                                       {nodelay, true}]) of
         {ok, Sock} ->
             ok = gen_tcp:send(Sock, amqp_util:protocol_header()),
     %% What happens if the following command reaches the server
     %% before the tune ok?
     %% Or doesn't get sent at all?
-    ConnectionOpen = #'connection.open'{virtual_host = VHostPath},
+    ConnectionOpen = #'connection.open'{virtual_host = VHostPath,
+                                        capabilities = <<"">>,
+                                        insist = false },
     do(Writer, ConnectionOpen),
     #'connection.open_ok'{} = recv(),
     %% TODO What should I do with the KnownHosts?
                             {<<"platform">>, longstr, <<"Erlang">>}
                            ],
            mechanism = <<"AMQPLAIN">>,
-           response = rabbit_binary_generator:generate_table(LoginTable)}.
+           response = rabbit_binary_generator:generate_table(LoginTable),
+           locale = <<"en_US">>}.
 
 start_reader(Sock, FramingPid) ->
     process_flag(trap_exit, true),

deps/rabbitmq-erlang-client/src/amqp_rpc_client.erl

 
 -module(amqp_rpc_client).
 
--include_lib("rabbit_framing.hrl").
--include_lib("rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
 -include("amqp_client.hrl").
 
 -behaviour(gen_server).
     Pid.
 
 stop(Pid) ->
-    gen_server:call(Pid, stop, infinity).
+    gen_server:call(Pid, stop).
 
 call(RpcClientPid, Payload) ->
-    gen_server:call(RpcClientPid, {call, Payload}, infinity).
+    gen_server:call(RpcClientPid, {call, Payload}).
 
 %---------------------------------------------------------------------------
 % Plumbing

deps/rabbitmq-erlang-client/src/amqp_rpc_server.erl

 
 -behaviour(gen_server).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 -include("amqp_client.hrl").
 
 -export([init/1, terminate/2, code_change/3, handle_call/3,
     Pid.
 
 stop(Pid) ->
-    gen_server:call(Pid, stop, infinity).
+    gen_server:call(Pid, stop).
 
 %---------------------------------------------------------------------------
 % gen_server callbacks

deps/rabbitmq-erlang-client/src/amqp_util.erl

 
 -module(amqp_util).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 
 -export([message_payload/1]).
 -export([binary/1]).

deps/rabbitmq-erlang-client/src/lib_amqp.erl

 
 -module(lib_amqp).
 
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
 -include("amqp_client.hrl").
 
 -compile(export_all).
 
 start_connection() ->
-    amqp_connection:start_direct("guest", "guest").
+    amqp_connection:start("guest", "guest").
 
 start_connection(Host) ->
-    start_connection(Host, ?PROTOCOL_PORT).
-
-start_connection(Host, Port) ->
-    amqp_connection:start_network("guest", "guest", Host, Port).
+    amqp_connection:start("guest", "guest", Host).
 
 start_channel(Connection) ->
     amqp_connection:open_channel(Connection).
 
 declare_exchange(Channel, X, Type) ->
     ExchangeDeclare = #'exchange.declare'{exchange = X,
-                                          type = Type},
+                                          type = Type,
+                                          passive = false,
+                                          durable = false,
+                                          auto_delete = false,
+                                          internal = false,
+                                          nowait = false,
+                                          arguments = []},
     amqp_channel:call(Channel, ExchangeDeclare).
 
 delete_exchange(Channel, X) ->
-    ExchangeDelete = #'exchange.delete'{exchange = X},
+    ExchangeDelete = #'exchange.delete'{exchange = X,
+                                        if_unused = false, nowait = false},
     #'exchange.delete_ok'{} = amqp_channel:call(Channel, ExchangeDelete).
 
 %%---------------------------------------------------------------------------
                  Payload, Mandatory, Properties) ->
     BasicPublish = #'basic.publish'{exchange = X,
                                     routing_key = RoutingKey,
-                                    mandatory = Mandatory},
+                                    mandatory = Mandatory,
+                                    immediate = false},
     {ClassId, _MethodId} = rabbit_framing:method_id('basic.publish'),
     Content = #content{class_id = ClassId,
                        properties = Properties,
 subscribe(Channel, Q, Consumer, Tag, NoAck) ->
     BasicConsume = #'basic.consume'{queue = Q,
                                     consumer_tag = Tag,
-                                    no_ack = NoAck},
+                                    no_local = false, no_ack = NoAck,
+                                    exclusive = false, nowait = false},
     #'basic.consume_ok'{consumer_tag = ConsumerTag} =
         amqp_channel:subscribe(Channel, BasicConsume, Consumer),
     ConsumerTag.
 
 unsubscribe(Channel, Tag) ->
-    BasicCancel = #'basic.cancel'{consumer_tag = Tag},
+    BasicCancel = #'basic.cancel'{consumer_tag = Tag, nowait = false},
     #'basic.cancel_ok'{} = amqp_channel:call(Channel, BasicCancel),
     ok.
 
 declare_queue(Channel, Q) ->
     %% TODO Specifying these defaults is unecessary - this is already taken
     %% care of in the spec file
-    QueueDeclare = #'queue.declare'{queue = Q},
+    QueueDeclare = #'queue.declare'{queue = Q,
+                                    passive = false, durable = false,
+                                    exclusive = false, auto_delete = false,
+                                    nowait = false, arguments = []},
     declare_queue(Channel, QueueDeclare).
 
 %% Creates a queue that is exclusive and auto-delete
 %%---------------------------------------------------------------------------
 
 delete_queue(Channel, Q) ->
-    QueueDelete = #'queue.delete'{queue = Q},
+    QueueDelete = #'queue.delete'{queue = Q,
+                                  if_unused = false,
+                                  if_empty = false,
+                                  nowait = false},
     #'queue.delete_ok'{} = amqp_channel:call(Channel, QueueDelete).
 
 bind_queue(Channel, X, Q, Binding) ->
     QueueBind = #'queue.bind'{queue = Q, exchange = X,
-                              routing_key = Binding},
+                              routing_key = Binding,
+                              nowait = false, arguments = []},
     #'queue.bind_ok'{} = amqp_channel:call(Channel, QueueBind).
 
 unbind_queue(Channel, X, Q, Binding) ->

deps/rabbitmq-erlang-client/test/Makefile

-#   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 the RabbitMQ Erlang Client.
-#
-#   The Initial Developers of the Original Code are LShift Ltd.,
-#   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
-#
-#   Portions created by LShift Ltd., Cohesive Financial
-#   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
-#   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
-#   Technologies Ltd.;
-#
-#   All Rights Reserved.
-#
-#   Contributor(s): ________________________
-#
-
-
-TEST_SOURCES=$(wildcard *.erl)
-TEST_TARGETS=$(patsubst %.erl, %.beam, $(TEST_SOURCES))
-INCLUDES=$(wildcard ../$(INCLUDE_DIR)/*.hrl)
-
-ERLC_OPTS=-I ../$(INCLUDE_DIR) -I ../$(INCLUDE_SERV_DIR) -o ./ -Wall -v +debug_info $(shell [ $(USE_SPECS) = "true" ] && echo "-Duse_specs")
-
-all: compile
-
-compile: $(TEST_TARGETS)
-
-%.beam: %.erl $(INCLUDES)
-	erlc $(ERLC_OPTS) $<
-
-clean:
-	rm -f *.beam

deps/rabbitmq-erlang-client/test/direct_client_SUITE.erl

-%%   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 the RabbitMQ Erlang Client.
-%%
-%%   The Initial Developers of the Original Code are LShift Ltd.,
-%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
-%%
-%%   Portions created by LShift Ltd., Cohesive Financial
-%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
-%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
-%%   Technologies Ltd.;
-%%
-%%   All Rights Reserved.
-%%
-%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
-%%
-
--module(direct_client_SUITE).
-
--define(RPC_TIMEOUT, 10000).
--define(RPC_SLEEP, 500).
-
--export([test_coverage/0]).
--export([test_channel_flow/0]).
-
--include_lib("eunit/include/eunit.hrl").
-
-basic_get_test() -> 
-    test_util:basic_get_test(new_connection()).
-
-basic_return_test() ->
-    test_util:basic_return_test(new_connection()).
-
-basic_qos_test() ->
-    test_util:basic_qos_test(new_connection()).
-
-basic_recover_test() ->
-    test_util:basic_recover_test(new_connection()).
-
-basic_consume_test() ->
-    test_util:basic_consume_test(new_connection()).
-
-lifecycle_test() ->
-    test_util:lifecycle_test(new_connection()).
-
-basic_ack_test() ->
-    test_util:basic_ack_test(new_connection()).
-
-command_serialization_test() ->
-    test_util:command_serialization_test(new_connection()).
-
-queue_unbind_test() ->
-    test_util:queue_unbind_test(new_connection()).
-
-%%---------------------------------------------------------------------------
-%% This must be kicked off manually because it can only be run after Rabbit
-%% has been running for 1 minute
-test_channel_flow() ->
-    test_util:channel_flow_test(new_connection()).
-
-%%---------------------------------------------------------------------------
-%% Negative Tests
-%%---------------------------------------------------------------------------
-
-non_existent_exchange_test() -> 
-    negative_test_util:non_existent_exchange_test(new_connection()).
-
-hard_error_test() ->
-    negative_test_util:hard_error_test(new_connection()).
-
-%%---------------------------------------------------------------------------
-%% Common Functions
-%%---------------------------------------------------------------------------
-
-new_connection() ->
-    lib_amqp:start_connection().
-
-test_coverage() ->
-    rabbit_misc:enable_cover(),
-    test(),
-    rabbit_misc:report_cover().
-

deps/rabbitmq-erlang-client/test/negative_test_util.erl

-%%   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 the RabbitMQ Erlang Client.
-%%
-%%   The Initial Developers of the Original Code are LShift Ltd.,
-%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
-%%
-%%   Portions created by LShift Ltd., Cohesive Financial
-%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
-%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
-%%   Technologies Ltd.;
-%%
-%%   All Rights Reserved.
-%%
-%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
-%%
--module(negative_test_util).
-
--include_lib("eunit/include/eunit.hrl").
--include_lib("rabbit_framing.hrl").
-
--compile(export_all).
-
-non_existent_exchange_test(Connection) ->
-    {A,B,C} = now(),
-    X = <<A:32,B:32,C:32>>,
-    RoutingKey = <<"a">>, 
-    Payload = <<"foobar">>,
-    Channel = lib_amqp:start_channel(Connection),
-    lib_amqp:declare_exchange(Channel, X),
-    %% Deliberately mix up the routingkey and exchange arguments
-    lib_amqp:publish(Channel, RoutingKey, X, Payload),
-    wait_for_death(Channel),
-    ?assertMatch(true, is_process_alive(Connection)),
-    lib_amqp:close_connection(Connection).
-
-hard_error_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    try
-        amqp_channel:call(Channel, #'basic.qos'{global = true})
-    catch
-        exit:_ -> ok;
-        _:_    -> exit(did_not_throw_error)
-    end,
-    wait_for_death(Channel),
-    wait_for_death(Connection).
-
-wait_for_death(Pid) ->
-    Ref = erlang:monitor(process, Pid),
-    receive {'DOWN', Ref, process, Pid, _Reason} -> ok
-    after 1000 -> exit({timed_out_waiting_for_process_death, Pid})
-    end.

deps/rabbitmq-erlang-client/test/network_client_SUITE.erl

-%%   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 the RabbitMQ Erlang Client.
-%%
-%%   The Initial Developers of the Original Code are LShift Ltd.,
-%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
-%%
-%%   Portions created by LShift Ltd., Cohesive Financial
-%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
-%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
-%%   Technologies Ltd.;
-%%
-%%   All Rights Reserved.
-%%
-%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
-%%
-
--module(network_client_SUITE).
-
--export([test_coverage/0]).
-
--include_lib("eunit/include/eunit.hrl").
-
-basic_get_test() ->
-    test_util:basic_get_test(new_connection()).
-
-basic_return_test() ->
-    test_util:basic_return_test(new_connection()).
-
-basic_qos_test() ->
-    test_util:basic_qos_test(new_connection()).
-
-basic_recover_test() -> 
-    test_util:basic_recover_test(new_connection()).
-
-basic_consume_test() -> 
-    test_util:basic_consume_test(new_connection()).
-
-lifecycle_test() ->
-    test_util:lifecycle_test(new_connection()).
-
-basic_ack_test() ->
-    test_util:basic_ack_test(new_connection()).
-
-channel_lifecycle_test() ->
-    test_util:channel_lifecycle_test(new_connection()).
-
-queue_unbind_test() ->
-    test_util:queue_unbind_test(new_connection()).
-
-command_serialization_test() ->
-    test_util:command_serialization_test(new_connection()).
-
-teardown_test() ->
-    test_util:teardown_test(new_connection()).
-
-rpc_test() ->
-    test_util:rpc_test(new_connection()).
-
-%%---------------------------------------------------------------------------
-%% Negative Tests
-
-non_existent_exchange_test() -> 
-  negative_test_util:non_existent_exchange_test(new_connection()).
-
-hard_error_test() ->
-    negative_test_util:hard_error_test(new_connection()).
-
-%%---------------------------------------------------------------------------
-%% Common Functions
-
-new_connection() ->
-  lib_amqp:start_connection("localhost").
-
-test_coverage() ->
-    rabbit_misc:enable_cover(),
-    test(),
-    rabbit_misc:report_cover().

deps/rabbitmq-erlang-client/test/test_util.erl

-%%   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 the RabbitMQ Erlang Client.
-%%
-%%   The Initial Developers of the Original Code are LShift Ltd.,
-%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
-%%
-%%   Portions created by LShift Ltd., Cohesive Financial
-%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
-%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
-%%   Technologies Ltd.;
-%%
-%%   All Rights Reserved.
-%%
-%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
-%%
-
--module(test_util).
-
--include_lib("rabbit.hrl").
--include_lib("rabbit_framing.hrl").
--include_lib("eunit/include/eunit.hrl").
--include("amqp_client.hrl").
-
--compile([export_all]).
-
--record(publish, {q, x, routing_key, bind_key, payload,
-                 mandatory = false, immediate = false}).
-
-%% 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).
-
-%%%%
-%%
-%% This is an example of how the client interaction should work
-%%
-%%   Connection = amqp_connection:start(User, Password, Host),
-%%   Channel = amqp_connection:open_channel(Connection),
-%%   %%...do something useful
-%%   ChannelClose = #'channel.close'{ %% set the appropriate fields },
-%%   amqp_channel:call(Channel, ChannelClose),
-%%   ConnectionClose = #'connection.close'{ %% set the appropriate fields },
-%%   amqp_connection:close(Connection, ConnectionClose).
-%%
-
-lifecycle_test(Connection) ->
-    X = <<"x">>,
-    Channel = lib_amqp:start_channel(Connection),
-    lib_amqp:declare_exchange(Channel, X, <<"topic">>),
-    Parent = self(),
-    [spawn(
-           fun() ->
-                queue_exchange_binding(Channel, X, Parent, Tag) end)
-            || Tag <- lists:seq(1, ?Latch)],
-    latch_loop(?Latch),
-    lib_amqp:delete_exchange(Channel, X),
-    lib_amqp:teardown(Connection, Channel),
-    ok.
-
-queue_exchange_binding(Channel, X, Parent, Tag) ->
-    receive
-        nothing -> ok
-    after (?Latch - Tag rem 7) * 10 ->
-        ok
-    end,
-    Q = <<"a.b.c", Tag:32>>,
-    Binding = <<"a.b.c.*">>,
-    Q1 = lib_amqp:declare_queue(Channel, Q),
-    ?assertMatch(Q, Q1),
-    lib_amqp:bind_queue(Channel, X, Q, Binding),
-    lib_amqp:delete_queue(Channel, Q),
-    Parent ! finished.
-
-channel_lifecycle_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    lib_amqp:close_channel(Channel),
-    Channel2 = lib_amqp:start_channel(Connection),
-    lib_amqp:teardown(Connection, Channel2),
-    ok.
-
-%% This is designed to exercize the internal queuing mechanism
-%% to ensure that commands are properly serialized
-command_serialization_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    Parent = self(),
-    [spawn(fun() ->
-                Q = uuid(),
-                Q1 = lib_amqp:declare_queue(Channel, Q),
-                ?assertMatch(Q, Q1),
-                Parent ! finished
-           end) || _ <- lists:seq(1, ?Latch)],
-    latch_loop(?Latch),
-    lib_amqp:teardown(Connection, Channel).
-
-queue_unbind_test(Connection) ->
-    X = <<"eggs">>, Q = <<"foobar">>, Key = <<"quay">>,
-    Payload = <<"foobar">>,
-    Channel = lib_amqp:start_channel(Connection),
-    lib_amqp:declare_exchange(Channel, X),
-    lib_amqp:declare_queue(Channel, Q),
-    lib_amqp:bind_queue(Channel, X, Q, Key),
-    lib_amqp:publish(Channel, X, Key, Payload),
-    get_and_assert_equals(Channel, Q, Payload),
-    lib_amqp:unbind_queue(Channel, X, Q, Key),
-    lib_amqp:publish(Channel, X, Key, Payload),
-    get_and_assert_empty(Channel, Q),
-    lib_amqp:teardown(Connection, Channel).
-
-get_and_assert_empty(Channel, Q) ->
-    BasicGetEmpty = lib_amqp:get(Channel, Q, false),
-    ?assertMatch('basic.get_empty', BasicGetEmpty).
-
-get_and_assert_equals(Channel, Q, Payload) ->
-    Content = lib_amqp:get(Channel, Q),
-    #content{payload_fragments_rev = PayloadFragments} = Content,
-    ?assertMatch([Payload], PayloadFragments).
-
-basic_get_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    {ok, Q} = setup_publish(Channel),
-    %% TODO: This could be refactored to use get_and_assert_equals,
-    %% get_and_assert_empty .... would require another bug though :-)
-    Content = lib_amqp:get(Channel, Q),
-    #content{payload_fragments_rev = PayloadFragments} = Content,
-    ?assertMatch([<<"foobar">>], PayloadFragments),
-    BasicGetEmpty = lib_amqp:get(Channel, Q, false),
-    ?assertMatch('basic.get_empty', BasicGetEmpty),
-    lib_amqp:teardown(Connection, Channel).
-
-basic_return_test(Connection) ->
-    X = uuid(),
-    Q = uuid(),
-    Key = uuid(),
-    Payload = <<"qwerty">>,
-    Channel = lib_amqp:start_channel(Connection),
-    amqp_channel:register_return_handler(Channel, self()),
-    lib_amqp:declare_exchange(Channel, X),
-    lib_amqp:declare_queue(Channel, Q),
-    lib_amqp:publish(Channel, X, Key, Payload, true),
-    timer:sleep(200),
-    receive
-        {BasicReturn = #'basic.return'{}, Content} ->
-            #'basic.return'{reply_text = ReplyText,
-                            exchange = X} = BasicReturn,
-            ?assertMatch(<<"unroutable">>, ReplyText),
-            #content{payload_fragments_rev = Payload2} = Content,
-            ?assertMatch([Payload], Payload2);
-        WhatsThis ->
-            %% TODO investigate where this comes from
-            io:format("Spurious message ~p~n", [WhatsThis])
-    after 2000 ->
-        exit(no_return_received)
-    end,
-    lib_amqp:teardown(Connection, Channel).
-
-basic_ack_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    {ok, Q} = setup_publish(Channel),
-    {DeliveryTag, _} = lib_amqp:get(Channel, Q, false),
-    lib_amqp:ack(Channel, DeliveryTag),
-    lib_amqp:teardown(Connection, Channel).
-
-basic_consume_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    X = uuid(),
-    lib_amqp:declare_exchange(Channel, X),
-    RoutingKey = uuid(),
-    Parent = self(),
-    [spawn(
-        fun() ->
-            consume_loop(Channel, X, RoutingKey, Parent, <<Tag:32>>) end)
-        || Tag <- lists:seq(1, ?Latch)],
-    timer:sleep(?Latch * 20),
-    lib_amqp:publish(Channel, X, RoutingKey, <<"foobar">>),
-    latch_loop(?Latch),
-    lib_amqp:teardown(Connection, Channel).
-
-consume_loop(Channel, X, RoutingKey, Parent, Tag) ->
-    Q = lib_amqp:declare_queue(Channel),
-    lib_amqp:bind_queue(Channel, X, Q, RoutingKey),
-    lib_amqp:subscribe(Channel, Q, self(), Tag),
-    receive
-        #'basic.consume_ok'{consumer_tag = Tag} -> ok
-    end,
-    receive
-        {#'basic.deliver'{}, _} -> ok
-    end,
-    lib_amqp:unsubscribe(Channel, Tag),
-    receive
-        #'basic.cancel_ok'{consumer_tag = Tag} -> ok
-    end,
-    Parent ! finished.
-
-basic_recover_test(Connection) ->
-    Q = uuid(),
-    Channel = lib_amqp:start_channel(Connection),
-    lib_amqp:declare_queue(Channel, Q),
-    Tag = lib_amqp:subscribe(Channel, Q, self(), false),
-    receive
-        #'basic.consume_ok'{consumer_tag = Tag} -> ok
-    after 2000 ->
-        exit(did_not_receive_subscription_message)
-    end,
-    lib_amqp:publish(Channel, <<>>, Q, <<"foobar">>),
-    receive
-        {#'basic.deliver'{}, _} ->
-            %% no_ack set to false, but don't send ack
-            ok
-    after 2000 ->
-        exit(did_not_receive_first_message)
-    end,
-    BasicRecover = #'basic.recover'{requeue = true},
-    amqp_channel:cast(Channel, BasicRecover),
-    receive
-        {#'basic.deliver'{delivery_tag = DeliveryTag2}, _} ->
-            lib_amqp:ack(Channel, DeliveryTag2)
-    after 2000 ->
-        exit(did_not_receive_second_message)
-    end,
-    lib_amqp:teardown(Connection, Channel).
-
-basic_qos_test(Con) ->
-    [NoQos, Qos] = [basic_qos_test(Con, Prefetch) || Prefetch <- [0,1]],
-    ExpectedRatio = (1+1) / (1+50/5),
-    FudgeFactor = 2, %% account for timing variations
-    ?assertMatch(true, Qos / NoQos < ExpectedRatio * FudgeFactor).
-
-basic_qos_test(Connection, Prefetch) ->
-    Messages = 100,
-    Workers = [5, 50],
-    Parent = self(),
-    Chan = lib_amqp:start_channel(Connection),
-    Q = lib_amqp:declare_queue(Chan),
-    Kids = [spawn(fun() ->
-                    Channel = lib_amqp:start_channel(Connection),
-                    lib_amqp:set_prefetch_count(Channel, Prefetch),
-                    lib_amqp:subscribe(Channel, Q, self(), false),
-                    Parent ! finished,
-                    sleeping_consumer(Channel, Sleep, Parent)
-                  end) || Sleep <- Workers],
-    latch_loop(length(Kids)),
-    spawn(fun() -> producer_loop(lib_amqp:start_channel(Connection),
-                                 Q, Messages) end),
-    {Res, ok} = timer:tc(erlang, apply, [fun latch_loop/1, [Messages]]),
-    [Kid ! stop || Kid <- Kids],
-    latch_loop(length(Kids)),
-    lib_amqp:close_channel(Chan),
-    Res.
-
-sleeping_consumer(Channel, Sleep, Parent) ->
-    receive
-        stop ->
-            do_stop(Channel, Parent);
-        #'basic.consume_ok'{} ->
-            sleeping_consumer(Channel, Sleep, Parent);
-        #'basic.cancel_ok'{}  ->
-            ok;
-        {#'basic.deliver'{delivery_tag = DeliveryTag}, _Content} ->
-            Parent ! finished,
-            receive stop -> do_stop(Channel, Parent)
-            after Sleep -> ok
-            end,
-            lib_amqp:ack(Channel, DeliveryTag),
-            sleeping_consumer(Channel, Sleep, Parent)
-    end.
-
-do_stop(Channel, Parent) ->
-    Parent ! finished,
-    lib_amqp:close_channel(Channel),
-    exit(normal).
-
-producer_loop(Channel, _RoutingKey, 0) ->
-    lib_amqp:close_channel(Channel),
-    ok;
-
-producer_loop(Channel, RoutingKey, N) ->
-    lib_amqp:publish(Channel, <<>>, RoutingKey, <<>>),
-    producer_loop(Channel, RoutingKey, N - 1).
-
-%% Reject is not yet implemented in RabbitMQ
-basic_reject_test(Connection) ->
-    lib_amqp:close_connection(Connection).
-
-%%----------------------------------------------------------------------------
-%% Unit test for the direct client
-%% This just relies on the fact that a fresh Rabbit VM must consume more than
-%% 0.1 pc of the system memory:
-%% 0. Wait 1 minute to let memsup do stuff
-%% 1. Make sure that the high watermark is set high
-%% 2. Start a process to receive the pause and resume commands from the broker
-%% 3. Register this as flow control notification handler
-%% 4. Let the system settle for a little bit
-%% 5. Set the threshold to the lowest possible value
-%% 6. When the flow handler receives the pause command, it sets the watermark
-%%    to a high value in order to get the broker to send the resume command
-%% 7. Allow 10 secs to receive the pause and resume, otherwise timeout and
-%%    fail
-channel_flow_test(Connection) ->
-    X = <<"amq.direct">>,
-    K = Payload = <<"x">>,
-    memsup:set_sysmem_high_watermark(0.99),
-    timer:sleep(1000),
-    Channel = lib_amqp:start_channel(Connection),
-    Parent = self(),
-    Child = spawn_link(
-              fun() ->
-                      receive
-                          #'channel.flow'{active = false} -> ok
-                      end,
-                      blocked = lib_amqp:publish(Channel, X, K, Payload),
-                      memsup:set_sysmem_high_watermark(0.99),
-                      receive
-                          #'channel.flow'{active = true} -> ok
-                      end,
-                      Parent ! ok
-              end),
-    amqp_channel:register_flow_handler(Channel, Child),
-    timer:sleep(1000),
-    memsup:set_sysmem_high_watermark(0.001),
-    receive
-        ok -> ok
-    after 10000 ->
-        io:format("Are you sure that you have waited 1 minute?~n"),
-        exit(did_not_receive_channel_flow)
-    end.
-
-%%----------------------------------------------------------------------------
-%% This is a test, albeit not a unit test, to see if the producer
-%% handles the effect of being throttled.
-
-channel_flow_sync(Connection) ->
-    start_channel_flow(Connection, fun lib_amqp:publish/4).
-
-channel_flow_async(Connection) ->
-    start_channel_flow(Connection, fun lib_amqp:async_publish/4).
-
-start_channel_flow(Connection, PublishFun) ->
-    X = <<"amq.direct">>,
-    Key = uuid(),
-    Producer = spawn_link(
-        fun() ->
-            Channel = lib_amqp:start_channel(Connection),
-            Parent = self(),
-            FlowHandler = spawn_link(fun() -> cf_handler_loop(Parent) end),
-            amqp_channel:register_flow_handler(Channel, FlowHandler),
-            Payload = << <<B:8>> || B <- lists:seq(1, 10000) >>,
-            cf_producer_loop(Channel, X, Key, PublishFun, Payload, 0)
-        end),
-    Consumer = spawn_link(
-        fun() ->
-            Channel = lib_amqp:start_channel(Connection),
-            Q = lib_amqp:declare_queue(Channel),
-            lib_amqp:bind_queue(Channel, X, Q, Key),
-            Tag = lib_amqp:subscribe(Channel, Q, self()),
-            cf_consumer_loop(Channel, Tag)
-        end),
-    {Producer, Consumer}.
-
-cf_consumer_loop(Channel, Tag) ->
-    receive
-        #'basic.consume_ok'{} -> cf_consumer_loop(Channel, Tag);
-        #'basic.cancel_ok'{} -> ok;
-        {#'basic.deliver'{delivery_tag = DeliveryTag}, _Content} ->
-             lib_amqp:ack(Channel, DeliveryTag),
-             cf_consumer_loop(Channel, Tag);
-        stop ->
-             lib_amqp:unsubscribe(Channel, Tag),
-             ok
-    end.
-
-cf_producer_loop(Channel, X, Key, PublishFun, Payload, N)
-        when N rem 5000 =:= 0 ->
-    io:format("Producer (~p) has sent about ~p messages since it started~n",
-              [self(), N]),
-    cf_producer_loop(Channel, X, Key, PublishFun, Payload, N + 1);
-
-cf_producer_loop(Channel, X, Key, PublishFun, Payload, N) ->
-    case PublishFun(Channel, X, Key, Payload) of
-        blocked ->
-            io:format("Producer (~p) is blocked, will go to sleep.....ZZZ~n",
-                      [self()]),
-            receive
-                resume ->
-                    io:format("Producer (~p) has woken up :-)~n", [self()]),
-                    cf_producer_loop(Channel, X, Key,
-                                     PublishFun, Payload, N + 1)
-            end;
-        _ ->
-            cf_producer_loop(Channel, X, Key, PublishFun, Payload, N + 1)
-    end.
-
-cf_handler_loop(Producer) ->
-    receive
-        #'channel.flow'{active = false} ->
-            io:format("Producer throttling ON~n"),
-            cf_handler_loop(Producer);
-        #'channel.flow'{active = true} ->
-            io:format("Producer throttling OFF, waking up producer (~p)~n",
-                      [Producer]),
-            Producer ! resume,
-            cf_handler_loop(Producer);
-        stop -> ok
-    end.
-
-%%---------------------------------------------------------------------------
-%% This tests whether RPC over AMQP produces the same result as invoking the
-%% same argument against the same underlying gen_server instance.
-rpc_test(Connection) ->
-    Q = uuid(),
-    Fun = fun(X) -> X + 1 end,
-    RPCHandler = fun(X) -> term_to_binary(Fun(binary_to_term(X))) end,
-    Server = amqp_rpc_server:start(Connection, Q, RPCHandler),
-    Client = amqp_rpc_client:start(Connection, Q),
-    Input = 1,
-    Reply = amqp_rpc_client:call(Client, term_to_binary(Input)),
-    Expected = Fun(Input),
-    DecodedReply = binary_to_term(Reply),
-    ?assertMatch(Expected, DecodedReply),
-    amqp_rpc_client:stop(Client),
-    amqp_rpc_server:stop(Server),
-    ok.
-
-%%---------------------------------------------------------------------------
-
-setup_publish(Channel) ->
-    Publish = #publish{routing_key = <<"a.b.c.d">>,
-                       q = <<"a.b.c">>,
-                       x = <<"x">>,
-                       bind_key = <<"a.b.c.*">>,
-                       payload = <<"foobar">>
-                       },
-    setup_publish(Channel, Publish).
-
-setup_publish(Channel, #publish{routing_key = RoutingKey,
-                                q = Q, x = X,
-                                bind_key = BindKey,
-                                payload = Payload}) ->
-    ok = setup_exchange(Channel, Q, X, BindKey),
-    lib_amqp:publish(Channel, X, RoutingKey, Payload),
-    {ok, Q}.
-
-teardown_test(Connection) ->
-    Channel = lib_amqp:start_channel(Connection),
-    ?assertMatch(true, is_process_alive(Channel)),
-    ?assertMatch(true, is_process_alive(Connection)),
-    lib_amqp:teardown(Connection, Channel),
-    ?assertMatch(false, is_process_alive(Channel)),
-    ?assertMatch(false, is_process_alive(Connection)).
-
-setup_exchange(Channel, Q, X, Binding) ->
-    lib_amqp:declare_exchange(Channel, X, <<"topic">>),
-    lib_amqp:declare_queue(Channel, Q),
-    lib_amqp:bind_queue(Channel, X, Q, Binding),
-    ok.
-
-latch_loop(0) ->
-    ok;
-
-latch_loop(Latch) ->
-    receive
-        finished ->
-            latch_loop(Latch - 1)
-    after ?Latch * ?Wait ->
-        exit(waited_too_long)
-    end.
-
-uuid() ->
-    {A, B, C} = now(),
-    <<A:32, B:32, C:32>>.
-

deps/rabbitmq-erlang-client/tests/direct_client_test.erl

+%%   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 the RabbitMQ Erlang Client.
+%%
+%%   The Initial Developers of the Original Code are LShift Ltd.,
+%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+%%
+%%   Portions created by LShift Ltd., Cohesive Financial
+%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
+%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+%%   Technologies Ltd.;
+%%
+%%   All Rights Reserved.
+%%
+%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
+%%
+
+-module(direct_client_test).
+
+-define(RPC_TIMEOUT, 10000).
+-define(RPC_SLEEP, 500).
+
+-export([test_coverage/0]).
+-export([test_channel_flow/0]).
+
+-include_lib("eunit/include/eunit.hrl").
+
+basic_get_test() -> 
+    test_util:basic_get_test(new_connection()).
+
+basic_return_test() ->
+    test_util:basic_return_test(new_connection()).
+
+basic_qos_test() ->
+    test_util:basic_qos_test(new_connection()).
+
+basic_recover_test() ->
+    test_util:basic_recover_test(new_connection()).
+
+basic_consume_test() ->
+    test_util:basic_consume_test(new_connection()).
+
+lifecycle_test() ->
+    test_util:lifecycle_test(new_connection()).
+
+basic_ack_test() ->
+    test_util:basic_ack_test(new_connection()).
+
+command_serialization_test() ->
+    test_util:command_serialization_test(new_connection()).
+
+queue_unbind_test() ->
+    test_util:queue_unbind_test(new_connection()).
+
+%%---------------------------------------------------------------------------
+%% This must be kicked off manually because it can only be run after Rabbit
+%% has been running for 1 minute
+test_channel_flow() ->
+    test_util:channel_flow_test(new_connection()).
+
+%%---------------------------------------------------------------------------
+%% Negative Tests
+%%---------------------------------------------------------------------------
+
+non_existent_exchange_test() -> 
+    negative_test_util:non_existent_exchange_test(new_connection()).
+
+hard_error_test() ->
+    negative_test_util:hard_error_test(new_connection()).
+
+%%---------------------------------------------------------------------------
+%% Common Functions
+%%---------------------------------------------------------------------------
+
+new_connection() ->
+    amqp_connection:start("guest", "guest").
+
+test_coverage() ->
+    rabbit_misc:enable_cover(),
+    test(),
+    rabbit_misc:report_cover().
+

deps/rabbitmq-erlang-client/tests/negative_test_util.erl

+%%   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 the RabbitMQ Erlang Client.
+%%
+%%   The Initial Developers of the Original Code are LShift Ltd.,
+%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+%%
+%%   Portions created by LShift Ltd., Cohesive Financial
+%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
+%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+%%   Technologies Ltd.;
+%%
+%%   All Rights Reserved.
+%%
+%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
+%%
+-module(negative_test_util).
+
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
+
+-compile(export_all).
+
+non_existent_exchange_test(Connection) ->
+    {A,B,C} = now(),
+    X = <<A:32,B:32,C:32>>,
+    RoutingKey = <<"a">>, 
+    Payload = <<"foobar">>,
+    Channel = lib_amqp:start_channel(Connection),
+    lib_amqp:declare_exchange(Channel, X),
+    %% Deliberately mix up the routingkey and exchange arguments
+    lib_amqp:publish(Channel, RoutingKey, X, Payload),
+    wait_for_death(Channel),
+    ?assert(is_process_alive(Connection)),
+    lib_amqp:close_connection(Connection).
+
+hard_error_test(Connection) ->
+    Channel = lib_amqp:start_channel(Connection),
+    try
+        amqp_channel:call(Channel, #'basic.qos'{global = true})
+    catch
+        exit:_ -> ok;
+        _:_    -> exit(did_not_throw_error)
+    end,
+    wait_for_death(Channel),
+    wait_for_death(Connection).
+
+wait_for_death(Pid) ->
+    Ref = erlang:monitor(process, Pid),
+    receive {'DOWN', Ref, process, Pid, _Reason} -> ok
+    after 1000 -> ?assert(false), ok
+    end.

deps/rabbitmq-erlang-client/tests/network_client_test.erl

+%%   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 the RabbitMQ Erlang Client.
+%%
+%%   The Initial Developers of the Original Code are LShift Ltd.,
+%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+%%
+%%   Portions created by LShift Ltd., Cohesive Financial
+%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
+%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+%%   Technologies Ltd.;
+%%
+%%   All Rights Reserved.
+%%
+%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
+%%
+
+-module(network_client_test).
+
+-export([test_coverage/0]).
+
+-include_lib("eunit/include/eunit.hrl").
+
+basic_get_test() ->
+    test_util:basic_get_test(new_connection()).
+
+basic_return_test() ->
+    test_util:basic_return_test(new_connection()).
+
+basic_qos_test() ->
+    test_util:basic_qos_test(new_connection()).
+
+basic_recover_test() -> 
+    test_util:basic_recover_test(new_connection()).
+
+basic_consume_test() -> 
+    test_util:basic_consume_test(new_connection()).
+
+lifecycle_test() ->
+    test_util:lifecycle_test(new_connection()).
+
+basic_ack_test() ->
+    test_util:basic_ack_test(new_connection()).
+
+channel_lifecycle_test() ->
+    test_util:channel_lifecycle_test(new_connection()).
+
+queue_unbind_test() ->
+    test_util:queue_unbind_test(new_connection()).
+
+command_serialization_test() ->
+    test_util:command_serialization_test(new_connection()).
+
+teardown_test() ->
+    test_util:teardown_test(new_connection()).
+
+rpc_test() ->
+    test_util:rpc_test(new_connection()).
+
+%%---------------------------------------------------------------------------
+%% Negative Tests
+
+non_existent_exchange_test() -> 
+  negative_test_util:non_existent_exchange_test(new_connection()).
+
+hard_error_test() ->
+    negative_test_util:hard_error_test(new_connection()).
+
+%%---------------------------------------------------------------------------
+%% Common Functions
+
+new_connection() ->
+  amqp_connection:start("guest", "guest", "localhost").
+
+test_coverage() ->
+    rabbit_misc:enable_cover(),
+    test(),
+    rabbit_misc:report_cover().

deps/rabbitmq-erlang-client/tests/test_util.erl

+%%   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 the RabbitMQ Erlang Client.
+%%
+%%   The Initial Developers of the Original Code are LShift Ltd.,
+%%   Cohesive Financial Technologies LLC., and Rabbit Technologies Ltd.
+%%
+%%   Portions created by LShift Ltd., Cohesive Financial
+%%   Technologies LLC., and Rabbit Technologies Ltd. are Copyright (C)
+%%   2007 LShift Ltd., Cohesive Financial Technologies LLC., and Rabbit
+%%   Technologies Ltd.;
+%%
+%%   All Rights Reserved.
+%%
+%%   Contributor(s): Ben Hood <0x6e6562@gmail.com>.
+%%
+
+-module(test_util).
+
+-include_lib("rabbitmq_server/include/rabbit.hrl").
+-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
+-include_lib("eunit/include/eunit.hrl").
+-include("amqp_client.hrl").
+
+-compile([export_all]).
+
+-record(publish, {q, x, routing_key, bind_key, payload,
+                 mandatory = false, immediate = false}).
+
+%% 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).
+
+%%%%
+%%
+%% This is an example of how the client interaction should work
+%%
+%%   Connection = amqp_connection:start(User, Password, Host),
+%%   Channel = amqp_connection:open_channel(Connection),
+%%   %%...do something useful
+%%   ChannelClose = #'channel.close'{ %% set the appropriate fields },
+%%   amqp_channel:call(Channel, ChannelClose),
+%%   ConnectionClose = #'connection.close'{ %% set the appropriate fields },
+%%   amqp_connection:close(Connection, ConnectionClose).
+%%
+
+lifecycle_test(Connection) ->
+    X = <<"x">>,
+    Channel = lib_amqp:start_channel(Connection),
+    lib_amqp:declare_exchange(Channel, X, <<"topic">>),
+    Parent = self(),
+    [spawn(
+           fun() ->
+                queue_exchange_binding(Channel, X, Parent, Tag) end)
+            || Tag <- lists:seq(1, ?Latch)],
+    latch_loop(?Latch),
+    lib_amqp:delete_exchange(Channel, X),
+    lib_amqp:teardown(Connection, Channel),
+    ok.
+
+queue_exchange_binding(Channel, X, Parent, Tag) ->
+    receive
+        nothing -> ok
+    after (?Latch - Tag rem 7) * 10 ->
+        ok
+    end,
+    Q = <<"a.b.c", Tag:32>>,
+    Binding = <<"a.b.c.*">>,
+    Q1 = lib_amqp:declare_queue(Channel, Q),
+    ?assertMatch(Q, Q1),
+    lib_amqp:bind_queue(Channel, X, Q, Binding),
+    lib_amqp:delete_queue(Channel, Q),
+    Parent ! finished.
+
+channel_lifecycle_test(Connection) ->
+    Channel = lib_amqp:start_channel(Connection),
+    lib_amqp:close_channel(Channel),
+    Channel2 = lib_amqp:start_channel(Connection),
+    lib_amqp:teardown(Connection, Channel2),
+    ok.
+
+%% This is designed to exercize the internal queuing mechanism
+%% to ensure that commands are properly serialized
+command_serialization_test(Connection) ->
+    Channel = lib_amqp:start_channel(Connection),
+    Parent = self(),
+    [spawn(fun() ->
+                Q = uuid(),
+                Q1 = lib_amqp:declare_queue(Channel, Q),
+                ?assertMatch(Q, Q1),
+                Parent ! finished
+           end) || _ <- lists:seq(1, ?Latch)],
+    latch_loop(?Latch),
+    lib_amqp:teardown(Connection, Channel).
+
+queue_unbind_test(Connection) ->
+    X = <<"eggs">>, Q = <<"foobar">>, Key = <<"quay">>,
+    Payload = <<"foobar">>,
+    Channel = lib_amqp:start_channel(Connection),
+    lib_amqp:declare_exchange(Channel, X),
+    lib_amqp:declare_queue(Channel, Q),
+    lib_amqp:bind_queue(Channel, X, Q, Key),
+    lib_amqp:publish(Channel, X, Key, Payload),
+    get_and_assert_equals(Channel, Q, Payload),
+    lib_amqp:unbind_queue(Channel, X, Q, Key),
+    lib_amqp:publish(Channel, X, Key, Payload),