Skip to content

Commit cbbb571

Browse files
author
Matthew Sackman
committed
merge bug20633 into default
2 parents 37f02ec + 3761220 commit cbbb571

File tree

2 files changed

+45
-48
lines changed

2 files changed

+45
-48
lines changed

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

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

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

34+
import com.rabbitmq.client.AMQP;
3435
import com.rabbitmq.client.Channel;
3536
import com.rabbitmq.client.Connection;
3637
import com.rabbitmq.client.GetResponse;
@@ -48,8 +49,6 @@
4849
* primary node is still running. That way we exercise any node-down
4950
* handler code in the server.
5051
*
51-
* TODO: Adjust this test when Queue.Unbind is implemented in the
52-
* server
5352
*/
5453
public class BindingLifecycle extends PersisterRestartBase {
5554

@@ -203,9 +202,7 @@ public void testQueueDelete() throws IOException {
203202

204203
// Nuke the queue and repeat this test, this time you expect
205204
// nothing to get routed.
206-
//
207-
// TODO: When unbind is implemented, use that instead of
208-
// deleting and re-creating the queue
205+
209206
channel.queueDelete(binding.q);
210207
channel.queueDeclare(binding.q, durable);
211208

@@ -313,6 +310,45 @@ public void testExchangeAutoDeleteDurableManyBindings() throws IOException {
313310
doAutoDelete(true, 10);
314311
}
315312

313+
/**
314+
* Test the behaviour of queue.unbind
315+
*/
316+
public void testUnbind() throws Exception {
317+
318+
Binding b = new Binding(channel.queueDeclare().getQueue(),
319+
"amq.direct",
320+
"quay");
321+
322+
// failure cases
323+
324+
Binding[] tests = new Binding[] {
325+
new Binding("unknown_queue", b.x, b.k),
326+
new Binding(b.q, "unknown_exchange", b.k),
327+
new Binding("unknown_unknown", "exchange_queue", b.k),
328+
new Binding(b.q, b.x, "unknown_rk"),
329+
new Binding("unknown_queue", "unknown_exchange", "unknown_rk")
330+
};
331+
332+
for (int i = 0; i < tests.length; i++) {
333+
334+
Binding test = tests[i];
335+
try {
336+
channel.queueUnbind(test.q, test.x, test.k);
337+
fail("expected not_found in test " + i);
338+
} catch (IOException ee) {
339+
checkShutdownSignal(AMQP.NOT_FOUND, ee);
340+
openChannel();
341+
}
342+
}
343+
344+
// success case
345+
346+
channel.queueBind(b.q, b.x, b.k);
347+
sendRoutable(b);
348+
channel.queueUnbind(b.q, b.x, b.k);
349+
sendUnroutable(b);
350+
}
351+
316352
private void doAutoDelete(boolean durable, int queues) throws IOException {
317353

318354
String[] queueNames = null;
@@ -350,7 +386,7 @@ private void doAutoDelete(boolean durable, int queues) throws IOException {
350386
for (String s : queueNames) {
351387
channel.basicConsume(s, true,
352388
new QueueingConsumer(channel));
353-
Binding tmp = new Binding(binding.x, s, binding.k);
389+
Binding tmp = new Binding(s, binding.x, binding.k);
354390
sendUnroutable(tmp);
355391
}
356392
}
@@ -410,15 +446,15 @@ private static String randomString() {
410446

411447
private static class Binding {
412448

413-
String x, q, k;
449+
String q, x, k;
414450

415451
static Binding randomBinding() {
416452
return new Binding(randomString(), randomString(), randomString());
417453
}
418454

419-
private Binding(String x, String q, String k) {
420-
this.x = x;
455+
private Binding(String q, String x, String k) {
421456
this.q = q;
457+
this.x = x;
422458
this.k = k;
423459
}
424460
}

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

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -217,43 +217,4 @@ public void testHeadersRouting() throws Exception {
217217
checkGet(Q2, false);
218218
}
219219

220-
public void testUnbind() throws Exception {
221-
222-
String x = "amq.direct";
223-
String q = "testUnbind";
224-
String routingKey = "quay";
225-
226-
AMQP.Queue.DeclareOk ok = channel.queueDeclare(q);
227-
channel.queueBind(q, x, routingKey);
228-
channel.basicPublish(x, routingKey, null, "foobar".getBytes());
229-
checkGet(q, true);
230-
231-
String[][] tests = new String[][] {
232-
new String[] {"unknown_queue", x, routingKey},
233-
new String[] {q, "unknown_exchange", routingKey},
234-
new String[] {"unknown_queue", "unknown_exchange", routingKey},
235-
// see bug 20633
236-
// new String[] {q, x, "unknown_rk"},
237-
new String[] {"unknown_queue", "unknown_exchange", "unknown_rk"}
238-
};
239-
240-
for (int i = 0; i < tests.length; i++) {
241-
242-
String[] test = tests[i];
243-
try {
244-
channel.queueUnbind(test[0], test[1], test[2]);
245-
fail("expected not_found in test " + i);
246-
} catch (IOException ee) {
247-
checkShutdownSignal(AMQP.NOT_FOUND, ee);
248-
openChannel();
249-
}
250-
}
251-
252-
channel.queueUnbind(q, x, routingKey);
253-
254-
channel.basicPublish(x, routingKey, null, "foobar".getBytes());
255-
checkGet(q, false);
256-
257-
channel.queueDelete(q);
258-
}
259220
}

0 commit comments

Comments
 (0)