Skip to content

Commit 96ebca4

Browse files
author
Emile Joubert
committed
Merged heads
2 parents 580b0d0 + b3d5a53 commit 96ebca4

File tree

4 files changed

+237
-5
lines changed

4 files changed

+237
-5
lines changed

README-EXAMPLES

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
Overview
2+
========
3+
4+
A number of examples are packaged with the source distribution and
5+
with the tests jar in the binary distribution. These examples vary in
6+
complexity from simple clients and servers through to complex test
7+
harnesses that are used for testing the RabbitMQ server.
8+
9+
The source code for the examples can be found in the
10+
test/src/com/rabbitmq/examples directory of the source distribution.
11+
12+
13+
Running the Examples
14+
====================
15+
16+
The script runjava.sh or runjava.bat can be found in the top level
17+
directory of the binary distribution or in the scripts directory of
18+
the source distribution.
19+
20+
This script can be used to run the examples. For instance, if you are
21+
using the binary distribution and if you have a RabbitMQ broker
22+
running and you open two shell or console windows you can test basic
23+
connectivity like this:
24+
25+
shell-1$ ./runjava.sh com.rabbitmq.examples.SimpleConsumer
26+
27+
shell-2$ ./runjava.sh com.rabbitmq.examples.SimpleProducer
28+
29+
shell-1$ ./runjava.sh com.rabbitmq.examples.SimpleConsumer
30+
Message: the time is Fri Feb 26 08:28:58 GMT 2010
31+
32+
Running the examples from the source distribution requries two more
33+
preliminary steps:
34+
35+
shell-1$ ant dist
36+
37+
shell-1$ cd build/dist/
38+
39+
Now, the examples can be run exactly as detailed above.
40+
41+
The more complex examples will require additional command line
42+
arguments and it is best to examine the source of the examples to
43+
determine what arguments are available.
44+
45+
All examples live in the com.rabbitmq.examples package, so just add
46+
that package name to the examples described below to produce the full
47+
classname that is required as the first argument to the runjava
48+
script.
49+
50+
51+
Simple Examples
52+
===============
53+
54+
SimpleProducer - Sends a message to an exchange.
55+
SimpleConsumer - Reads a message from a queue.
56+
SimpleTopicProducer - Sends a message to a topic exchange.
57+
SimpleTopicConsumer - Reads a message from a topic queue.
58+
SendString - Send a string to an exchange.
59+
FileProducer - Sends a file to an exchange.
60+
FileConsumer - Reads a file from a queue.
61+
HelloClient - Performs a simple RPC call over AMQP.
62+
HelloServer - Acts as an RPC server over AMQP.
63+
HelloJsonClient - Performs a simple JSON-RPC call over AMQP.
64+
HelloJsonServer - Acts as a JSON-RPC server over AMQP.
65+
LogTail - Tails the server logs.
66+
SendString - Sends a user supplied message over AMQP.
67+
68+
69+
More Complex Examples
70+
=====================
71+
72+
Most of these examples are used in testing and tuning the RabbitMQ
73+
server.
74+
75+
BufferPerformanceMetrics - Tests buffer sizing.
76+
ChannelCreationPerformance - Test different Channel creation strategies.
77+
ConsumerMain - Measures performance of Consumers.
78+
ManyConnections - Tests many connections.
79+
MulticastMain - Measures performance of multiple consumers and producers.
80+
ProducerMain - Measures performance of Producers.
81+
SpammyTopicProducer - Sends lots of different topic messages over AMQP.
82+
StressPersister - Stress test for persister.
83+
TestMain - RabbitMQ server regression tests.
84+
TracerConcurrencyTest - Tests correct concurrency behaviour of RabbitMQ tracer.

