1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
#
# Copyright (c) 2006 The Apache Software Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""
Tests for exchange behaviour.
Test classes ending in 'RuleTests' are derived from rules in amqp.xml.
"""
import logging, Queue
from qpid.testlib import TestBase
from qpid.content import Content
# TODO aconway 2006-09-01: Investigate and add tests as appropriate.
# Observered on C++:
#
# No exception raised for basic_consume on non-existent queue name.
# No exception for basic_publish with bad routing key.
# No exception for binding to non-existent exchange?
# queue_bind hangs with invalid exchange name
#
# Do server exceptions get propagated properly?
# Do Java exceptions propagate with any data (or just Closed())
class StandardExchangeVerifier:
"""Verifies standard exchange behavior.
Used as base class for classes that test standard exchanges."""
def verifyDirectExchange(self, ex):
"""Verify that ex behaves like a direct exchange."""
self.queue_declare(queue="q")
self.channel.queue_bind(queue="q", exchange=ex, routing_key="k")
self.assertPublishConsume(exchange=ex, queue="q", routing_key="k")
try:
self.assertPublishConsume(exchange=ex, queue="q", routing_key="kk")
self.fail("Expected Empty exception")
except Queue.Empty: None # Expected
def verifyFanOutExchange(self, ex):
"""Verify that ex behaves like a fanout exchange."""
self.queue_declare(queue="q")
self.channel.queue_bind(queue="q", exchange=ex)
self.queue_declare(queue="p")
self.channel.queue_bind(queue="p", exchange=ex)
for qname in ["q", "p"]: self.assertPublishGet(self.consume(qname), ex)
def verifyTopicExchange(self, ex):
"""Verify that ex behaves like a topic exchange"""
self.queue_declare(queue="a")
self.channel.queue_bind(queue="a", exchange=ex, routing_key="a.#.b.*")
q = self.consume("a")
self.assertPublishGet(q, ex, "a.b.x")
self.assertPublishGet(q, ex, "a.x.b.x")
self.assertPublishGet(q, ex, "a.x.x.b.x")
# Shouldn't match
self.channel.basic_publish(exchange=ex, routing_key="a.b")
self.channel.basic_publish(exchange=ex, routing_key="a.b.x.y")
self.channel.basic_publish(exchange=ex, routing_key="x.a.b.x")
self.channel.basic_publish(exchange=ex, routing_key="a.b")
self.assert_(q.empty())
class RecommendedTypesRuleTests(TestBase, StandardExchangeVerifier):
"""
The server SHOULD implement these standard exchange types: topic, headers.
Client attempts to declare an exchange with each of these standard types.
"""
def testDirect(self):
"""Declare and test a direct exchange"""
self.exchange_declare(0, exchange="d", type="direct")
self.verifyDirectExchange("d")
def testFanout(self):
"""Declare and test a fanout exchange"""
self.exchange_declare(0, exchange="f", type="fanout")
self.verifyFanOutExchange("f")
def testTopic(self):
"""Declare and test a topic exchange"""
self.exchange_declare(0, exchange="t", type="topic")
self.verifyTopicExchange("t")
class RequiredInstancesRuleTests(TestBase, StandardExchangeVerifier):
"""
The server MUST, in each virtual host, pre-declare an exchange instance
for each standard exchange type that it implements, where the name of the
exchange instance is amq. followed by the exchange type name.
Client creates a temporary queue and attempts to bind to each required
exchange instance (amq.fanout, amq.direct, and amq.topic, amq.headers if
those types are defined).
"""
def testAmqDirect(self): self.verifyDirectExchange("amq.direct")
def testAmqFanOut(self): self.verifyFanOutExchange("amq.fanout")
def testAmqTopic(self): self.verifyTopicExchange("amq.topic")
def testAmqHeaders(self):
self.exchange_declare(0, exchange="amq.headers", passive="true")
# TODO aconway 2006-09-14: verify headers behavior
class DefaultExchangeRuleTests(TestBase, StandardExchangeVerifier):
"""
The server MUST predeclare a direct exchange to act as the default exchange
for content Publish methods and for default queue bindings.
Client checks that the default exchange is active by specifying a queue
binding with no exchange name, and publishing a message with a suitable
routing key but without specifying the exchange name, then ensuring that
the message arrives in the queue correctly.
"""
def testDefaultExchange(self):
# Test automatic binding by queue name.
self.queue_declare(queue="d")
self.assertPublishConsume(queue="d", routing_key="d")
# Test explicit bind to default queue
self.verifyDirectExchange("")
class DefaultAccessRuleTests(TestBase):
"""
The server MUST NOT allow clients to access the default exchange except
by specifying an empty exchange name in the Queue.Bind and content Publish
methods.
"""
# TODO aconway 2006-09-18: fill this in.
class ExtensionsRuleTests(TestBase):
"""
The server MAY implement other exchange types as wanted.
"""
class DeclareMethodMinimumRuleTests(TestBase):
"""
The server SHOULD support a minimum of 16 exchanges per virtual host and
ideally, impose no limit except as defined by available resources.
The client creates as many exchanges as it can until the server reports
an error; the number of exchanges successfuly created must be at least
sixteen.
"""
class DeclareMethodTicketFieldValidityRuleTests(TestBase):
"""
The client MUST provide a valid access ticket giving "active" access to
the realm in which the exchange exists or will be created, or "passive"
access if the if-exists flag is set.
Client creates access ticket with wrong access rights and attempts to use
in this method.
"""
class DeclareMethodExchangeFieldReservedRuleTests(TestBase):
"""
Exchange names starting with "amq." are reserved for predeclared and
standardised exchanges. The client MUST NOT attempt to create an exchange
starting with "amq.".
"""
class DeclareMethodTypeFieldTypedRuleTests(TestBase):
"""
Exchanges cannot be redeclared with different types. The client MUST not
attempt to redeclare an existing exchange with a different type than used
in the original Exchange.Declare method.
"""
class DeclareMethodTypeFieldSupportRuleTests(TestBase):
"""
The client MUST NOT attempt to create an exchange with a type that the
server does not support.
"""
class DeclareMethodPassiveFieldNotFoundRuleTests(TestBase):
"""
If set, and the exchange does not already exist, the server MUST raise a
channel exception with reply code 404 (not found).
"""
class DeclareMethodDurableFieldSupportRuleTests(TestBase):
"""
The server MUST support both durable and transient exchanges.
"""
class DeclareMethodDurableFieldStickyRuleTests(TestBase):
"""
The server MUST ignore the durable field if the exchange already exists.
"""
class DeclareMethodAutoDeleteFieldStickyRuleTests(TestBase):
"""
The server MUST ignore the auto-delete field if the exchange already
exists.
"""
class DeleteMethodTicketFieldValidityRuleTests(TestBase):
"""
The client MUST provide a valid access ticket giving "active" access
rights to the exchange's access realm.
Client creates access ticket with wrong access rights and attempts to use
in this method.
"""
class DeleteMethodExchangeFieldExistsRuleTests(TestBase):
"""
The client MUST NOT attempt to delete an exchange that does not exist.
"""
|