Skip to content

Commit 322fe42

Browse files
author
Michael Bridgen
committed
Torturously extract more generic conformance tests from those that require a restart
1 parent 0dc5536 commit 322fe42

File tree

11 files changed

+329
-683
lines changed

11 files changed

+329
-683
lines changed

test/src/com/rabbitmq/client/test/BrokerTestCase.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import com.rabbitmq.client.Command;
4040
import com.rabbitmq.client.Connection;
4141
import com.rabbitmq.client.ConnectionFactory;
42+
import com.rabbitmq.client.GetResponse;
43+
import com.rabbitmq.client.MessageProperties;
4244
import com.rabbitmq.client.ShutdownSignalException;
4345

4446
import com.rabbitmq.client.AMQP;
@@ -137,4 +139,64 @@ public void checkShutdownSignal(int expectedCode, IOException ioe) {
137139
assertEquals(expectedCode, closeMethod.getReplyCode());
138140
}
139141
}
142+
143+
protected void assertDelivered(String q, int count) throws IOException {
144+
assertDelivered(q, count, false);
145+
}
146+
147+
protected void assertDelivered(String q, int count, boolean redelivered) throws IOException {
148+
GetResponse r;
149+
for (int i = 0; i < count; i++) {
150+
r = basicGet(q);
151+
assertNotNull(r);
152+
assertEquals(r.getEnvelope().isRedeliver(), redelivered);
153+
}
154+
assertNull(basicGet(q));
155+
}
156+
157+
protected GetResponse basicGet(String q) throws IOException {
158+
return channel.basicGet(q, true);
159+
}
160+
161+
protected void basicPublishPersistent(String q) throws IOException {
162+
channel.basicPublish("", q, MessageProperties.PERSISTENT_TEXT_PLAIN, "persistent message".getBytes());
163+
}
164+
165+
protected void basicPublishPersistent(String x, String routingKey) throws IOException {
166+
channel.basicPublish(x, routingKey, MessageProperties.PERSISTENT_TEXT_PLAIN, "persistent message".getBytes());
167+
}
168+
169+
protected void basicPublishVolatile(String q) throws IOException {
170+
channel.basicPublish("", q, MessageProperties.TEXT_PLAIN, "not persistent message".getBytes());
171+
}
172+
173+
protected void basicPublishVolatile(String x, String routingKey) throws IOException {
174+
channel.basicPublish(x, routingKey, MessageProperties.TEXT_PLAIN, "not persistent message".getBytes());
175+
}
176+
177+
protected void declareAndBindDurableQueue(String q, String x, String r) throws IOException {
178+
declareDurableQueue(q);
179+
channel.queueBind(q, x, r);
180+
}
181+
182+
protected void declareDurableDirectExchange(String x) throws IOException {
183+
channel.exchangeDeclare(x, "direct", true);
184+
}
185+
186+
protected void declareDurableQueue(String q) throws IOException {
187+
channel.queueDeclare(q, true);
188+
}
189+
190+
protected void declareDurableTopicExchange(String x) throws IOException {
191+
channel.exchangeDeclare(x, "topic", true);
192+
}
193+
194+
protected void deleteExchange(String x) throws IOException {
195+
channel.exchangeDelete(x);
196+
}
197+
198+
protected void deleteQueue(String q) throws IOException {
199+
channel.queueDelete(q);
200+
}
201+
140202
}
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// The contents of this file are subject to the Mozilla Public License
2+
// Version 1.1 (the "License"); you may not use this file except in
3+
// compliance with the License. You may obtain a copy of the License at
4+
// http://www.mozilla.org/MPL/
5+
//
6+
// Software distributed under the License is distributed on an "AS IS"
7+
// basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
8+
// License for the specific language governing rights and limitations
9+
// under the License.
10+
//
11+
// The Original Code is RabbitMQ.
12+
//
13+
// The Initial Developers of the Original Code are LShift Ltd,
14+
// Cohesive Financial Technologies LLC, and Rabbit Technologies Ltd.
15+
//
16+
// Portions created before 22-Nov-2008 00:00:00 GMT by LShift Ltd,
17+
// Cohesive Financial Technologies LLC, or Rabbit Technologies Ltd
18+
// are Copyright (C) 2007-2008 LShift Ltd, Cohesive Financial
19+
// Technologies LLC, and Rabbit Technologies Ltd.
20+
//
21+
// Portions created by LShift Ltd are Copyright (C) 2007-2009 LShift
22+
// Ltd. Portions created by Cohesive Financial Technologies LLC are
23+
// Copyright (C) 2007-2009 Cohesive Financial Technologies
24+
// LLC. Portions created by Rabbit Technologies Ltd are Copyright
25+
// (C) 2007-2009 Rabbit Technologies Ltd.
26+
//
27+
// All Rights Reserved.
28+
//
29+
// Contributor(s): ______________________________________.
30+
//
31+
32+
package com.rabbitmq.client.test.functional;
33+
34+
import com.rabbitmq.client.AMQP;
35+
import com.rabbitmq.client.Channel;
36+
import com.rabbitmq.client.Connection;
37+
import com.rabbitmq.client.GetResponse;
38+
import com.rabbitmq.client.QueueingConsumer;
39+
40+
import java.io.IOException;
41+
42+
/**
43+
* This tests whether bindings are created and nuked properly.
44+
*
45+
* The tests attempt to declare durable queues on a secondary node, if
46+
* present, and that node is restarted as part of the tests while the
47+
* primary node is still running. That way we exercise any node-down
48+
* handler code in the server.
49+
*
50+
*/
51+
public class BindingLifecycle extends BindingLifecycleBase {
52+
53+
/**
54+
* This tests that when you purge a queue, all of its messages go.
55+
*/
56+
public void testQueuePurge() throws IOException {
57+
58+
Binding binding = setupExchangeBindings(false);
59+
channel.basicPublish(binding.x, binding.k, null, payload);
60+
61+
// Purge the queue, and test that we don't recieve a message
62+
channel.queuePurge(binding.q);
63+
64+
GetResponse response = channel.basicGet(binding.q, true);
65+
assertNull("The response SHOULD BE null", response);
66+
67+
deleteExchangeAndQueue(binding);
68+
}
69+
70+
/**
71+
* This tests whether when you delete an exchange, that any
72+
* bindings attached to it are deleted as well.
73+
*/
74+
public void testExchangeDelete() throws IOException {
75+
76+
boolean durable = true;
77+
Binding binding = setupExchangeAndRouteMessage(durable);
78+
79+
// Nuke the exchange and repeat this test, this time you
80+
// expect nothing to get routed
81+
82+
channel.exchangeDelete(binding.x);
83+
channel.exchangeDeclare(binding.x, "direct");
84+
85+
sendUnroutable(binding);
86+
87+
channel.queueDelete(binding.q);
88+
}
89+
90+
/**
91+
* This tests whether the server checks that an exchange is
92+
* actually being used when you try to delete it with the ifunused
93+
* flag.
94+
*
95+
* To test this, you try to delete an exchange with a queue still
96+
* bound to it and expect the delete operation to fail.
97+
*/
98+
public void testExchangeIfUnused() throws IOException {
99+
100+
boolean durable = true;
101+
Binding binding = setupExchangeBindings(durable);
102+
103+
try {
104+
channel.exchangeDelete(binding.x, true);
105+
}
106+
catch (Exception e) {
107+
// do nothing, this is the correct behaviour
108+
openChannel();
109+
deleteExchangeAndQueue(binding);
110+
return;
111+
}
112+
113+
fail("Exchange delete should have failed");
114+
}
115+
116+
/**
117+
* This tests whether the server checks that an auto_delete
118+
* exchange actually deletes the bindings attached to it when it
119+
* is deleted.
120+
*
121+
* To test this, you declare and auto_delete exchange and bind an
122+
* auto_delete queue to it.
123+
*
124+
* Start a consumer on this queue, send a message, let it get
125+
* consumed and then cancel the consumer
126+
*
127+
* The unsubscribe should cause the queue to auto_delete, which in
128+
* turn should cause the exchange to auto_delete.
129+
*
130+
* Then re-declare the queue again and try to rebind it to the same exhange.
131+
*
132+
* Because the exchange has been auto-deleted, the bind operation
133+
* should fail.
134+
*/
135+
public void testExchangeAutoDelete() throws IOException {
136+
doAutoDelete(false, 1);
137+
}
138+
139+
/**
140+
* Runs something similar to testExchangeAutoDelete, but adds
141+
* different queues with the same binding to the same exchange.
142+
*
143+
* The difference should be that the original exchange should not
144+
* get auto-deleted
145+
*/
146+
public void testExchangeAutoDeleteManyBindings() throws IOException {
147+
doAutoDelete(false, 10);
148+
}
149+
150+
/**
151+
* Test the behaviour of queue.unbind
152+
*/
153+
public void testUnbind() throws Exception {
154+
155+
Binding b = new Binding(channel.queueDeclare().getQueue(),
156+
"amq.direct",
157+
"quay");
158+
159+
// failure cases
160+
161+
Binding[] tests = new Binding[] {
162+
new Binding("unknown_queue", b.x, b.k),
163+
new Binding(b.q, "unknown_exchange", b.k),
164+
new Binding("unknown_unknown", "exchange_queue", b.k),
165+
new Binding(b.q, b.x, "unknown_rk"),
166+
new Binding("unknown_queue", "unknown_exchange", "unknown_rk")
167+
};
168+
169+
for (int i = 0; i < tests.length; i++) {
170+
171+
Binding test = tests[i];
172+
try {
173+
channel.queueUnbind(test.q, test.x, test.k);
174+
fail("expected not_found in test " + i);
175+
} catch (IOException ee) {
176+
checkShutdownSignal(AMQP.NOT_FOUND, ee);
177+
openChannel();
178+
}
179+
}
180+
181+
// success case
182+
183+
channel.queueBind(b.q, b.x, b.k);
184+
sendRoutable(b);
185+
channel.queueUnbind(b.q, b.x, b.k);
186+
sendUnroutable(b);
187+
}
188+
189+
}

test/src/com/rabbitmq/client/test/functional/FunctionalTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
package com.rabbitmq.client.test.functional;
3333

34-
import com.rabbitmq.client.test.server.BindingLifecycle;
3534
import com.rabbitmq.client.test.Bug20004Test;
3635
import com.rabbitmq.client.test.server.Permissions;
3736
import junit.framework.TestCase;

0 commit comments

Comments
 (0)