Skip to content

Commit 9dd1d05

Browse files
committed
merge bug20630 into v1_5
2 parents 7ce6453 + e7ad09f commit 9dd1d05

File tree

4 files changed

+117
-8
lines changed

4 files changed

+117
-8
lines changed

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,12 @@
3636
import junit.framework.TestCase;
3737

3838
import com.rabbitmq.client.Channel;
39+
import com.rabbitmq.client.Command;
3940
import com.rabbitmq.client.Connection;
4041
import com.rabbitmq.client.ConnectionFactory;
42+
import com.rabbitmq.client.ShutdownSignalException;
43+
44+
import com.rabbitmq.client.AMQP;
4145

4246
public class BrokerTestCase extends TestCase
4347
{
@@ -120,4 +124,17 @@ public void closeChannel()
120124
}
121125
}
122126

127+
public void checkShutdownSignal(int expectedCode, IOException ioe) {
128+
ShutdownSignalException sse = (ShutdownSignalException) ioe.getCause();
129+
Command closeCommand = (Command) sse.getReason();
130+
channel = null;
131+
if (sse.isHardError()) {
132+
connection = null;
133+
AMQP.Connection.Close closeMethod = (AMQP.Connection.Close) closeCommand.getMethod();
134+
assertEquals(expectedCode, closeMethod.getReplyCode());
135+
} else {
136+
AMQP.Channel.Close closeMethod = (AMQP.Channel.Close) closeCommand.getMethod();
137+
assertEquals(expectedCode, closeMethod.getReplyCode());
138+
}
139+
}
123140
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.ShutdownSignalException;
36+
import java.io.IOException;
37+
38+
public class DoubleDeletion extends BrokerTestCase
39+
{
40+
protected static final String Q = "DoubleDeletionQueue";
41+
protected static final String X = "DoubleDeletionExchange";
42+
43+
public void testDoubleDeletionQueue()
44+
throws IOException
45+
{
46+
channel.queueDeclare(Q);
47+
channel.queueDelete(Q);
48+
try {
49+
channel.queueDelete(Q);
50+
fail("Expected exception from double deletion of queue");
51+
} catch (IOException ee) {
52+
checkShutdownSignal(AMQP.NOT_FOUND, ee);
53+
// Pass!
54+
}
55+
}
56+
57+
public void testDoubleDeletionExchange()
58+
throws IOException
59+
{
60+
channel.exchangeDeclare(X, "direct");
61+
channel.exchangeDelete(X);
62+
try {
63+
channel.exchangeDelete(X);
64+
fail("Expected exception from double deletion of exchange");
65+
} catch (IOException ee) {
66+
checkShutdownSignal(AMQP.NOT_FOUND, ee);
67+
// Pass!
68+
}
69+
}
70+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
public class FunctionalTests extends TestCase {
3838
public static TestSuite suite() {
3939
TestSuite suite = new TestSuite("functional");
40+
suite.addTestSuite(DoubleDeletion.class);
4041
suite.addTestSuite(Routing.class);
4142
suite.addTestSuite(BindingLifecycle.class);
4243
suite.addTestSuite(Transactions.class);

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,21 +165,42 @@ public void testTopicRouting() throws Exception {
165165
}
166166

167167
public void testUnbind() throws Exception {
168-
AMQP.Queue.DeclareOk ok = channel.queueDeclare();
169-
String queue = ok.getQueue();
170168

171-
String routingKey = "quay";
172169
String x = "amq.direct";
170+
String q = "testUnbind";
171+
String routingKey = "quay";
173172

174-
channel.queueBind(queue, x, routingKey);
173+
AMQP.Queue.DeclareOk ok = channel.queueDeclare(q);
174+
channel.queueBind(q, x, routingKey);
175175
channel.basicPublish(x, routingKey, null, "foobar".getBytes());
176-
checkGet(queue, true);
176+
checkGet(q, true);
177+
178+
String[][] tests = new String[][] {
179+
new String[] {"unknown_queue", x, routingKey},
180+
new String[] {q, "unknown_exchange", routingKey},
181+
new String[] {"unknown_queue", "unknown_exchange", routingKey},
182+
// see bug 20633
183+
// new String[] {q, x, "unknown_rk"},
184+
new String[] {"unknown_queue", "unknown_exchange", "unknown_rk"}
185+
};
186+
187+
for (int i = 0; i < tests.length; i++) {
188+
189+
String[] test = tests[i];
190+
try {
191+
channel.queueUnbind(test[0], test[1], test[2]);
192+
fail("expected not_found in test " + i);
193+
} catch (IOException ee) {
194+
checkShutdownSignal(AMQP.NOT_FOUND, ee);
195+
openChannel();
196+
}
197+
}
177198

178-
channel.queueUnbind(queue, x, routingKey);
199+
channel.queueUnbind(q, x, routingKey);
179200

180201
channel.basicPublish(x, routingKey, null, "foobar".getBytes());
181-
checkGet(queue, false);
202+
checkGet(q, false);
182203

183-
channel.queueDelete(queue);
204+
channel.queueDelete(q);
184205
}
185206
}

0 commit comments

Comments
 (0)