|
1 | | -// Copyright (c) 2007-2025 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. |
2 | 3 | // |
3 | 4 | // This software, the RabbitMQ Java client library, is triple-licensed under the |
4 | 5 | // Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2 |
|
12 | 13 | // |
13 | 14 | // If you have any questions regarding licensing, please contact us at |
14 | 15 | |
15 | | - |
16 | | - |
17 | 16 | package com.rabbitmq.client.test.functional; |
18 | 17 |
|
19 | 18 | import static org.junit.jupiter.api.Assertions.fail; |
20 | 19 |
|
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 | | - |
27 | 20 | import com.rabbitmq.client.AMQP; |
28 | 21 | import com.rabbitmq.client.Channel; |
29 | 22 | import com.rabbitmq.client.Connection; |
30 | 23 | import com.rabbitmq.client.QueueingConsumer; |
31 | 24 | 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; |
32 | 29 |
|
33 | 30 | // Test queue auto-delete and exclusive semantics. |
34 | 31 | public class QueueExclusivity extends BrokerTestCase { |
35 | 32 |
|
36 | | - final HashMap<String, Object> noArgs = new HashMap<String, Object>(); |
| 33 | + final HashMap<String, Object> noArgs = new HashMap<>(); |
37 | 34 |
|
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; |
41 | 38 |
|
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 | + } |
49 | 45 |
|
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); |
54 | 49 | } |
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; |
64 | 59 | } |
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; |
76 | 72 | } |
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; |
87 | 84 | } |
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; |
97 | 95 | } |
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; |
107 | 106 | } |
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; |
117 | 117 | } |
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; |
135 | 136 | } |
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; |
145 | 147 | } |
146 | | - |
| 148 | + fail("Exclusive queue should be locked for basic get from another connection"); |
| 149 | + } |
147 | 150 | } |
0 commit comments