Skip to content

Commit 04264b6

Browse files
committed
Use different queue name for each test
For exclusive queue test, otherwise there can be conflicts between tests, as the queue record is not completely gone. (cherry picked from commit ed73350) Conflicts: src/test/java/com/rabbitmq/client/test/functional/QueueExclusivity.java
1 parent 99f1255 commit 04264b6

File tree

2 files changed

+112
-108
lines changed

2 files changed

+112
-108
lines changed

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@
788788
<include>src/main/java/com/rabbitmq/client/impl/Environment.java</include>
789789
<include>src/main/java/com/rabbitmq/client/observation/**/*.java</include>
790790
<include>src/test/java/com/rabbitmq/client/test/functional/MicrometerObservationCollectorMetrics.java</include>
791+
<include>src/test/java/com/rabbitmq/client/test/functional/QueueExclusivity.java</include>
791792
<include>src/test/java/com/rabbitmq/client/test/NettyTest.java</include>
792793
<include>src/test/java/com/rabbitmq/client/test/ProtocolVersionMismatch.java</include>
793794
<include>src/test/java/com/rabbitmq/client/test/TestUtils.java</include>
Lines changed: 111 additions & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2007-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
1+
// Copyright (c) 2007-2025 Broadcom. All Rights Reserved.
2+
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
23
//
34
// This software, the RabbitMQ Java client library, is triple-licensed under the
45
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -12,136 +13,138 @@
1213
//
1314
// If you have any questions regarding licensing, please contact us at
1415
15-
16-
1716
package com.rabbitmq.client.test.functional;
1817

1918
import static org.junit.jupiter.api.Assertions.fail;
2019

21-
import java.io.IOException;
22-
import java.util.HashMap;
23-
import java.util.concurrent.TimeoutException;
24-
25-
import org.junit.jupiter.api.Test;
26-
2720
import com.rabbitmq.client.AMQP;
2821
import com.rabbitmq.client.Channel;
2922
import com.rabbitmq.client.Connection;
3023
import com.rabbitmq.client.QueueingConsumer;
3124
import com.rabbitmq.client.test.BrokerTestCase;
25+
import java.io.IOException;
26+
import java.util.HashMap;
27+
import java.util.concurrent.TimeoutException;
28+
import org.junit.jupiter.api.Test;
3229

