|
31 | 31 |
|
32 | 32 | package com.rabbitmq.client.test.functional; |
33 | 33 |
|
| 34 | +import com.rabbitmq.client.GetResponse; |
34 | 35 | import com.rabbitmq.client.QueueingConsumer; |
| 36 | +import com.rabbitmq.client.ShutdownSignalException; |
35 | 37 | import com.rabbitmq.client.test.BrokerTestCase; |
36 | 38 |
|
37 | 39 | import java.io.IOException; |
|
45 | 47 | // ------- ------- |
46 | 48 | // -/ \- -/ \- |
47 | 49 | // / \ / \ +-------------+ |
48 | | -// | e0 +------| e1 +-----------+ q1 | |
| 50 | +// | e0 +------| e1 +-----------+ q1 | |
49 | 51 | // \ / \ / +-------------+ |
50 | 52 | // -\ /- -\ /- |
51 | 53 | // ------- ------- |
52 | 54 | // (internal) |
53 | 55 | // |
| 56 | +// Where a non-internal exchange is bound to an internal exchange, which in |
| 57 | +// turn is bound to a queue. A client should be able to publish to e0, but |
| 58 | +// not to e1, and publications to e0 should be delivered into q1. |
| 59 | +// |
54 | 60 | public class InternalExchangeTest extends BrokerTestCase |
55 | 61 | { |
56 | 62 | private final String[] queues = new String[] { "q1" }; |
@@ -94,19 +100,30 @@ protected void releaseResources() throws IOException |
94 | 100 | } |
95 | 101 |
|
96 | 102 |
|
97 | | - public void testOhForFucksSake() throws IOException, InterruptedException |
| 103 | + public void testTryPublishingToInternalExchange() |
| 104 | + throws IOException, |
| 105 | + InterruptedException |
98 | 106 | { |
99 | | - System.out.println("Yes, there is a test here."); |
| 107 | + byte[] testDataBody = "test-data".getBytes(); |
100 | 108 |
|
101 | | - // Create a simple consumer to try to catch stuff we've published... |
102 | | - if(false) |
103 | | - { |
104 | | - QueueingConsumer consumer = new QueueingConsumer(channel); |
105 | | - channel.basicConsume("q1", false, consumer); |
| 109 | + // We should be able to publish to the non-internal exchange as usual |
| 110 | + // and see our message land in the queue... |
| 111 | + channel.basicPublish("e0", "", null, testDataBody); |
| 112 | + assertTrue(channel.isOpen()); |
| 113 | + GetResponse r = channel.basicGet("q1", true); |
| 114 | + assertTrue(Arrays.equals(r.getBody(), testDataBody)); |
106 | 115 |
|
107 | | - QueueingConsumer.Delivery delivery = consumer.nextDelivery(); |
108 | | - // process delivery |
109 | | - channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false); |
110 | | - } |
| 116 | + |
| 117 | + // Publishing to the internal exchange will not be allowed... |
| 118 | + channel.basicPublish("e1", "", null, testDataBody); |
| 119 | + Thread.sleep(250L); |
| 120 | + assertFalse(channel.isOpen()); |
| 121 | + ShutdownSignalException sdse = channel.getCloseReason(); |
| 122 | + assertNotNull(sdse); |
| 123 | + String message = sdse.getMessage(); |
| 124 | + assertTrue(message.contains("reply-code=403")); |
| 125 | + assertTrue(message.contains("reply-text=ACCESS_REFUSED")); |
| 126 | + assertTrue(message.contains("cannot publish to internal exchange")); |
111 | 127 | } |
| 128 | + |
112 | 129 | } |
0 commit comments