Skip to content

Commit 5e34120

Browse files
RabbitMQ main disables non-exclusive non-durable queues by default
so adapt the tests.
1 parent e4ce1b0 commit 5e34120

32 files changed

Lines changed: 215 additions & 139 deletions

src/test/java/com/rabbitmq/client/AbstractJsonRpcTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ public void init() throws Exception {
4141
clientChannel = clientConnection.createChannel();
4242
serverConnection = TestUtils.connectionFactory().newConnection();
4343
serverChannel = serverConnection.createChannel();
44-
serverChannel.queueDeclare(queue, false, false, false, null);
44+
serverChannel.queueDelete(queue);
45+
serverChannel.queueDeclare(queue, true, false, false, null);
4546
server = new JsonRpcServer(serverChannel, queue, RpcService.class, new DefaultRpcservice(), createMapper());
4647
new Thread(() -> {
4748
try {

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,14 @@ protected void declareDurableQueue(String q) throws IOException {
257257
channel.queueDeclare(q, true, false, false, null);
258258
}
259259

260-
protected void declareTransientQueue(String q) throws IOException {
261-
channel.queueDeclare(q, false, false, false, null);
260+
protected void deleteAndDeclareQueue(String q) throws IOException {
261+
channel.queueDelete(q);
262+
channel.queueDeclare(q, true, false, false, null);
262263
}
263264

264-
protected void declareTransientQueue(String q, Map<String, Object> args) throws IOException {
265-
channel.queueDeclare(q, false, false, false, args);
265+
protected void deleteAndDeclareQueue(String q, Map<String, Object> args) throws IOException {
266+
channel.queueDelete(q);
267+
channel.queueDeclare(q, true, false, false, args);
266268
}
267269

268270
protected void declareDurableTopicExchange(String x) throws IOException {

src/test/java/com/rabbitmq/client/test/Bug20004Test.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void bug20004() throws InterruptedException {
5050
() -> {
5151
try {
5252
synchronized (channel) {
53-
channel.queueDeclare("Bug20004Test", false, false, false, null);
53+
channel.queueDelete("Bug20004Test");
54+
channel.queueDeclare("Bug20004Test", true, false, false, null);
5455
testInstance.created = true;
5556
}
5657
} catch (Exception e) {

src/test/java/com/rabbitmq/client/test/CloseInMainLoop.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public void closeWithFaultyConsumer() throws Exception {
110110
SpecialConnection connection = new SpecialConnection();
111111
Channel channel = connection.createChannel();
112112
channel.exchangeDeclare(x, "direct");
113-
channel.queueDeclare(q, false, false, false, null);
113+
channel.queueDelete(q);
114+
channel.queueDeclare(q, true, false, false, null);
114115
channel.queueBind(q, x, "k");
115116

116117
channel.basicConsume(
@@ -128,5 +129,10 @@ public void handleDelivery(
128129

129130
assertTrue(closeLatch.await(1000, TimeUnit.MILLISECONDS));
130131
assertTrue(connection.hadValidShutdown());
132+
133+
Channel cleanupCh = this.connection.createChannel();
134+
cleanupCh.queueDelete(q);
135+
cleanupCh.exchangeDelete(x);
136+
cleanupCh.close();
131137
}
132138
}

src/test/java/com/rabbitmq/client/test/MaxInboundMessageSizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static void safeClose(Connection c) {
4545
@Override
4646
protected void createResources() throws IOException, TimeoutException {
4747
q = generateQueueName();
48-
declareTransientQueue(q);
48+
deleteAndDeclareQueue(q);
4949
super.createResources();
5050
}
5151

src/test/java/com/rabbitmq/client/test/MultiThreadedChannel.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
package com.rabbitmq.client.test;
1717

18+
import java.io.IOException;
1819
import java.util.concurrent.atomic.AtomicReference;
1920

2021
import org.junit.jupiter.api.Test;
@@ -28,15 +29,22 @@ public class MultiThreadedChannel extends BrokerTestCase {
2829

2930
private static final String DUMMY_EXCHANGE_NAME = "dummy.exchange";
3031

32+
@Override
33+
protected void releaseResources() throws IOException {
34+
channel.queueDelete(DUMMY_QUEUE_NAME);
35+
channel.exchangeDelete(DUMMY_EXCHANGE_NAME);
36+
}
37+
3138
@Test public void interleavedRpcs() throws Throwable {
39+
channel.queueDelete(DUMMY_QUEUE_NAME);
3240

3341
final AtomicReference<Throwable> throwableRef = new AtomicReference<Throwable>(null);
3442

3543
Thread queueDeclare = new Thread(new Runnable() {
3644
public void run() {
3745
try {
3846
for (int x = 0; x < 100; x++) {
39-
channel.queueDeclare(DUMMY_QUEUE_NAME, false, false, true, null);
47+
channel.queueDeclare(DUMMY_QUEUE_NAME, true, false, true, null);
4048
}
4149
} catch (Throwable e) {
4250
throwableRef.set(e);

src/test/java/com/rabbitmq/client/test/NoAutoRecoveryWhenTcpWindowIsFullTest.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class NoAutoRecoveryWhenTcpWindowIsFullTest {
7878
private AutorecoveringChannel consumingChannel;
7979

8080
private CountDownLatch consumerOkLatch;
81+
private String testQueue;
8182

8283
@BeforeEach
8384
public void setUp() throws Exception {
@@ -115,16 +116,22 @@ public void configure(Socket socket) throws IOException {
115116
}
116117

117118
@AfterEach
118-
public void tearDown() throws IOException {
119+
public void tearDown() throws Exception {
119120
closeConnectionIfOpen(consumingConnection);
120121
closeConnectionIfOpen(producingConnection);
121-
122+
if (testQueue != null) {
123+
ConnectionFactory cf = TestUtils.connectionFactory();
124+
try (Connection c = cf.newConnection(); Channel ch = c.createChannel()) {
125+
ch.queueDelete(testQueue);
126+
}
127+
}
122128
executorService.shutdownNow();
123129
}
124130

125131
@Test
126132
public void failureAndRecovery() throws IOException, InterruptedException {
127133
final String queue = UUID.randomUUID().toString();
134+
this.testQueue = queue;
128135

129136
final CountDownLatch recoveryLatch = new CountDownLatch(1);
130137

@@ -161,7 +168,8 @@ private void closeConnectionIfOpen(Connection connection) throws IOException {
161168

162169
private void declareQueue(final Channel channel, final String queue) throws IOException {
163170
final Map<String, Object> queueArguments = new HashMap<String, Object>();
164-
channel.queueDeclare(queue, false, false, false, queueArguments);
171+
channel.queueDelete(queue);
172+
channel.queueDeclare(queue, true, false, false, queueArguments);
165173
}
166174

167175
private void produceMessagesInBackground(final Channel channel, final String queue) throws IOException {

src/test/java/com/rabbitmq/client/test/RpcTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ public void init() throws Exception {
5555
clientChannel = clientConnection.createChannel();
5656
serverConnection = TestUtils.connectionFactory().newConnection();
5757
serverChannel = serverConnection.createChannel();
58-
serverChannel.queueDeclare(queue, false, false, false, null);
58+
serverChannel.queueDelete(queue);
59+
serverChannel.queueDeclare(queue, true, false, false, null);
5960
}
6061

6162
@AfterEach

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ public void handleReturn(int replyCode,
7979

8080
@Override protected void createResources() throws IOException {
8181
for (String q : resources) {
82-
channel.queueDeclare(q, false, false, false, null);
82+
channel.queueDelete(q);
83+
channel.queueDeclare(q, true, false, false, null);
8384
}
8485
}
8586

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ protected static String randomString() {
6060

6161
protected void createQueueAndBindToExchange(Binding binding, boolean durable) throws IOException {
6262
channel.exchangeDeclare(binding.x, "direct", durable);
63-
channel.queueDeclare(binding.q, durable, false, false, null);
63+
channel.queueDelete(binding.q);
64+
channel.queueDeclare(binding.q, true, false, false, null);
6465
channel.queueBind(binding.q, binding.x, binding.k);
6566
}
6667

0 commit comments

Comments
 (0)