|
42 | 42 | // Test queue auto-delete and exclusive semantics. |
43 | 43 | public class QueueExclusivity extends BrokerTestCase { |
44 | 44 |
|
45 | | - HashMap<String, Object> noArgs = new HashMap<String, Object>(); |
46 | | - |
47 | | - public Connection altConnection; |
48 | | - public Channel altChannel; |
49 | | - String q = "exclusiveQ"; |
50 | | - |
51 | | - protected void createResources() throws IOException { |
52 | | - altConnection = connectionFactory.newConnection(); |
53 | | - altChannel = altConnection.createChannel(); |
54 | | - altChannel.queueDeclare(q, |
55 | | - // not durable, exclusive, not auto-delete |
56 | | - false, true, false, noArgs); |
57 | | - } |
58 | | - |
59 | | - protected void releaseResources() throws IOException { |
60 | | - if (altConnection != null && altConnection.isOpen()) { |
61 | | - altConnection.close(); |
62 | | - } |
63 | | - } |
64 | | - |
65 | | - public void testQueueExclusiveForPassiveDeclare() throws Exception { |
66 | | - try { |
67 | | - channel.queueDeclarePassive(q); |
68 | | - } catch (IOException ioe) { |
69 | | - return; |
70 | | - } |
71 | | - fail("Passive queue declaration of an exclusive queue from another connection should fail"); |
72 | | - } |
73 | | - |
74 | | - // This is a different scenario because active declare takes notice of |
75 | | - // the all the arguments |
76 | | - public void testQueueExclusiveForDeclare() throws Exception { |
77 | | - try { |
78 | | - channel.queueDeclare(q, false, true, false, noArgs); |
79 | | - } catch (IOException ioe) { |
80 | | - return; |
81 | | - } |
82 | | - fail("Active queue declaration of an exclusive queue from another connection should fail"); |
83 | | - } |
84 | | - |
85 | | - public void testQueueExclusiveForConsume() throws Exception { |
86 | | - QueueingConsumer c = new QueueingConsumer(channel); |
87 | | - try { |
88 | | - channel.basicConsume(q, c); |
89 | | - } catch (IOException ioe) { |
90 | | - return; |
91 | | - } |
92 | | - fail("Exclusive queue should be locked for basic consume from another connection"); |
93 | | - } |
94 | | - |
95 | | - public void testQueueExclusiveForPurge() throws Exception { |
96 | | - try { |
97 | | - channel.queuePurge(q); |
98 | | - } catch (IOException ioe) { |
99 | | - return; |
100 | | - } |
101 | | - fail("Exclusive queue should be locked for queue purge from another connection"); |
102 | | - } |
103 | | - |
104 | | - public void testQueueExclusiveForDelete() throws Exception { |
105 | | - try { |
106 | | - channel.queueDelete(q); |
107 | | - } catch (IOException ioe) { |
108 | | - return; |
109 | | - } |
110 | | - fail("Exclusive queue should be locked for queue delete from another connection"); |
111 | | - } |
112 | | - |
113 | | - public void testQueueExclusiveForBind() throws Exception { |
114 | | - try { |
115 | | - channel.queueBind(q, "", ""); // NB uses default exchange |
116 | | - } catch (IOException ioe) { |
117 | | - return; |
118 | | - } |
119 | | - fail("Exclusive queue should be locked for queue bind from another connection"); |
120 | | - } |
121 | | - |
122 | | - // NB The spec XML doesn't mention queue.unbind, basic.cancel, or |
123 | | - // basic.get in the exclusive rule. It seems the most sensible |
124 | | - // interpretation to include queue.unbind and basic.get in the |
125 | | - // prohibition. |
126 | | - // basic.cancel is inherently local to a channel, so it |
127 | | - // *doesn't* make sense to include it. |
128 | | - |
129 | | - public void testQueueExclusiveForUnbind() throws Exception { |
130 | | - altChannel.queueBind(q, "", ""); // NB uses default exchange |
131 | | - try { |
132 | | - channel.queueUnbind(q, "", ""); |
133 | | - } catch (IOException ioe) { |
134 | | - return; |
135 | | - } |
136 | | - fail("Exclusive queue should be locked for queue unbind from another connection"); |
137 | | - } |
138 | | - |
139 | | - public void testQueueExclusiveForGet() throws Exception { |
140 | | - try { |
141 | | - channel.basicGet(q, true); |
142 | | - } catch (IOException ioe) { |
143 | | - return; |
144 | | - } |
145 | | - fail("Exclusive queue should be locked for basic get from another connection"); |
146 | | - } |
| 45 | + HashMap<String, Object> noArgs = new HashMap<String, Object>(); |
| 46 | + |
| 47 | + public Connection altConnection; |
| 48 | + public Channel altChannel; |
| 49 | + String q = "exclusiveQ"; |
| 50 | + |
| 51 | + protected void createResources() throws IOException { |
| 52 | + altConnection = connectionFactory.newConnection(); |
| 53 | + altChannel = altConnection.createChannel(); |
| 54 | + altChannel.queueDeclare(q, |
| 55 | + // not durable, exclusive, not auto-delete |
| 56 | + false, true, false, noArgs); |
| 57 | + } |
| 58 | + |
| 59 | + protected void releaseResources() throws IOException { |
| 60 | + if (altConnection != null && altConnection.isOpen()) { |
| 61 | + altConnection.close(); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + public void testQueueExclusiveForPassiveDeclare() throws Exception { |
| 66 | + try { |
| 67 | + channel.queueDeclarePassive(q); |
| 68 | + } catch (IOException ioe) { |
| 69 | + return; |
| 70 | + } |
| 71 | + fail("Passive queue declaration of an exclusive queue from another connection should fail"); |
| 72 | + } |
| 73 | + |
| 74 | + // This is a different scenario because active declare takes notice of |
| 75 | + // the all the arguments |
| 76 | + public void testQueueExclusiveForDeclare() throws Exception { |
| 77 | + try { |
| 78 | + channel.queueDeclare(q, false, true, false, noArgs); |
| 79 | + } catch (IOException ioe) { |
| 80 | + return; |
| 81 | + } |
| 82 | + fail("Active queue declaration of an exclusive queue from another connection should fail"); |
| 83 | + } |
| 84 | + |
| 85 | + public void testQueueExclusiveForConsume() throws Exception { |
| 86 | + QueueingConsumer c = new QueueingConsumer(channel); |
| 87 | + try { |
| 88 | + channel.basicConsume(q, c); |
| 89 | + } catch (IOException ioe) { |
| 90 | + return; |
| 91 | + } |
| 92 | + fail("Exclusive queue should be locked for basic consume from another connection"); |
| 93 | + } |
| 94 | + |
| 95 | + public void testQueueExclusiveForPurge() throws Exception { |
| 96 | + try { |
| 97 | + channel.queuePurge(q); |
| 98 | + } catch (IOException ioe) { |
| 99 | + return; |
| 100 | + } |
| 101 | + fail("Exclusive queue should be locked for queue purge from another connection"); |
| 102 | + } |
| 103 | + |
| 104 | + public void testQueueExclusiveForDelete() throws Exception { |
| 105 | + try { |
| 106 | + channel.queueDelete(q); |
| 107 | + } catch (IOException ioe) { |
| 108 | + return; |
| 109 | + } |
| 110 | + fail("Exclusive queue should be locked for queue delete from another connection"); |
| 111 | + } |
| 112 | + |
| 113 | + public void testQueueExclusiveForBind() throws Exception { |
| 114 | + try { |
| 115 | + channel.queueBind(q, "", ""); // NB uses default exchange |
| 116 | + } catch (IOException ioe) { |
| 117 | + return; |
| 118 | + } |
| 119 | + fail("Exclusive queue should be locked for queue bind from another connection"); |
| 120 | + } |
| 121 | + |
| 122 | + // NB The spec XML doesn't mention queue.unbind, basic.cancel, or |
| 123 | + // basic.get in the exclusive rule. It seems the most sensible |
| 124 | + // interpretation to include queue.unbind and basic.get in the |
| 125 | + // prohibition. |
| 126 | + // basic.cancel is inherently local to a channel, so it |
| 127 | + // *doesn't* make sense to include it. |
| 128 | + |
| 129 | + public void testQueueExclusiveForUnbind() throws Exception { |
| 130 | + altChannel.queueBind(q, "", ""); // NB uses default exchange |
| 131 | + try { |
| 132 | + channel.queueUnbind(q, "", ""); |
| 133 | + } catch (IOException ioe) { |
| 134 | + return; |
| 135 | + } |
| 136 | + fail("Exclusive queue should be locked for queue unbind from another connection"); |
| 137 | + } |
| 138 | + |
| 139 | + public void testQueueExclusiveForGet() throws Exception { |
| 140 | + try { |
| 141 | + channel.basicGet(q, true); |
| 142 | + } catch (IOException ioe) { |
| 143 | + return; |
| 144 | + } |
| 145 | + fail("Exclusive queue should be locked for basic get from another connection"); |
| 146 | + } |
147 | 147 |
|
148 | 148 | } |
0 commit comments