3330
// Test queue auto-delete and exclusive semantics.
3431
public class QueueExclusivity extends BrokerTestCase {
3532

36-
final HashMap<String, Object> noArgs = new HashMap<String, Object>();
33+
final HashMap<String, Object> noArgs = new HashMap<>();
3734

38-
public Connection altConnection;
39-
public Channel altChannel;
40-
final String q = "exclusiveQ";
35+
public Connection altConnection;
36+
public Channel altChannel;
37+
private String q;
4138

42-
protected void createResources() throws IOException, TimeoutException {
43-
altConnection = connectionFactory.newConnection();
44-
altChannel = altConnection.createChannel();
45-
altChannel.queueDeclare(q,
46-
// not durable, exclusive, not auto-delete
47-
false, true, false, noArgs);
48-
}
39+
protected void createResources() throws IOException, TimeoutException {
40+
q = generateQueueName();
41+
altConnection = connectionFactory.newConnection();
42+
altChannel = altConnection.createChannel();
43+
altChannel.queueDeclare(q, false, true, false, noArgs);
44+
}
4945

50-
protected void releaseResources() throws IOException {
51-
if (altConnection != null && altConnection.isOpen()) {
52-
altConnection.close(10_000);
53-
}
46+
protected void releaseResources() throws IOException {
47+
if (altConnection != null && altConnection.isOpen()) {
48+
altConnection.close(10_000);
5449
}
55-
56-
@Test public void queueExclusiveForPassiveDeclare() throws Exception {
57-
try {
58-
channel.queueDeclarePassive(q);
59-
} catch (IOException ioe) {
60-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
61-
return;
62-
}
63-
fail("Passive queue declaration of an exclusive queue from another connection should fail");
50+
}
51+
52+
@Test
53+
public void queueExclusiveForPassiveDeclare() {
54+
try {
55+
channel.queueDeclarePassive(q);
56+
} catch (IOException ioe) {
57+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
58+
return;
6459
}
65-
66-
// This is a different scenario because active declare takes notice of
67-
// the all the arguments
68-
@Test public void queueExclusiveForDeclare() throws Exception {
69-
try {
70-
channel.queueDeclare(q, false, true, false, noArgs);
71-
} catch (IOException ioe) {
72-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
73-
return;
74-
}
75-
fail("Active queue declaration of an exclusive queue from another connection should fail");
60+
fail("Passive queue declaration of an exclusive queue from another connection should fail");
61+
}
62+
63+
// This is a different scenario because active declare takes notice of
64+
// the all the arguments
65+
@Test
66+
public void queueExclusiveForDeclare() {
67+
try {
68+
channel.queueDeclare(q, false, true, false, noArgs);
69+
} catch (IOException ioe) {
70+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
71+
return;
7672
}
77-
78-
@Test public void queueExclusiveForConsume() throws Exception {
79-
QueueingConsumer c = new QueueingConsumer(channel);
80-
try {
81-
channel.basicConsume(q, c);
82-
} catch (IOException ioe) {
83-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
84-
return;
85-
}
86-
fail("Exclusive queue should be locked for basic consume from another connection");
73+
fail("Active queue declaration of an exclusive queue from another connection should fail");
74+
}
75+
76+
@Test
77+
public void queueExclusiveForConsume() {
78+
QueueingConsumer c = new QueueingConsumer(channel);
79+
try {
80+
channel.basicConsume(q, c);
81+
} catch (IOException ioe) {
82+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
83+
return;
8784
}
88-
89-
@Test public void queueExclusiveForPurge() throws Exception {
90-
try {
91-
channel.queuePurge(q);
92-
} catch (IOException ioe) {
93-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
94-
return;
95-
}
96-
fail("Exclusive queue should be locked for queue purge from another connection");
85+
fail("Exclusive queue should be locked for basic consume from another connection");
86+
}
87+
88+
@Test
89+
public void queueExclusiveForPurge() {
90+
try {
91+
channel.queuePurge(q);
92+
} catch (IOException ioe) {
93+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
94+
return;
9795
}
98-
99-
@Test public void queueExclusiveForDelete() throws Exception {
100-
try {
101-
channel.queueDelete(q);
102-
} catch (IOException ioe) {
103-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
104-
return;
105-
}
106-
fail("Exclusive queue should be locked for queue delete from another connection");
96+
fail("Exclusive queue should be locked for queue purge from another connection");
97+
}
98+
99+
@Test
100+
public void queueExclusiveForDelete() {
101+
try {
102+
channel.queueDelete(q);
103+
} catch (IOException ioe) {
104+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
105+
return;
107106
}
108-
109-
@Test public void queueExclusiveForBind() throws Exception {
110-
try {
111-
channel.queueBind(q, "amq.direct", "");
112-
} catch (IOException ioe) {
113-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
114-
return;
115-
}
116-
fail("Exclusive queue should be locked for queue bind from another connection");
107+
fail("Exclusive queue should be locked for queue delete from another connection");
108+
}
109+
110+
@Test
111+
public void queueExclusiveForBind() {
112+
try {
113+
channel.queueBind(q, "amq.direct", "");
114+
} catch (IOException ioe) {
115+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
116+
return;
117117
}
118-
119-
// NB The spec XML doesn't mention queue.unbind, basic.cancel, or
120-
// basic.get in the exclusive rule. It seems the most sensible
121-
// interpretation to include queue.unbind and basic.get in the
122-
// prohibition.
123-
// basic.cancel is inherently local to a channel, so it
124-
// *doesn't* make sense to include it.
125-
126-
@Test public void queueExclusiveForUnbind() throws Exception {
127-
altChannel.queueBind(q, "amq.direct", "");
128-
try {
129-
channel.queueUnbind(q, "amq.direct", "");
130-
} catch (IOException ioe) {
131-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
132-
return;
133-
}
134-
fail("Exclusive queue should be locked for queue unbind from another connection");
118+
fail("Exclusive queue should be locked for queue bind from another connection");
119+
}
120+
121+
// NB The spec XML doesn't mention queue.unbind, basic.cancel, or
122+
// basic.get in the exclusive rule. It seems the most sensible
123+
// interpretation to include queue.unbind and basic.get in the
124+
// prohibition.
125+
// basic.cancel is inherently local to a channel, so it
126+
// *doesn't* make sense to include it.
127+
128+
@Test
129+
public void queueExclusiveForUnbind() throws Exception {
130+
altChannel.queueBind(q, "amq.direct", "");
131+
try {
132+
channel.queueUnbind(q, "amq.direct", "");
133+
} catch (IOException ioe) {
134+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
135+
return;
135136
}
136-
137-
@Test public void queueExclusiveForGet() throws Exception {
138-
try {
139-
channel.basicGet(q, true);
140-
} catch (IOException ioe) {
141-
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
142-
return;
143-
}
144-
fail("Exclusive queue should be locked for basic get from another connection");
137+
fail("Exclusive queue should be locked for queue unbind from another connection");
138+
}
139+
140+
@Test
141+
public void queueExclusiveForGet() {
142+
try {
143+
channel.basicGet(q, true);
144+
} catch (IOException ioe) {
145+
checkShutdownSignal(AMQP.RESOURCE_LOCKED, ioe);
146+
return;
145147
}
146-
148+
fail("Exclusive queue should be locked for basic get from another connection");
149+
}
147150
}

0 commit comments

Comments
 (0)