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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
|
#!/usr/bin/env python
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
import os, signal, sys, unittest
from testlib import TestBaseCluster
class ClusterTests(TestBaseCluster):
"""Basic cluster with async store tests"""
def test_Cluster_01_Initialization(self):
"""Start a single cluster containing several nodes, and stop it again"""
try:
clusterName = "cluster-01"
self.createCheckCluster(clusterName, 5)
self.checkNumBrokers(5)
self.stopCheckCluster(clusterName)
except:
self.killAllClusters()
raise
def test_Cluster_02_MultipleClusterInitialization(self):
"""Start several clusters each with several nodes and stop them again"""
try:
for i in range(0, 5):
clusterName = "cluster-02.%d" % i
self.createCluster(clusterName, 5)
self.checkNumBrokers(25)
self.killCluster("cluster-02.2")
self.checkNumBrokers(20)
self.stopCheckAll()
except:
self.killAllClusters()
raise
def test_Cluster_03_AddRemoveNodes(self):
"""Create a multi-node cluster, then kill some nodes and add some new ones (not those killed)"""
try:
clusterName = "cluster-03"
self.createCheckCluster(clusterName, 3)
for i in range(4,9):
self.createClusterNode(i, clusterName)
self.checkNumClusterBrokers(clusterName, 8)
self.killNode(2, clusterName)
self.killNode(5, clusterName)
self.killNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 5)
self.createClusterNode(9, clusterName)
self.createClusterNode(10, clusterName)
self.checkNumClusterBrokers(clusterName, 7)
self.stopCheckAll()
except:
self.killAllClusters()
raise
def test_Cluster_04_RemoveRestoreNodes(self):
"""Create a multi-node cluster, then kill some of the nodes and restart them"""
try:
clusterName = "cluster-04"
self.createCheckCluster(clusterName, 6)
self.checkNumBrokers(6)
self.killNode(1, clusterName)
self.killNode(3, clusterName)
self.killNode(4, clusterName)
self.checkNumBrokers(3)
self.createClusterNode(1, clusterName)
self.createClusterNode(3, clusterName)
self.createClusterNode(4, clusterName)
self.checkNumClusterBrokers(clusterName, 6)
self.killNode(2, clusterName)
self.killNode(3, clusterName)
self.killNode(4, clusterName)
self.checkNumBrokers(3)
self.createClusterNode(2, clusterName)
self.createClusterNode(3, clusterName)
self.createClusterNode(4, clusterName)
self.checkNumClusterBrokers(clusterName, 6)
self.stopCheckAll()
except:
self.killAllClusters()
raise
def test_Cluster_05_KillAllNodesThenRecover(self):
"""Create a multi-node cluster, then kill *all* nodes, then restart the cluster"""
try:
clusterName = "cluster-05"
self.createCheckCluster(clusterName, 6)
self.killClusterCheck(clusterName)
self.createCheckCluster(clusterName, 6)
self.stopCheckAll()
except:
self.killAllClusters()
raise
def test_Cluster_06_PublishConsume(self):
"""Publish then consume 100 messages from a single cluster"""
try:
clusterName = "cluster-06"
self.createCheckCluster(clusterName, 3)
self.sendReceiveMsgs(0, clusterName, "test-exchange-06", "test-queue-06", 100)
self.stopCheckAll()
except:
self.killAllClusters()
raise
def test_Cluster_07_MultiplePublishConsume(self):
"""Staggered publish and consume on a single cluster"""
try:
clusterName = "cluster-07"
exchangeName = "test-exchange-07"
queueName = "test-queue-07"
self.createCheckCluster(clusterName, 3)
self.createBindDirectExchangeQueue(0, clusterName, exchangeName, queueName)
txMsgs = self.sendMsgs(0, clusterName, exchangeName, queueName, 20) # 20, 0
rxMsgs = self.receiveMsgs(1, clusterName, queueName, 10) # 10, 10
txMsgs += self.sendMsgs(2, clusterName, exchangeName, queueName, 20) # 30, 10
rxMsgs += self.receiveMsgs(0, clusterName, queueName, 20) # 10, 30
txMsgs += self.sendMsgs(1, clusterName, exchangeName, queueName, 20) # 30, 30
rxMsgs += self.receiveMsgs(2, clusterName, queueName, 20) # 10, 50
txMsgs += self.sendMsgs(0, clusterName, exchangeName, queueName, 20) # 30, 50
rxMsgs += self.receiveMsgs(1, clusterName, queueName, 30) # 0, 80
self.stopCheckAll()
if txMsgs != rxMsgs:
print "txMsgs=%s" % txMsgs
print "rxMsgs=%s" % rxMsgs
self.fail("Send - receive message mismatch")
except:
self.killAllClusters()
raise
def test_Cluster_08_MsgPublishConsumeAddRemoveNodes(self):
"""Staggered publish and consume interleaved with adding and removing nodes on a single cluster"""
try:
clusterName = "cluster-08"
exchangeName = "test-exchange-08"
queueName = "test-queue-08"
self.createCheckCluster(clusterName, 3)
self.createBindDirectExchangeQueue(0, clusterName, exchangeName, queueName)
txMsgs = self.sendMsgs(0, clusterName, exchangeName, queueName, 20) # 20, 0
for i in range(3,6):
self.createClusterNode(i, clusterName)
self.checkNumClusterBrokers(clusterName, 6)
txMsgs += self.sendMsgs(1, clusterName, exchangeName, queueName, 20) # 40, 0
self.killNode(0, clusterName)
self.checkNumClusterBrokers(clusterName, 5)
rxMsgs = self.receiveMsgs(2, clusterName, queueName, 10) # 30, 10
self.killNode(2, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
rxMsgs += self.receiveMsgs(3, clusterName, queueName, 20) # 10, 30
self.createClusterNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 5)
txMsgs += self.sendMsgs(4, clusterName, exchangeName, queueName, 20) # 30, 30
rxMsgs += self.receiveMsgs(5, clusterName, queueName, 20) # 10, 50
self.createClusterNode(7, clusterName)
self.checkNumClusterBrokers(clusterName, 6)
txMsgs += self.sendMsgs(6, clusterName, exchangeName, queueName, 20) # 30, 50
rxMsgs += self.receiveMsgs(1, clusterName, queueName, 30) # 0, 80
self.stopCheckAll()
if txMsgs != rxMsgs:
print "txMsgs=%s" % txMsgs
print "rxMsgs=%s" % rxMsgs
self.fail("Send - receive message mismatch")
except:
self.killAllClusters()
raise
def test_Cluster_09_MsgPublishConsumeRemoveRestoreNodes(self):
"""Publish and consume messages interleaved with adding and restoring previous nodes on a single cluster"""
try:
clusterName = "cluster-09"
exchangeName = "test-exchange-09"
queueName = "test-queue-09"
self.createCheckCluster(clusterName, 6)
self.createBindDirectExchangeQueue(0, clusterName, exchangeName, queueName)
txMsgs = self.sendMsgs(0, clusterName, exchangeName, queueName, 20) # 20, 0
self.killNode(2, clusterName)
self.checkNumClusterBrokers(clusterName, 5)
txMsgs += self.sendMsgs(1, clusterName, exchangeName, queueName, 20) # 40, 0
self.killNode(0, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
rxMsgs = self.receiveMsgs(3, clusterName, queueName, 10) # 30, 10
self.killNode(4, clusterName)
self.checkNumClusterBrokers(clusterName, 3)
rxMsgs += self.receiveMsgs(5, clusterName, queueName, 20) # 10, 30
self.createClusterNode(2, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
txMsgs += self.sendMsgs(1, clusterName, exchangeName, queueName, 20) # 30, 30
self.createClusterNode(0, clusterName)
self.checkNumClusterBrokers(clusterName, 5)
rxMsgs += self.receiveMsgs(2, clusterName, queueName, 20) # 10, 50
self.createClusterNode(4, clusterName)
self.checkNumClusterBrokers(clusterName, 6)
txMsgs += self.sendMsgs(0, clusterName, exchangeName, queueName, 20) # 30, 50
rxMsgs += self.receiveMsgs(4, clusterName, queueName, 30) # 0, 80
self.stopCheckAll()
if txMsgs != rxMsgs:
print "txMsgs=%s" % txMsgs
print "rxMsgs=%s" % rxMsgs
self.fail("Send - receive message mismatch")
except:
self.killAllClusters()
raise
def test_Cluster_10_LinearNodeKillCreateProgression(self):
"""Publish and consume messages while linearly killing all original nodes and replacing them with new ones"""
try:
clusterName = "cluster-10"
exchangeName = "test-exchange-10"
queueName = "test-queue-10"
self.createCheckCluster(clusterName, 4)
self.createBindDirectExchangeQueue(2, clusterName, exchangeName, queueName)
txMsgs = self.sendMsgs(2, clusterName, exchangeName, queueName, 20)
rxMsgs = self.receiveMsgs(3, clusterName, queueName, 10)
for i in range(0, 16):
self.killNode(i, clusterName)
self.createClusterNode(i+4, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
txMsgs += self.sendMsgs(i+1, clusterName, exchangeName, queueName, 20)
rxMsgs += self.receiveMsgs(i+2, clusterName, queueName, 20)
rxMsgs += self.receiveMsgs(16, clusterName, queueName, 10)
self.stopCheckAll()
if txMsgs != rxMsgs:
print "txMsgs=%s" % txMsgs
print "rxMsgs=%s" % rxMsgs
self.fail("Send - receive message mismatch")
except:
self.killAllClusters()
raise
def test_Cluster_11_CircularNodeKillRestoreProgression(self):
"""Publish and consume messages while circularly killing all original nodes and restoring them again"""
try:
clusterName = "cluster-11"
exchangeName = "test-exchange-11"
queueName = "test-queue-11"
self.createCheckCluster(clusterName, 4)
self.createBindDirectExchangeQueue(2, clusterName, exchangeName, queueName)
txMsgs = self.sendMsgs(3, clusterName, exchangeName, queueName, 20)
rxMsgs = self.receiveMsgs(0, clusterName, queueName, 10)
self.killNode(0, clusterName)
self.killNode(1, clusterName)
for i in range(0, 16):
self.killNode((i + 2) % 4, clusterName)
self.createClusterNode(i % 4, clusterName)
self.checkNumClusterBrokers(clusterName, 2)
txMsgs += self.sendMsgs((i + 3) % 4, clusterName, exchangeName, queueName, 20)
rxMsgs += self.receiveMsgs((i + 4) % 4, clusterName, queueName, 20)
rxMsgs += self.receiveMsgs(3, clusterName, queueName, 10)
self.stopCheckAll()
if txMsgs != rxMsgs:
print "txMsgs=%s" % txMsgs
print "rxMsgs=%s" % rxMsgs
self.fail("Send - receive message mismatch")
except:
self.killAllClusters()
raise
def test_Cluster_12_TopicExchange(self):
"""Create topic exchange in a cluster and make sure it replicates correctly"""
try:
clusterName = "cluster-12"
self.createCheckCluster(clusterName, 4)
topicExchangeName = "test-exchange-12"
topicQueueNameKeyList = {"test-queue-12-A" : "#.A", "test-queue-12-B" : "#.B", "test-queue-12-C" : "C.#", "test-queue-12-D" : "D.#"}
self.createBindTopicExchangeQueues(2, clusterName, topicExchangeName, topicQueueNameKeyList)
# Place initial messages
txMsgsA = txMsgsC = self.sendMsgs(3, clusterName, topicExchangeName, "C.hello.A", 10) # (10, 0, 10, 0)
self.sendMsgs(2, clusterName, topicExchangeName, "hello", 10) # Should not go to any queue
txMsgsD = self.sendMsgs(1, clusterName, topicExchangeName, "D.hello.A", 10) # (20, 0, 10, 10)
txMsgsA += txMsgsD
txMsgsB = self.sendMsgs(0, clusterName, topicExchangeName, "hello.B", 20) # (20, 20, 10, 10)
# Kill and add some nodes
self.killNode(0, clusterName)
self.killNode(2, clusterName)
self.createClusterNode(4, clusterName)
self.createClusterNode(5, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
# Pull 10 messages from each queue
rxMsgsA = self.receiveMsgs(1, clusterName, "test-queue-12-A", 10) # (10, 20, 10, 10)
rxMsgsB = self.receiveMsgs(3, clusterName, "test-queue-12-B", 10) # (10, 10, 10, 10)
rxMsgsC = self.receiveMsgs(4, clusterName, "test-queue-12-C", 10) # (10, 10, 0, 10)
rxMsgsD = self.receiveMsgs(5, clusterName, "test-queue-12-D", 10) # (10, 10, 0, 0)
# Kill and add another node
self.killNode(4, clusterName)
self.createClusterNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
# Add two more queues
self.createBindTopicExchangeQueues(6, clusterName, topicExchangeName, {"test-queue-12-E" : "#.bye.A", "test-queue-12-F" : "#.bye.B"})
# Place more messages
txMsgs = self.sendMsgs(3, clusterName, topicExchangeName, "C.bye.A", 10) # (20, 10, 10, 0, 10, 0)
txMsgsA += txMsgs
txMsgsC += txMsgs
txMsgsE = txMsgs
self.sendMsgs(1, clusterName, topicExchangeName, "bye", 20) # Should not go to any queue
txMsgs = self.sendMsgs(5, clusterName, topicExchangeName, "D.bye.B", 20) # (20, 30, 10, 20, 10, 20)
txMsgsB += txMsgs
txMsgsD += txMsgs
txMsgsF = txMsgs
# Kill all nodes but one
self.killNode(1, clusterName)
self.killNode(3, clusterName)
self.killNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 1)
# Pull all remaining messages from each queue
rxMsgsA += self.receiveMsgs(5, clusterName, "test-queue-12-A", 20)
rxMsgsB += self.receiveMsgs(5, clusterName, "test-queue-12-B", 30)
rxMsgsC += self.receiveMsgs(5, clusterName, "test-queue-12-C", 10)
rxMsgsD += self.receiveMsgs(5, clusterName, "test-queue-12-D", 20)
rxMsgsE = self.receiveMsgs(5, clusterName, "test-queue-12-E", 10)
rxMsgsF = self.receiveMsgs(5, clusterName, "test-queue-12-F", 20)
# Check messages
self.stopCheckAll()
if txMsgsA != rxMsgsA:
self.fail("Send - receive message mismatch for queue A")
if txMsgsB != rxMsgsB:
self.fail("Send - receive message mismatch for queue B")
if txMsgsC != rxMsgsC:
self.fail("Send - receive message mismatch for queue C")
if txMsgsD != rxMsgsD:
self.fail("Send - receive message mismatch for queue D")
if txMsgsE != rxMsgsE:
self.fail("Send - receive message mismatch for queue E")
if txMsgsF != rxMsgsF:
self.fail("Send - receive message mismatch for queue F")
except:
self.killAllClusters()
raise
def test_Cluster_13_FanoutExchange(self):
"""Create fanout exchange in a cluster and make sure it replicates correctly"""
try:
clusterName = "cluster-13"
self.createCheckCluster(clusterName, 4)
fanoutExchangeName = "test-exchange-13"
fanoutQueueNameList = ["test-queue-13-A", "test-queue-13-B", "test-queue-13-C"]
self.createBindFanoutExchangeQueues(2, clusterName, fanoutExchangeName, fanoutQueueNameList)
# Place initial 20 messages, retrieve 10
txMsg = self.sendMsgs(3, clusterName, fanoutExchangeName, None, 20)
rxMsgA = self.receiveMsgs(1, clusterName, "test-queue-13-A", 10)
rxMsgB = self.receiveMsgs(3, clusterName, "test-queue-13-B", 10)
rxMsgC = self.receiveMsgs(0, clusterName, "test-queue-13-C", 10)
# Kill and add some nodes
self.killNode(0, clusterName)
self.killNode(2, clusterName)
self.createClusterNode(4, clusterName)
self.createClusterNode(5, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
# Place another 20 messages, retrieve 20
txMsg += self.sendMsgs(3, clusterName, fanoutExchangeName, None, 20)
rxMsgA += self.receiveMsgs(1, clusterName, "test-queue-13-A", 20)
rxMsgB += self.receiveMsgs(3, clusterName, "test-queue-13-B", 20)
rxMsgC += self.receiveMsgs(4, clusterName, "test-queue-13-C", 20)
# Kill and add another node
self.killNode(4, clusterName)
self.createClusterNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 4)
# Add another 2 queues
self.createBindFanoutExchangeQueues(6, clusterName, fanoutExchangeName, ["test-queue-13-D", "test-queue-13-E"])
# Place another 20 messages, retrieve 20
tmp = self.sendMsgs(3, clusterName, fanoutExchangeName, None, 20)
txMsg += tmp
rxMsgA += self.receiveMsgs(1, clusterName, "test-queue-13-A", 20)
rxMsgB += self.receiveMsgs(3, clusterName, "test-queue-13-B", 20)
rxMsgC += self.receiveMsgs(6, clusterName, "test-queue-13-C", 20)
rxMsgD = self.receiveMsgs(6, clusterName, "test-queue-13-D", 10)
rxMsgE = self.receiveMsgs(6, clusterName, "test-queue-13-E", 10)
# Kill all nodes but one
self.killNode(1, clusterName)
self.killNode(3, clusterName)
self.killNode(6, clusterName)
self.checkNumClusterBrokers(clusterName, 1)
# Pull all remaining messages from each queue
rxMsgA += self.receiveMsgs(5, clusterName, "test-queue-13-A", 10)
rxMsgB += self.receiveMsgs(5, clusterName, "test-queue-13-B", 10)
rxMsgC += self.receiveMsgs(5, clusterName, "test-queue-13-C", 10)
rxMsgD += self.receiveMsgs(5, clusterName, "test-queue-13-D", 10)
rxMsgE += self.receiveMsgs(5, clusterName, "test-queue-13-E", 10)
# Check messages
self.stopCheckAll()
if txMsg != rxMsgA:
self.fail("Send - receive message mismatch for queue A")
if txMsg != rxMsgB:
self.fail("Send - receive message mismatch for queue B")
if txMsg != rxMsgC:
self.fail("Send - receive message mismatch for queue C")
if tmp != rxMsgD:
self.fail("Send - receive message mismatch for queue D")
if tmp != rxMsgE:
self.fail("Send - receive message mismatch for queue E")
except:
self.killAllClusters()
raise
# Start the test here
if __name__ == '__main__':
if os.getenv("STORE_ENABLE") != None:
print "NOTE: Store enabled for the following tests:"
if not unittest.main(): sys.exit(1)
|