Skip to content

Commit da07598

Browse files
author
Matthew Sackman
committed
Merging bug 22848 onto default
2 parents 8d560a4 + a1c17dd commit da07598

File tree

10 files changed

+173
-16
lines changed

10 files changed

+173
-16
lines changed

src/com/rabbitmq/client/Channel.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,9 @@ Exchange.DeclareOk exchangeDeclare(String exchange, String type, boolean durable
225225
/**
226226
* Declare an exchange passively; that is, check if the named exchange exists.
227227
* @param name check the existence of an exchange named this
228-
* @param type the exchange type
229228
* @throws IOException the server will raise a 404 channel exception if the named exchange does not exist.
230229
*/
231-
Exchange.DeclareOk exchangeDeclarePassive(String name, String type) throws IOException;
230+
Exchange.DeclareOk exchangeDeclarePassive(String name) throws IOException;
232231

233232
/**
234233
* Delete an exchange

src/com/rabbitmq/client/impl/ChannelN.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,11 +433,11 @@ public Exchange.DeclareOk exchangeDeclare(String exchange, String type)
433433
}
434434

435435
/** Public API - {@inheritDoc} */
436-
public Exchange.DeclareOk exchangeDeclarePassive(String exchange, String type)
436+
public Exchange.DeclareOk exchangeDeclarePassive(String exchange)
437437
throws IOException
438438
{
439439
return (Exchange.DeclareOk)
440-
exnWrappingRpc(new Exchange.Declare(TICKET, exchange, type,
440+
exnWrappingRpc(new Exchange.Declare(TICKET, exchange, "",
441441
true, false, false,
442442
false, false, null)).getMethod();
443443
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,10 @@ public void testExchangeAutoDeleteManyBindings() throws IOException {
186186
*/
187187
public void testExchangePassiveDeclare() throws IOException {
188188
channel.exchangeDeclare("testPassive", "direct");
189-
channel.exchangeDeclarePassive("testPassive", "direct");
189+
channel.exchangeDeclarePassive("testPassive");
190190

191191
try {
192-
channel.exchangeDeclarePassive("unknown_exchange", "direct");
192+
channel.exchangeDeclarePassive("unknown_exchange");
193193
fail("Passive declare of an unknown exchange should fail");
194194
}
195195
catch (IOException ioe) {
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 java.util.Map;
35+
import java.util.HashMap;
36+
import java.io.IOException;
37+
38+
import com.rabbitmq.client.Channel;
39+
40+
import com.rabbitmq.client.test.BrokerTestCase;
41+
42+
public class ExchangeDeclare extends BrokerTestCase {
43+
44+
static final String TYPE = "direct";
45+
46+
static final String NAME = "exchange_test";
47+
48+
public void releaseResources() throws IOException {
49+
channel.exchangeDelete(NAME);
50+
}
51+
52+
public static void verifyEquivalent(Channel channel, String name,
53+
String type, boolean durable, boolean autoDelete,
54+
Map<String, Object> args) throws IOException {
55+
channel.exchangeDeclarePassive(name);
56+
channel.exchangeDeclare(name, type, durable, autoDelete, args);
57+
}
58+
59+
// Note: this will close the channel
60+
public static void verifyNotEquivalent(Channel channel, String name,
61+
String type, boolean durable, boolean autoDelete,
62+
Map<String, Object> args) throws IOException {
63+
channel.exchangeDeclarePassive(name);
64+
try {
65+
channel.exchangeDeclare(name, type, durable, autoDelete, args);
66+
fail("Exchange was supposed to be not equivalent");
67+
} catch (IOException ioe) {
68+
return;
69+
}
70+
}
71+
72+
public void testExchangeNoArgsEquivalence() throws IOException {
73+
channel.exchangeDeclare(NAME, TYPE, false, false, null);
74+
verifyEquivalent(channel, NAME, TYPE, false, false, null);
75+
}
76+
77+
public void testExchangeNonsenseArgsEquivalent() throws IOException {
78+
channel.exchangeDeclare(NAME, TYPE, false, false, null);
79+
Map<String, Object> args = new HashMap<String, Object>();
80+
args.put("nonsensical-argument-surely-not-in-use", "foo");
81+
verifyEquivalent(channel, NAME, TYPE, false, false, args);
82+
}
83+
84+
public void testExchangeDurableNotEquivalent() throws IOException {
85+
channel.exchangeDeclare(NAME, TYPE, false, false, null);
86+
verifyNotEquivalent(channel, NAME, TYPE, true, false, null);
87+
}
88+
89+
public void testExchangeTypeNotEquivalent() throws IOException {
90+
channel.exchangeDeclare(NAME, "direct", false, false, null);
91+
verifyNotEquivalent(channel, NAME, "fanout", false, false, null);
92+
}
93+
94+
public void testExchangeAutoDeleteNotEquivalent() throws IOException {
95+
channel.exchangeDeclare(NAME, "direct", false, false, null);
96+
verifyNotEquivalent(channel, NAME, "direct", false, true, null);
97+
}
98+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public static TestSuite suite() {
5252
suite.addTestSuite(Bug20004Test.class);
5353
suite.addTestSuite(QosTests.class);
5454
suite.addTestSuite(AlternateExchange.class);
55+
suite.addTestSuite(ExchangeDeclare.class);
5556
suite.addTestSuite(QueueLifecycle.class);
5657
suite.addTestSuite(QueueExclusivity.class);
5758
return suite;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,17 @@ public void testQueueEquivalence() throws IOException {
107107
}
108108

109109
// not equivalent in various ways
110-
// We don't enforce this for 0-8
111-
// public void testQueueNonEquivalenceDurable() throws IOException {
112-
// verifyNotEquivalent(true, false, false);
113-
// }
110+
public void testQueueNonEquivalenceDurable() throws IOException {
111+
verifyNotEquivalent(true, false, false);
112+
}
114113

115114
public void testQueueNonEquivalenceExclusive() throws IOException {
116115
verifyNotEquivalent(false, true, false);
117116
}
118117

119-
// We don't enforce this for 0-8
120-
// public void testQueueNonEquivalenceAutoDelete() throws IOException {
121-
// verifyNotEquivalent(false, false, true);
122-
// }
118+
public void testQueueNonEquivalenceAutoDelete() throws IOException {
119+
verifyNotEquivalent(false, false, true);
120+
}
123121

124122
// Note that this assumes that auto-deletion is synchronous with
125123
// basic.cancel,
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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.server;
33+
34+
import java.util.Map;
35+
import java.util.HashMap;
36+
import java.io.IOException;
37+
38+
import com.rabbitmq.client.test.BrokerTestCase;
39+
import com.rabbitmq.client.test.functional.ExchangeDeclare;
40+
41+
public class ExchangeEquivalence extends BrokerTestCase {
42+
static Map<String, Object> args = new HashMap<String, Object>();
43+
{
44+
args.put("alternate-exchange", "UME");
45+
}
46+
47+
public void testAlternateExchangeEquivalence() throws IOException {
48+
channel.exchangeDeclare("alternate", "direct", false, false, args);
49+
ExchangeDeclare.verifyEquivalent(channel, "alternate", "direct", false,
50+
false, args);
51+
}
52+
53+
public void testAlternateExchangeNonEquivalence() throws IOException {
54+
channel.exchangeDeclare("alternate", "direct", false, false, args);
55+
Map<String, Object> altargs = new HashMap<String, Object>();
56+
altargs.put("alternate-exchange", "somewhere");
57+
ExchangeDeclare.verifyNotEquivalent(channel, "alternate", "direct",
58+
false, false, altargs);
59+
}
60+
}

test/src/com/rabbitmq/client/test/server/Permissions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void with(String name) throws IOException {
162162
}});
163163
runConfigureTest(new WithName() {
164164
public void with(String name) throws IOException {
165-
channel.exchangeDeclarePassive(name, "direct");
165+
channel.exchangeDeclarePassive(name);
166166
}});
167167
runConfigureTest(new WithName() {
168168
public void with(String name) throws IOException {

test/src/com/rabbitmq/client/test/server/ServerTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public static TestSuite suite() {
4242
suite.addTestSuite(EffectVisibilityCrossNodeTest.class);
4343
suite.addTest(PersisterRestartTests.suite());
4444
suite.addTestSuite(ExclusiveQueueDurability.class);
45+
suite.addTestSuite(ExchangeEquivalence.class);
4546
return suite;
4647
}
4748
}

test/src/com/rabbitmq/examples/ProducerMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ private void runIt() throws IOException {
159159

160160
if (_sendCompletion) {
161161
String exchangeName = "test completion";
162-
_channel.exchangeDeclarePassive(exchangeName, "fanout");
162+
_channel.exchangeDeclarePassive(exchangeName);
163163
_channel.basicPublish(exchangeName, "", MessageProperties.BASIC, new byte[0]);
164164
if (shouldCommit())
165165
_channel.txCommit();

0 commit comments

Comments
 (0)