Skip to content

Commit 310801f

Browse files
author
Matthew Sackman
committed
Use exchangeDeclarePassive to assert that exchanges have been deleted
1 parent 03879fe commit 310801f

File tree

1 file changed

+53
-17
lines changed

1 file changed

+53
-17
lines changed

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

Lines changed: 53 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,50 @@
3333

3434
import java.io.IOException;
3535

36+
import com.rabbitmq.client.AMQP;
37+
import com.rabbitmq.client.Channel;
3638
import com.rabbitmq.client.test.BrokerTestCase;
3739

3840
public class ExchangeExchangeBindingsAutoDelete extends BrokerTestCase {
3941

42+
private Channel secondaryChannel = null;
43+
44+
@Override
45+
protected void createResources() throws IOException {
46+
super.createResources();
47+
maybeCreateSecondaryChannel();
48+
}
49+
50+
private void maybeCreateSecondaryChannel() throws IOException {
51+
if (null != secondaryChannel && ! secondaryChannel.isOpen()) {
52+
secondaryChannel = null;
53+
}
54+
if (null == secondaryChannel) {
55+
secondaryChannel = connection.createChannel();
56+
}
57+
}
58+
59+
@Override
60+
protected void releaseResources() throws IOException {
61+
super.releaseResources();
62+
if (null != secondaryChannel && secondaryChannel.isOpen()) {
63+
secondaryChannel.close();
64+
}
65+
}
66+
67+
private void assertExchangeNotExists(String name) throws IOException {
68+
maybeCreateSecondaryChannel();
69+
try {
70+
secondaryChannel.exchangeDeclarePassive(name);
71+
fail("Exchange " + name + " still exists.");
72+
} catch (IOException e) {
73+
checkShutdownSignal(AMQP.NOT_FOUND, e);
74+
}
75+
}
76+
4077
/*
41-
* build (A -> B) and (B -> A) and then delete one binding and
42-
* both exchanges should autodelete
78+
* build (A -> B) and (B -> A) and then delete one binding and both
79+
* exchanges should autodelete
4380
*/
4481
public void testAutoDeleteExchangesSimpleLoop() throws IOException {
4582
channel.exchangeDeclare("A", "fanout", false, true, null);
@@ -48,17 +85,12 @@ public void testAutoDeleteExchangesSimpleLoop() throws IOException {
4885
channel.exchangeBind("B", "A", "");
4986

5087
channel.exchangeUnbind("A", "B", "");
51-
// both exchanges should not exist now, so it should not be an
52-
// error to redeclare either with different arguments
53-
channel.exchangeDeclare("A", "fanout", true, true, null);
54-
channel.exchangeDeclare("B", "fanout", true, true, null);
55-
channel.exchangeDelete("A");
56-
channel.exchangeDelete("B");
88+
assertExchangeNotExists("A");
89+
assertExchangeNotExists("B");
5790
}
5891

5992
/*
60-
* build (A -> B) (B -> C) (C -> D) and then delete D.
61-
* All should autodelete
93+
* build (A -> B) (B -> C) (C -> D) and then delete D. All should autodelete
6294
*/
6395
public void testTransientAutoDelete() throws IOException {
6496
channel.exchangeDeclare("A", "fanout", false, true, null);
@@ -72,14 +104,15 @@ public void testTransientAutoDelete() throws IOException {
72104

73105
channel.exchangeDelete("D");
74106

75-
channel.exchangeDeclare("A", "fanout", true, true, null);
76-
channel.exchangeDelete("A");
107+
assertExchangeNotExists("A");
108+
assertExchangeNotExists("B");
109+
assertExchangeNotExists("C");
110+
assertExchangeNotExists("D");
77111
}
78112

79113
/*
80-
* build (A -> B) (B -> C) (C -> D)
81-
* (Source -> A) (Source -> B) (Source -> C) (Source -> D)
82-
* On removal of D, all should autodelete
114+
* build (A -> B) (B -> C) (C -> D) (Source -> A) (Source -> B) (Source ->
115+
* C) (Source -> D) On removal of D, all should autodelete
83116
*/
84117
public void testRepeatedTargetAutoDelete() throws IOException {
85118
channel.exchangeDeclare("A", "fanout", false, true, null);
@@ -104,7 +137,10 @@ public void testRepeatedTargetAutoDelete() throws IOException {
104137

105138
channel.exchangeDelete("D");
106139

107-
channel.exchangeDeclare("Source", "fanout", true, true, null);
108-
channel.exchangeDelete("Source");
140+
assertExchangeNotExists("Source");
141+
assertExchangeNotExists("A");
142+
assertExchangeNotExists("B");
143+
assertExchangeNotExists("C");
144+
assertExchangeNotExists("D");
109145
}
110146
}

0 commit comments

Comments
 (0)