Skip to content

Commit 26a9815

Browse files
author
Jerry Kuch
committed
Functional test for internal exchanges.
1 parent 3cf26e5 commit 26a9815

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public static TestSuite suite() {
7070
suite.addTestSuite(RecoverAfterCancel.class);
7171
suite.addTestSuite(UnexpectedFrames.class);
7272
suite.addTestSuite(PerQueueTTL.class);
73-
73+
suite.addTestSuite(InternalExchangeTest.class);
7474
return suite;
7575
}
7676
}

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

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

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

34+
import com.rabbitmq.client.GetResponse;
3435
import com.rabbitmq.client.QueueingConsumer;
36+
import com.rabbitmq.client.ShutdownSignalException;
3537
import com.rabbitmq.client.test.BrokerTestCase;
3638

3739
import java.io.IOException;
@@ -45,12 +47,16 @@
4547
// ------- -------
4648
// -/ \- -/ \-
4749
// / \ / \ +-------------+
48-
// | e0 +------| e1 +-----------+ q1 |
50+
// | e0 +------| e1 +-----------+ q1 |
4951
// \ / \ / +-------------+
5052
// -\ /- -\ /-
5153
// ------- -------
5254
// (internal)
5355
//
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+
//
5460
public class InternalExchangeTest extends BrokerTestCase
5561
{
5662
private final String[] queues = new String[] { "q1" };
@@ -94,19 +100,30 @@ protected void releaseResources() throws IOException
94100
}
95101

96102

97-
public void testOhForFucksSake() throws IOException, InterruptedException
103+
public void testTryPublishingToInternalExchange()
104+
throws IOException,
105+
InterruptedException
98106
{
99-
System.out.println("Yes, there is a test here.");
107+
byte[] testDataBody = "test-data".getBytes();
100108

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));
106115

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"));
111127
}
128+
112129
}

0 commit comments

Comments
 (0)