README-TESTS

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
Overview
2+
========
3+
4+
There are multiple test suites in the RabbitMQ Java client library;
5+
the source for all of the suites can be found in the test/src
6+
directory.
7+
8+
The suites are:
9+
10+
Client tests
11+
Functional tests
12+
Server tests
13+
SSL tests
14+
15+
All the tests require a conforming server listening on localhost:5672
16+
(the default settings). For details on running specific tests, see
17+
below.
18+
19+
All the test suites can be run with the command ant test-suite. To run
20+
specific test suites see the instructions below.
21+
22+
23+
Running a Specific Test Suite
24+
=============================
25+
26+
To run a specific test suite, but not the others, you should execute
27+
one of the following in the top-level directory of the source tree:
28+
29+
ant test-client
30+
ant test-functional
31+
ant test-server
32+
ant test-ssl
33+
34+
Note that to run the SSL tests, the RabbitMQ server should be
35+
configured to use SSL as per the SSL with RabbitMQ guide.
36+
37+
The server tests are meant to test a RabbitMQ broker. Broadly, they
38+
require a running RabbitMQ broker on the default host/port, the source
39+
code for rabbitmq-server in ../rabbitmq-server, and a test directory
40+
../rabbitmq-test. Running them manually is a tricky business.
41+
42+
For example, to run the client tests:
43+
44+
----------------- Example shell session -------------------------------------
45+
rabbitmq-java-client$ ant test-client
46+
Buildfile: build.xml
47+
48+
test-prepare:
49+
50+
test-build:
51+
52+
amqp-generate-check:
53+
54+
amqp-generate:
55+
56+
build:
57+
58+
test-build-param:
59+
60+
test-client:
61+
[junit] Running com.rabbitmq.client.test.ClientTests
62+
[junit] Tests run: 31, Failures: 0, Errors: 0, Time elapsed: 2.388 sec
63+
64+
BUILD SUCCESSFUL
65+
-----------------------------------------------------------------------------
66+
67+
If any tests are broken details can be found by viewing this file:
68+
build/TEST-com.rabbitmq.client.test.ClientTests.txt

build.xml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
</fail>
7878
</target>
7979

80-
<target name="build" depends="amqp-generate">
80+
<target name="build" depends="amqp-generate" description="Build the client library.">
8181
<mkdir dir="${javac.out}"/>
8282
<copy file="src/com/rabbitmq/client/impl/ClientVersion.java.in"
8383
tofile="${src.generated}/com/rabbitmq/client/impl/ClientVersion.java">
@@ -116,6 +116,10 @@
116116
<property name="SSL_P12_PASSWORD" value="${env.PASSWORD}"/>
117117
</target>
118118

119+
<target name="detect-umbrella">
120+
<available property="UMBRELLA_AVAILABLE" file="../rabbitmq-test"/>
121+
</target>
122+
119123
<target name="detect-tmpdir">
120124
<property environment="env"/>
121125
<condition property="TMPDIR" value="${env.TMPDIR}" else="/tmp">
@@ -317,7 +321,7 @@
317321
<property name="haltOnFailureJava" value="false" />
318322
</target>
319323

320-
<target name="test-suite" depends="test-suite-prepare, test-suite-run">
324+
<target name="test-suite" depends="test-suite-prepare, test-suite-run" description="Run all test suites.">
321325
<fail message="Errors occured in tests">
322326
<condition>
323327
<not>
@@ -329,7 +333,7 @@
329333

330334
<target name="test-suite-run" depends="test-client, test-ssl, test-server, test-functional, test-main-silent"/>
331335

332-
<target name="test-client" depends="test-build">
336+
<target name="test-client" depends="test-build" description="Run the client test suites.">
333337
<junit printSummary="withOutAndErr"
334338
haltOnFailure="${haltOnFailureJunit}"
335339
failureproperty="test.failure"
@@ -362,7 +366,7 @@
362366
<antcall target="remove-client-keystore"/>
363367
</target>
364368

365-
<target name="test-functional" depends="test-build">
369+
<target name="test-functional" depends="test-build" description="Run the functional test suite.">
366370
<junit printSummary="withOutAndErr"
367371
haltOnFailure="${haltOnFailureJunit}"
368372
failureproperty="test.failure"
@@ -375,7 +379,7 @@
375379
</junit>
376380
</target>
377381

378-
<target name="test-server" depends="test-build">
382+
<target name="test-server" depends="detect-umbrella, test-build" if="UMBRELLA_AVAILABLE">
379383
<junit printSummary="withOutAndErr"
380384
haltOnFailure="${haltOnFailureJunit}"
381385
failureproperty="test.failure"

