|
31 | 31 |
|
32 | 32 | package com.rabbitmq.client.test.functional; |
33 | 33 |
|
| 34 | +import com.rabbitmq.client.AMQP; |
34 | 35 | import com.rabbitmq.client.Channel; |
35 | 36 | import com.rabbitmq.client.Connection; |
36 | 37 | import com.rabbitmq.client.GetResponse; |
|
48 | 49 | * primary node is still running. That way we exercise any node-down |
49 | 50 | * handler code in the server. |
50 | 51 | * |
51 | | - * TODO: Adjust this test when Queue.Unbind is implemented in the |
52 | | - * server |
53 | 52 | */ |
54 | 53 | public class BindingLifecycle extends PersisterRestartBase { |
55 | 54 |
|
@@ -203,9 +202,7 @@ public void testQueueDelete() throws IOException { |
203 | 202 |
|
204 | 203 | // Nuke the queue and repeat this test, this time you expect |
205 | 204 | // nothing to get routed. |
206 | | - // |
207 | | - // TODO: When unbind is implemented, use that instead of |
208 | | - // deleting and re-creating the queue |
| 205 | + |
209 | 206 | channel.queueDelete(binding.q); |
210 | 207 | channel.queueDeclare(binding.q, durable); |
211 | 208 |
|
@@ -313,6 +310,45 @@ public void testExchangeAutoDeleteDurableManyBindings() throws IOException { |
313 | 310 | doAutoDelete(true, 10); |
314 | 311 | } |
315 | 312 |
|
| 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 | + |
316 | 352 | private void doAutoDelete(boolean durable, int queues) throws IOException { |
317 | 353 |
|
318 | 354 | String[] queueNames = null; |
@@ -350,7 +386,7 @@ private void doAutoDelete(boolean durable, int queues) throws IOException { |
350 | 386 | for (String s : queueNames) { |
351 | 387 | channel.basicConsume(s, true, |
352 | 388 | new QueueingConsumer(channel)); |
353 | | - Binding tmp = new Binding(binding.x, s, binding.k); |
| 389 | + Binding tmp = new Binding(s, binding.x, binding.k); |
354 | 390 | sendUnroutable(tmp); |
355 | 391 | } |
356 | 392 | } |
@@ -410,15 +446,15 @@ private static String randomString() { |
410 | 446 |
|
411 | 447 | private static class Binding { |
412 | 448 |
|
413 | | - String x, q, k; |
| 449 | + String q, x, k; |
414 | 450 |
|
415 | 451 | static Binding randomBinding() { |
416 | 452 | return new Binding(randomString(), randomString(), randomString()); |
417 | 453 | } |
418 | 454 |
|
419 | | - private Binding(String x, String q, String k) { |
420 | | - this.x = x; |
| 455 | + private Binding(String q, String x, String k) { |
421 | 456 | this.q = q; |
| 457 | + this.x = x; |
422 | 458 | this.k = k; |
423 | 459 | } |
424 | 460 | } |
|
0 commit comments