Merged bug19985 into default

This commit is contained in:
Ben Hood 2009-07-10 11:05:11 +01:00
commit 93f2def362
16 changed files with 210 additions and 100 deletions

View File

@ -1 +1,7 @@
\.beam$
^rabbitmq_server$
^cover/
^tmp/
^dist/
^erl_crash.dump$

View File

@ -24,56 +24,61 @@
#
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
INCLUDE_SERV_DIR=rabbitmq_server/include
DIST_DIR=rabbitmq-erlang-client
LOAD_PATH=ebin rabbitmq_server/ebin
INCLUDES=$(wildcard $(INCLUDE_DIR)/*.hrl)
SOURCES=$(wildcard $(SOURCE_DIR)/*.erl)
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))
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))
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
USE_SPECS=$(shell if [ $$(erl -noshell -eval 'io:format(erlang:system_info(version)), halt().') \> "5.6.2" ]; then echo "true"; else echo "false"; fi)
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")
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
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)
BROKER_DIR=../rabbitmq-server
BROKER_SYMLINK=rabbitmq_server
all: compile
dialyze: $(EBIN_DIR) $(TARGETS)
dialyzer --plt $(PLT) -c $(TARGETS)
compile: $(TARGETS)
dialyze_all: $(EBIN_DIR) $(TARGETS) $(TEST_TARGETS)
dialyzer --plt $(PLT) -c $(TARGETS) $(TEST_TARGETS)
compile_tests: $(TEST_TARGETS)
dialyze: $(TARGETS)
$(DIALYZER_CALL) -c $^
dialyze_all: $(TARGETS) $(TEST_TARGETS)
$(DIALYZER_CALL) -c $^
add_broker_to_plt: $(BROKER_SYMLINK)/ebin
dialyzer --add_to_plt --plt $(PLT) -r $<
$(DIALYZER_CALL) --add_to_plt -r $<
compile: $(EBIN_DIR) $(TARGETS)
compile_tests: $(EBIN_DIR) $(TEST_TARGETS)
$(TEST_TARGETS): $(BROKER_SYMLINK)
$(MAKE) -C $(TEST_DIR)
$(BROKER_SYMLINK):
ifdef BROKER_DIR
@ -83,50 +88,50 @@ endif
$(EBIN_DIR):
mkdir -p $@
$(EBIN_DIR)/%.beam: $(SOURCE_DIR)/%.erl $(INCLUDES) $(BROKER_SYMLINK)
$(EBIN_DIR)/%.beam: $(SOURCE_DIR)/%.erl $(EBIN_DIR) $(BROKER_SYMLINK)
erlc $(ERLC_OPTS) $<
$(EBIN_DIR)/%.beam: $(TEST_SOURCE_DIR)/%.erl $(INCLUDES) $(BROKER_SYMLINK)
erlc $(ERLC_OPTS) $<
run:
run: compile
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
tests_network: test_network test_network_coverage
$(ERL_CALL) -q
all_tests: compile compile_tests
$(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()'
test_network: compile compile_tests
erl -pa $(LOAD_PATH) -noshell -eval 'network_client_test:test(),halt().'
$(ERL_WITH_BROKER) -eval 'network_client_SUITE:test(),halt().'
test_network_coverage: compile compile_tests
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)
$(ERL_WITH_BROKER) -eval 'network_client_SUITE:test_coverage(),halt().'
test_direct: compile compile_tests
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().'
$(ERL_WITH_BROKER) -eval 'direct_client_SUITE:test(),halt().'
test_direct_coverage: compile compile_tests
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().'
$(ERL_WITH_BROKER) -eval 'direct_client_SUITE:test_coverage(),halt().'
clean:
rm -f $(EBIN_DIR)/*.beam
rm -f rabbitmq_server erl_crash.dump
rm -fr cover dist
rm -fr cover dist tmp
$(MAKE) -C $(TEST_DIR) clean
source_tarball:
mkdir -p dist/$(DIST_DIR)
cp -a README Makefile src/*.erl include/*.hrl 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)/
cd dist ; tar cvzf $(DIST_DIR).tar.gz $(DIST_DIR)

View File

@ -94,30 +94,37 @@ need to specify the path to this directory:
$ make BROKER_DIR=PATH_TO_THE_SERVER
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:
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:
$ 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
@ -132,20 +139,23 @@ Both tests require that the memory alarms are turned on in the
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, run the following
commmand (where SOME_DIRECTORY is some directory where you want mnesia
to log its files):
this from the *rabbitmq-erlang-client directory*, type
$ erl -pa ebin rabbitmq_server/ebin -mnesia dir SOME_DIRECTORY \
-boot start_sasl -s rabbit
rabbitmq-erlang-client $ make LOG_IN_FILE=false run_with_broker
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_test:test_channel_flow().
1> direct_client_SUITE:test_channel_flow().
=INFO REPORT==== 17-Dec-2008::13:39:41 ===
alarm_handler: {set,{system_memory_high_watermark,[]}}
@ -160,10 +170,10 @@ network client driver. Whilst it can be run using the direct client,
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 $ erl -pa rabbitmq_server/ebin/ ebin/
rabbitmq-erlang-client $ make run
Erlang (BEAM) emulator version 5.6.3 [source] [smp:2] \
[async-threads:0][kernel-poll:false]
@ -177,13 +187,13 @@ After having done this, you should see output similar to this:
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
@ -196,3 +206,52 @@ wake up again:
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.

View File

@ -25,8 +25,8 @@
-module(amqp_channel).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include_lib("stdlib/include/qlc.hrl").
-include("amqp_client.hrl").

View File

@ -24,8 +24,8 @@
-module(amqp_connection).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include("amqp_client.hrl").
-behaviour(gen_server).

View File

@ -25,8 +25,8 @@
-module(amqp_direct_driver).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include("amqp_client.hrl").
-export([handshake/1, open_channel/3, close_channel/1, close_connection/3]).

View File

@ -25,8 +25,8 @@
-module(amqp_network_driver).
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include("amqp_client.hrl").
-export([handshake/1, open_channel/3, close_channel/1, close_connection/3]).

View File

@ -25,8 +25,8 @@
-module(amqp_rpc_client).
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include("amqp_client.hrl").
-behaviour(gen_server).

View File

@ -27,8 +27,8 @@
-behaviour(gen_server).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include("amqp_client.hrl").
-export([init/1, terminate/2, code_change/3, handle_call/3,

View File

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

View File

@ -25,8 +25,8 @@
-module(lib_amqp).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include("amqp_client.hrl").
-compile(export_all).

40
deps/amqp_client/test/Makefile vendored Normal file
View File

@ -0,0 +1,40 @@
# 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))
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
erlc $(ERLC_OPTS) $<
clean:
rm -f *.beam

View File

@ -23,7 +23,7 @@
%% Contributor(s): Ben Hood <0x6e6562@gmail.com>.
%%
-module(direct_client_test).
-module(direct_client_SUITE).
-define(RPC_TIMEOUT, 10000).
-define(RPC_SLEEP, 500).

View File

@ -25,7 +25,7 @@
-module(negative_test_util).
-include_lib("eunit/include/eunit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit_framing.hrl").
-compile(export_all).

View File

@ -23,7 +23,7 @@
%% Contributor(s): Ben Hood <0x6e6562@gmail.com>.
%%
-module(network_client_test).
-module(network_client_SUITE).
-export([test_coverage/0]).

View File

@ -25,8 +25,8 @@
-module(test_util).
-include_lib("rabbitmq_server/include/rabbit.hrl").
-include_lib("rabbitmq_server/include/rabbit_framing.hrl").
-include_lib("rabbit.hrl").
-include_lib("rabbit_framing.hrl").
-include_lib("eunit/include/eunit.hrl").
-include("amqp_client.hrl").