test/src/com/rabbitmq/client/test/server/Permissions.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public class Permissions extends BrokerTestCase
5252
{
5353

5454
protected Channel adminCh;
55+
protected Connection noAccessConn;
56+
protected Channel noAccessCh;
5557

5658
public Permissions()
5759
{
@@ -81,17 +83,21 @@ protected void addRestrictedAccount()
8183
{
8284
runCtl("add_user test test");
8385
runCtl("add_user testadmin test");
86+
runCtl("add_user noaccess test");
8487
runCtl("add_vhost /test");
8588
runCtl("set_permissions -p /test test configure write read");
8689
runCtl("set_permissions -p /test testadmin \".*\" \".*\" \".*\"");
90+
runCtl("set_permissions -p /test noaccess \"\" \"\" \"\"");
8791
}
8892

8993
protected void deleteRestrictedAccount()
9094
throws IOException
9195
{
96+
runCtl("clear_permissions -p /test noaccess");
9297
runCtl("clear_permissions -p /test testadmin");
9398
runCtl("clear_permissions -p /test test");
9499
runCtl("delete_vhost /test");
100+
runCtl("delete_user noaccess");
95101
runCtl("delete_user testadmin");
96102
runCtl("delete_user test");
97103
}
@@ -117,6 +123,13 @@ public void with(String name) throws IOException {
117123
adminCh.exchangeDeclare(name, "direct");
118124
adminCh.queueDeclare(name, false, false, false, null);
119125
}});
126+
127+
factory = new ConnectionFactory();
128+
factory.setUsername("noaccess");
129+
factory.setPassword("test");
130+
factory.setVirtualHost("/test");
131+
noAccessConn = factory.newConnection();
132+
noAccessCh = noAccessConn.createChannel();
120133
}
121134

122135
protected void releaseResources()
@@ -250,6 +263,69 @@ public void testAltExchConfiguration()
250263
createAltExchConfigTest("configure-and-read-me"));
251264
}
252265

266+
public void testNoAccess()
267+
throws IOException
268+
{
269+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
270+
public void with(String _) throws IOException {
271+
noAccessCh.queueDeclare("justaqueue", false, false, true, null);
272+
}}
273+
);
274+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
275+
public void with(String _) throws IOException {
276+
noAccessCh.queueDelete("configure");
277+
}}
278+
);
279+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
280+
public void with(String _) throws IOException {
281+
noAccessCh.queueBind("write", "write", "write");
282+
}}
283+
);
284+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
285+
public void with(String _) throws IOException {
286+
noAccessCh.queuePurge("read");
287+
}}
288+
);
289+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
290+
public void with(String _) throws IOException {
291+
noAccessCh.exchangeDeclare("justanexchange", "direct");
292+
}}
293+
);
294+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
295+
public void with(String _) throws IOException {
296+
noAccessCh.exchangeDeclare("configure", "direct");
297+
}}
298+
);
299+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
300+
public void with(String _) throws IOException {
301+
noAccessCh.basicPublish("write", "", null, "foo".getBytes());
302+
noAccessCh.queueDeclare();
303+
}}
304+
);
305+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
306+
public void with(String _) throws IOException {
307+
noAccessCh.basicGet("read", false);
308+
}}
309+
);
310+
expectExceptionRun(AMQP.ACCESS_REFUSED, new WithName() {
311+
public void with(String _) throws IOException {
312+
noAccessCh.basicConsume("read", null);
313+
}}
314+
);
315+
}
316+
317+
protected void expectExceptionRun(int exceptionCode, WithName action)
318+
throws IOException
319+
{
320+
try {
321+
action.with("");
322+
fail();
323+
} catch (IOException e) {
324+
noAccessCh = noAccessConn.createChannel();
325+
checkShutdownSignal(exceptionCode, e);
326+
}
327+
}
328+
253329
protected WithName createAltExchConfigTest(final String exchange)
254330
throws IOException
255331
{

0 commit comments

Comments
 (0)