iron_mq 3.1.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile.lock +10 -8
- data/README.md +278 -53
- data/iron_mq.gemspec +3 -2
- data/lib/iron_mq/client.rb +32 -9
- data/lib/iron_mq/messages.rb +21 -104
- data/lib/iron_mq/queues.rb +149 -142
- data/lib/iron_mq/response.rb +16 -15
- data/lib/iron_mq/subscribers.rb +12 -21
- data/lib/iron_mq/version.rb +1 -1
- data/test/quick_run.rb +69 -39
- data/test/test_base.rb +13 -5
- data/test/test_beanstalkd.rb +26 -4
- data/test/test_bulk.rb +7 -3
- data/test/test_iron_mq.rb +370 -159
- data/test/test_push_queues.rb +21 -7
- metadata +41 -45
data/test/test_iron_mq.rb
CHANGED
@@ -1,119 +1,128 @@
|
|
1
1
|
require 'test/unit'
|
2
2
|
require 'yaml'
|
3
|
-
require 'test_base'
|
3
|
+
require File.expand_path('test_base.rb', File.dirname(__FILE__))
|
4
4
|
|
5
5
|
class IronMQTests < TestBase
|
6
6
|
def setup
|
7
7
|
super
|
8
8
|
@skip = @host.include? 'rackspace'
|
9
9
|
LOG.info "@host: #{@host}"
|
10
|
+
|
10
11
|
queues = @client.queues.list
|
11
|
-
p queues
|
12
|
-
clear_queue()
|
12
|
+
# p queues
|
13
13
|
end
|
14
14
|
|
15
15
|
def test_performance_post_100_messages
|
16
|
-
@client.
|
16
|
+
queue = @client.queue('test_perf_100')
|
17
17
|
# slower to rackspace since this is running on aws
|
18
18
|
timeout = @host.include?('rackspace') ? 40 : 12
|
19
|
-
|
19
|
+
|
20
|
+
assert_performance(timeout) do
|
20
21
|
100.times do
|
21
|
-
|
22
|
+
queue.post("hello world!")
|
22
23
|
end
|
24
|
+
|
25
|
+
# delete queue on test complete
|
26
|
+
resp = queue.delete_queue
|
27
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
23
28
|
end
|
24
29
|
end
|
25
30
|
|
26
31
|
|
27
32
|
def test_basics
|
28
33
|
queue_name = 'test_basics_7'
|
29
|
-
|
30
|
-
|
34
|
+
clear_queue(queue_name)
|
35
|
+
|
36
|
+
# NOTE: Kept for backward compatibility checking
|
37
|
+
queue = @client.queues.get(:name => queue_name)
|
38
|
+
# p queue
|
39
|
+
res = queue.post("hello world!")
|
40
|
+
# p res
|
31
41
|
|
32
|
-
res = @client.messages.post("hello world!")
|
33
|
-
p res
|
34
42
|
assert res["id"]
|
35
43
|
assert res.id
|
36
44
|
assert res.msg
|
37
45
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
p res
|
46
|
+
assert_equal 1, queue.size
|
47
|
+
|
48
|
+
message = queue.get
|
49
|
+
# p res
|
43
50
|
assert res["id"]
|
44
51
|
assert res.id
|
45
52
|
|
46
|
-
res =
|
47
|
-
p res
|
53
|
+
res = queue.delete(res["id"])
|
54
|
+
# p res
|
48
55
|
puts "shouldn't be any more"
|
49
|
-
res =
|
50
|
-
p res
|
56
|
+
res = queue.get
|
57
|
+
# p res
|
51
58
|
assert_nil res
|
52
59
|
|
53
|
-
queue = @client.queues.get(:name => @client.queue_name)
|
54
60
|
assert_equal 0, queue.size
|
55
61
|
|
56
|
-
res =
|
57
|
-
p res
|
62
|
+
res = queue.post("hello world 2!")
|
63
|
+
# p res
|
58
64
|
|
59
|
-
msg =
|
60
|
-
p msg
|
65
|
+
msg = queue.get
|
66
|
+
# p msg
|
61
67
|
assert msg
|
62
68
|
|
63
69
|
res = msg.delete
|
64
|
-
p res
|
70
|
+
#p res
|
65
71
|
|
66
72
|
puts "shouldn't be any more"
|
67
|
-
res =
|
68
|
-
p res
|
73
|
+
res = queue.get
|
74
|
+
# p res
|
69
75
|
assert_nil res
|
70
76
|
|
71
|
-
|
72
77
|
# new style of referencing queue
|
73
78
|
queue = @client.queue(queue_name)
|
74
79
|
v = "hello big world"
|
75
80
|
res = queue.post(v)
|
76
|
-
p res
|
81
|
+
# p res
|
77
82
|
assert res.msg
|
78
83
|
|
79
|
-
res = queue.get
|
80
|
-
p res
|
84
|
+
res = queue.get
|
85
|
+
# p res
|
81
86
|
assert res["id"]
|
82
87
|
assert res.id
|
83
88
|
assert_equal v, res.body
|
84
89
|
|
85
90
|
res = queue.delete(res.id)
|
86
|
-
p res
|
91
|
+
# p res
|
87
92
|
puts "shouldn't be any more"
|
88
|
-
res = queue.get
|
89
|
-
p res
|
93
|
+
res = queue.get
|
94
|
+
# p res
|
90
95
|
assert_nil res
|
91
96
|
|
92
97
|
# test delete by item
|
93
98
|
res = queue.post(v)
|
94
|
-
p res
|
99
|
+
# p res
|
95
100
|
assert res.msg
|
96
101
|
|
97
|
-
res = queue.get
|
98
|
-
p res
|
102
|
+
res = queue.get
|
103
|
+
# p res
|
99
104
|
assert res.body
|
105
|
+
|
100
106
|
res = res.delete
|
101
|
-
p res
|
107
|
+
# p res
|
102
108
|
puts "shouldn't be any more"
|
103
|
-
res = queue.get
|
104
|
-
p res
|
109
|
+
res = queue.get
|
110
|
+
# p res
|
105
111
|
assert_nil res
|
106
112
|
|
113
|
+
# delete queue on test complete
|
114
|
+
resp = queue.delete_queue
|
115
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
107
116
|
end
|
108
117
|
|
109
118
|
|
110
119
|
def test_queues_list
|
111
120
|
queue_name = 'test_queues_list'
|
112
|
-
|
113
|
-
clear_queue
|
121
|
+
clear_queue(queue_name)
|
114
122
|
|
115
|
-
|
116
|
-
|
123
|
+
queue = @client.queue(queue_name)
|
124
|
+
res = queue.post("hello world!")
|
125
|
+
# p res
|
117
126
|
|
118
127
|
res = @client.queues.list
|
119
128
|
res.each do |q|
|
@@ -122,23 +131,29 @@ class IronMQTests < TestBase
|
|
122
131
|
assert_equal q.size, 1
|
123
132
|
end
|
124
133
|
end
|
134
|
+
|
135
|
+
# delete queue on test complete
|
136
|
+
resp = queue.delete_queue
|
137
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
125
138
|
end
|
126
139
|
|
127
140
|
|
128
141
|
# TODO: pass :timeout in post/get messages and test those
|
129
142
|
def test_timeout
|
130
|
-
|
131
|
-
clear_queue
|
143
|
+
queue_name = "test_timeout_6"
|
144
|
+
clear_queue(queue_name)
|
145
|
+
|
146
|
+
queue = @client.queue(queue_name)
|
132
147
|
|
133
|
-
res =
|
134
|
-
p res
|
148
|
+
res = queue.post("hello world timeout!")
|
149
|
+
# p res
|
135
150
|
|
136
|
-
msg =
|
137
|
-
p msg
|
151
|
+
msg = queue.get
|
152
|
+
# p msg
|
138
153
|
assert msg
|
139
154
|
|
140
|
-
msg_nil =
|
141
|
-
p msg_nil
|
155
|
+
msg_nil = queue.get
|
156
|
+
# p msg_nil
|
142
157
|
assert_nil msg_nil
|
143
158
|
|
144
159
|
tries = MAX_TRIES
|
@@ -146,23 +161,28 @@ class IronMQTests < TestBase
|
|
146
161
|
sleep 0.5
|
147
162
|
tries -= 1
|
148
163
|
sleep 1
|
149
|
-
|
150
|
-
|
164
|
+
|
165
|
+
new_msg = queue.get
|
166
|
+
# p new_msg
|
151
167
|
next if new_msg.nil?
|
168
|
+
|
152
169
|
assert_equal new_msg.id, msg.id
|
170
|
+
|
153
171
|
new_msg.delete
|
154
172
|
break
|
155
173
|
end
|
156
174
|
assert_not_equal tries, 0
|
157
175
|
|
158
176
|
# now try explicit timeout
|
159
|
-
res =
|
160
|
-
p res
|
161
|
-
msg =
|
162
|
-
p msg
|
177
|
+
res = queue.post("hello world timeout2!", :timeout => 30)
|
178
|
+
# p res
|
179
|
+
msg = queue.get
|
180
|
+
# p msg
|
163
181
|
assert msg
|
164
|
-
|
165
|
-
|
182
|
+
assert_equal msg.raw['timeout'], 30
|
183
|
+
|
184
|
+
msg_nil = queue.get
|
185
|
+
# p msg_nil
|
166
186
|
assert_nil msg_nil
|
167
187
|
|
168
188
|
tries = MAX_TRIES
|
@@ -170,50 +190,90 @@ class IronMQTests < TestBase
|
|
170
190
|
sleep 0.5
|
171
191
|
tries -= 1
|
172
192
|
sleep 1
|
173
|
-
|
193
|
+
|
194
|
+
new_msg = queue.get
|
174
195
|
next if new_msg.nil?
|
196
|
+
|
175
197
|
assert_equal new_msg.id, msg.id
|
198
|
+
|
199
|
+
new_msg.delete
|
176
200
|
break
|
177
201
|
end
|
178
202
|
assert_not_equal tries, 0
|
179
203
|
|
204
|
+
# timeout on get
|
205
|
+
res = queue.post("hello world timeout3!")
|
206
|
+
msg = queue.get(:timeout => 30)
|
207
|
+
assert msg
|
208
|
+
assert_equal msg.raw['timeout'], 30
|
209
|
+
|
210
|
+
msg_nil = queue.get
|
211
|
+
# p msg_nil
|
212
|
+
assert_nil msg_nil
|
213
|
+
|
214
|
+
tries = MAX_TRIES
|
215
|
+
while tries > 0
|
216
|
+
sleep 0.5
|
217
|
+
tries -= 1
|
218
|
+
sleep 1
|
219
|
+
|
220
|
+
new_msg = queue.get
|
221
|
+
next if new_msg.nil?
|
222
|
+
|
223
|
+
assert_equal new_msg.id, msg.id
|
224
|
+
|
225
|
+
new_msg.delete
|
226
|
+
break
|
227
|
+
end
|
228
|
+
assert_not_equal tries, 0
|
229
|
+
|
230
|
+
# delete queue on test complete
|
231
|
+
resp = queue.delete_queue
|
232
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
180
233
|
end
|
181
234
|
|
182
235
|
def test_queues
|
183
236
|
puts 'test_queues'
|
184
237
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
238
|
+
# Now client library is not provide plain call to API
|
239
|
+
# But creates Queue object instead
|
240
|
+
# also added `#new?` method to check is queue exist
|
241
|
+
#
|
242
|
+
#assert_raise Rest::HttpError do
|
243
|
+
# # should raise a 404
|
244
|
+
# q = @client.queues.get(:name => "some_queue_that_does_not_exist")
|
245
|
+
#end
|
246
|
+
queue = @client.queues.get(:name => "some_queue_that_does_not_exist")
|
247
|
+
assert queue.new? == true
|
189
248
|
|
190
|
-
res = @client.queues.list
|
191
|
-
puts "res.size:
|
249
|
+
res = @client.queues.list
|
250
|
+
# puts "res.size: #{res.size}"
|
192
251
|
res.each do |q|
|
193
|
-
puts "queue_name: " + q.name
|
194
|
-
puts "queue size: " + q.size.to_s
|
252
|
+
# puts "queue_name: " + q.name
|
253
|
+
# puts "queue size: " + q.size.to_s
|
195
254
|
assert q.size >= 0
|
196
255
|
end
|
197
256
|
assert res.size > 0
|
198
257
|
|
199
258
|
res = @client.queues.list(:page => 15)
|
200
|
-
puts "res.size 2:
|
201
|
-
res.each do |q|
|
202
|
-
p q.name
|
203
|
-
end
|
204
|
-
assert_equal 0, res.size
|
259
|
+
# puts "res.size 2: #{res.size}"
|
260
|
+
# res.each do |q| { p q.name }
|
205
261
|
|
262
|
+
assert_equal 0, res.size
|
206
263
|
end
|
207
264
|
|
208
265
|
def test_delay
|
209
266
|
puts 'test_delay'
|
210
|
-
|
211
|
-
|
267
|
+
|
268
|
+
queue_name = "test_delay_6"
|
269
|
+
clear_queue(queue_name)
|
270
|
+
|
212
271
|
msgTxt = "testMessage-"+Time.now.to_s
|
213
|
-
puts msgTxt
|
214
|
-
@client.
|
215
|
-
|
216
|
-
|
272
|
+
# puts msgTxt
|
273
|
+
queue = @client.queue(queue_name)
|
274
|
+
queue.post(msgTxt, {:delay => 5})
|
275
|
+
msg = queue.get
|
276
|
+
# p msg
|
217
277
|
assert_nil msg
|
218
278
|
|
219
279
|
tries = MAX_TRIES
|
@@ -221,97 +281,235 @@ class IronMQTests < TestBase
|
|
221
281
|
sleep 0.5
|
222
282
|
tries -= 1
|
223
283
|
sleep 1
|
224
|
-
|
225
|
-
|
284
|
+
|
285
|
+
msg = queue.get
|
286
|
+
# p msg
|
226
287
|
next if msg.nil?
|
288
|
+
|
227
289
|
assert_equal msg.body, msgTxt
|
290
|
+
|
228
291
|
break
|
229
292
|
end
|
230
293
|
assert_not_equal tries, 0
|
231
|
-
|
294
|
+
|
295
|
+
# delete queue on test complete
|
296
|
+
resp = queue.delete_queue
|
297
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
232
298
|
end
|
233
299
|
|
234
300
|
def test_batch
|
235
301
|
puts 'test_batch'
|
236
|
-
|
237
|
-
|
302
|
+
|
303
|
+
queue_name = "test_batch_6"
|
304
|
+
clear_queue(queue_name)
|
238
305
|
|
239
306
|
x = []
|
240
307
|
10.times do |i|
|
241
308
|
x << {:body => "body #{i}"}
|
242
309
|
end
|
243
|
-
|
310
|
+
|
311
|
+
queue = @client.queue(queue_name)
|
312
|
+
|
313
|
+
resp = queue.post(x)
|
244
314
|
assert resp["ids"]
|
245
315
|
assert resp["ids"].is_a?(Array)
|
246
316
|
assert_equal 10, resp["ids"].size
|
247
317
|
|
248
|
-
msg =
|
318
|
+
msg = queue.get
|
249
319
|
assert msg
|
250
320
|
assert msg['id']
|
251
321
|
msg.delete
|
252
322
|
|
253
|
-
msgs =
|
323
|
+
msgs = queue.get(:n => 10)
|
254
324
|
assert msgs.is_a?(Array)
|
255
325
|
assert msgs.size == 9, "size should be 9, but it's #{msgs.size}"
|
256
326
|
assert msgs[0]["id"]
|
257
327
|
|
258
328
|
msgs.each do |m|
|
259
|
-
m.delete
|
329
|
+
resp = m.delete
|
330
|
+
assert_equal 200, resp.code, "API must delete message and response with HTTP 200 status, but returned HTTP #{resp.code}"
|
260
331
|
end
|
332
|
+
|
333
|
+
# delete queue on test complete
|
334
|
+
resp = queue.delete_queue
|
335
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
336
|
+
end
|
337
|
+
|
338
|
+
def test_peek
|
339
|
+
puts "test_message_peek"
|
340
|
+
|
341
|
+
queue_name = "test_msg_peek"
|
342
|
+
clear_queue(queue_name)
|
343
|
+
|
344
|
+
queue = @client.queue(queue_name)
|
345
|
+
queue.post([ {:body => "first message"},
|
346
|
+
{:body => "second message"},
|
347
|
+
{:body => "third message"} ])
|
348
|
+
|
349
|
+
msg = queue.peek
|
350
|
+
assert_not_nil msg
|
351
|
+
assert_equal "first message", msg.body, "message body must be 'first message', but it's '#{msg.body}'"
|
352
|
+
|
353
|
+
msg = queue.peek
|
354
|
+
assert_not_nil msg
|
355
|
+
assert_equal "first message", msg.body, "message body must be 'first message', but it's '#{msg.body}'"
|
356
|
+
|
357
|
+
msgs = queue.peek(:n => 2)
|
358
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
359
|
+
assert_equal 2, msgs.size, "must received 2 messages, but received #{msgs.size}"
|
360
|
+
|
361
|
+
msg = queue.peek
|
362
|
+
assert_not_nil msg
|
363
|
+
assert_equal "first message", msg.body, "message body must be 'first message', but it's '#{msg.body}'"
|
364
|
+
|
365
|
+
msgs = queue.peek(:n => 7)
|
366
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
367
|
+
assert_equal 3, msgs.size, "must received 3 messages, but received #{msgs.size}"
|
368
|
+
|
369
|
+
msg = queue.get
|
370
|
+
assert_not_nil msg
|
371
|
+
assert_equal "first message", msg.body, "message body must be 'first message', but it's '#{msg.body}'"
|
372
|
+
|
373
|
+
resp = msg.delete
|
374
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
375
|
+
|
376
|
+
msg = queue.peek
|
377
|
+
assert_not_nil msg
|
378
|
+
assert_equal "second message", msg.body, "message body must be 'second message', but it's '#{msg.body}'"
|
379
|
+
|
380
|
+
# delete queue on test complete
|
381
|
+
resp = queue.delete_queue
|
382
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
383
|
+
end
|
384
|
+
|
385
|
+
def test_touch
|
386
|
+
puts "test_message_touch"
|
387
|
+
|
388
|
+
queue_name = "test_msg_touch"
|
389
|
+
clear_queue(queue_name)
|
390
|
+
|
391
|
+
queue = @client.queue(queue_name)
|
392
|
+
queue.post([
|
393
|
+
{:body => "first message"},
|
394
|
+
{:body => "second message"},
|
395
|
+
{:body => "third message"}
|
396
|
+
],
|
397
|
+
{:timeout => 30}) # minimum timeout
|
398
|
+
|
399
|
+
# get message
|
400
|
+
msg = queue.get
|
401
|
+
assert_not_nil msg
|
402
|
+
assert_equal "first message", msg.body, "message body must be 'first message', but it's '#{msg.body}'"
|
403
|
+
|
404
|
+
sleep 15 # timeout is not passed
|
405
|
+
|
406
|
+
msgs = queue.peek(:n => 3) # all messages from queue
|
407
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
408
|
+
assert_equal 2, msgs.size, "API must return only 2 messages"
|
409
|
+
msgs.each { |m| assert_not_equal msg.id, m.id, "returned message which must be reserved" }
|
410
|
+
|
411
|
+
sleep 20 # ensure timeout is passed
|
412
|
+
|
413
|
+
# message must return to the queue
|
414
|
+
msgs = queue.peek(:n => 3)
|
415
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
416
|
+
assert_equal 3, msgs.size, "API must return 3 messages"
|
417
|
+
assert_equal msg.id, msgs[2].id, "released message must be at the end of the queue"
|
418
|
+
|
419
|
+
msg = queue.get
|
420
|
+
assert_not_nil msg
|
421
|
+
assert_equal "second message", msg.body, "message body must be 'second message', but it's '#{msg.body}'"
|
422
|
+
|
423
|
+
sleep 15 # timeout is not passed
|
424
|
+
|
425
|
+
msgs = queue.peek(:n => 3) # must return another message
|
426
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
427
|
+
assert_equal 2, msgs.size, "API must return only 2 messages"
|
428
|
+
msgs.each { |m| assert_not_equal msg.id, m.id, "returned message which must be reserved" }
|
429
|
+
|
430
|
+
resp = msg.touch # more 30 seconds timeout
|
431
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
432
|
+
|
433
|
+
sleep 20 # new timeout is not passed, but previous is (15 + 20 vs 30 + 30 seconds)
|
434
|
+
|
435
|
+
msgs = queue.peek(:n => 3) # must return the same as for msg2
|
436
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
437
|
+
assert_equal 2, msgs.size, "API must return only 2 messages"
|
438
|
+
msgs.each { |m| assert_not_equal msg.id, m.id, "returned message which must be reserved" }
|
439
|
+
|
440
|
+
sleep 15 # ensure timeout passed
|
441
|
+
|
442
|
+
# message must be returned to the end of the queue
|
443
|
+
msgs = queue.peek(:n => 3)
|
444
|
+
assert_equal Array, msgs.class, "waiting for Array, but got #{msgs.class}"
|
445
|
+
assert_equal 3, msgs.size, "API must return 3 messages"
|
446
|
+
assert_equal msg.id, msgs[2].id, "released message must be at the end of the queue"
|
447
|
+
|
448
|
+
# delete queue on test complete
|
449
|
+
resp = queue.delete_queue
|
450
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
261
451
|
end
|
262
452
|
|
263
453
|
def test_release
|
264
454
|
puts 'test_release'
|
265
|
-
|
266
|
-
|
455
|
+
|
456
|
+
queue_name = "test_release_6"
|
457
|
+
clear_queue(queue_name)
|
458
|
+
|
267
459
|
msgTxt = "testMessage-"+Time.now.to_s
|
268
|
-
puts msgTxt
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
460
|
+
# puts msgTxt
|
461
|
+
|
462
|
+
queue = @client.queue(queue_name)
|
463
|
+
|
464
|
+
msg_id = queue.post(msgTxt, {:timeout => 60*5}).id
|
465
|
+
# puts "msg_id: #{msg_id}"
|
466
|
+
message = queue.get
|
467
|
+
# p msg
|
468
|
+
assert_equal msg_id, message.id
|
274
469
|
# Ok, so should have received same message, now let's release it quicker than the original timeout
|
275
470
|
|
276
471
|
# but first, ensure the next get is nil
|
277
|
-
msg =
|
278
|
-
p msg
|
472
|
+
msg = queue.get
|
473
|
+
# p msg
|
279
474
|
assert_nil msg
|
280
475
|
|
281
476
|
# now release it instantly
|
282
|
-
|
283
|
-
msg =
|
284
|
-
p msg
|
477
|
+
message.release
|
478
|
+
msg = queue.get
|
479
|
+
# p msg
|
285
480
|
assert msg
|
286
|
-
assert_equal msg_id,
|
481
|
+
assert_equal msg_id, msg.id
|
287
482
|
|
288
483
|
# ok, so should be reserved again
|
289
|
-
msgr =
|
290
|
-
p msgr
|
484
|
+
msgr = queue.get
|
485
|
+
# p msgr
|
291
486
|
assert_nil msgr
|
292
487
|
|
293
488
|
# let's release it in 10 seconds
|
294
|
-
|
295
|
-
|
296
|
-
p msg
|
297
|
-
assert_nil
|
489
|
+
msg.release(:delay => 10)
|
490
|
+
msgr = queue.get
|
491
|
+
# p msg
|
492
|
+
assert_nil msgr
|
298
493
|
|
299
494
|
tries = MAX_TRIES
|
300
495
|
while tries > 0
|
301
496
|
sleep 0.5
|
302
497
|
tries -= 1
|
303
498
|
sleep 1
|
304
|
-
|
499
|
+
|
500
|
+
msg = queue.get
|
305
501
|
next if msg.nil?
|
306
|
-
|
502
|
+
|
503
|
+
#p msg
|
307
504
|
assert_equal msg.id, msg_id
|
505
|
+
|
308
506
|
break
|
309
507
|
end
|
310
508
|
assert_not_equal tries, 0
|
311
509
|
|
312
510
|
msg.release(:delay => 5)
|
313
|
-
msg =
|
314
|
-
p msg
|
511
|
+
msg = queue.get
|
512
|
+
# p msg
|
315
513
|
assert_nil msg
|
316
514
|
|
317
515
|
tries = MAX_TRIES
|
@@ -319,52 +517,59 @@ class IronMQTests < TestBase
|
|
319
517
|
sleep 0.5
|
320
518
|
tries -= 1
|
321
519
|
sleep 1
|
322
|
-
|
520
|
+
|
521
|
+
msg = queue.get
|
323
522
|
next if msg.nil?
|
324
|
-
|
523
|
+
|
524
|
+
# p msg
|
325
525
|
assert_equal msg.id, msg_id
|
526
|
+
|
326
527
|
break
|
327
528
|
end
|
328
529
|
assert_not_equal tries, 0
|
530
|
+
|
531
|
+
# delete queue on test complete
|
532
|
+
resp = queue.delete_queue
|
533
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
329
534
|
end
|
330
535
|
|
331
536
|
|
332
537
|
def test_clear
|
538
|
+
puts "test_clear"
|
333
539
|
|
334
|
-
|
335
|
-
|
336
|
-
clear_queue(q.name)
|
540
|
+
queue = @client.queue("test_clear_7")
|
541
|
+
clear_queue(queue.name)
|
337
542
|
|
338
543
|
val = "hi mr clean"
|
339
|
-
|
544
|
+
queue.post(val)
|
340
545
|
|
341
546
|
sleep 0.5 # make sure the counter has time to update
|
342
|
-
assert_equal 1,
|
547
|
+
assert_equal 1, queue.size
|
343
548
|
|
344
|
-
|
549
|
+
queue.clear
|
345
550
|
|
346
|
-
msg =
|
551
|
+
msg = queue.get
|
347
552
|
assert_nil msg
|
348
553
|
|
349
|
-
assert_equal 0,
|
350
|
-
end
|
554
|
+
assert_equal 0, queue.size
|
351
555
|
|
556
|
+
# delete queue on test complete
|
557
|
+
resp = queue.delete_queue
|
558
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
559
|
+
end
|
352
560
|
|
353
561
|
|
354
562
|
def test_poll
|
355
563
|
queue_name = "test_poll_6"
|
356
|
-
|
357
|
-
clear_queue
|
564
|
+
clear_queue(queue_name)
|
358
565
|
|
359
566
|
queue = @client.queue(queue_name)
|
360
567
|
|
361
568
|
v = "hello world"
|
362
|
-
5.times
|
363
|
-
queue.post(v)
|
364
|
-
end
|
569
|
+
5.times { queue.post(v) }
|
365
570
|
|
366
571
|
i = 0
|
367
|
-
queue.poll(:break_if_nil=>true) do |msg|
|
572
|
+
queue.poll(:break_if_nil => true) do |msg|
|
368
573
|
assert msg.body.include?("hello")
|
369
574
|
i += 1
|
370
575
|
end
|
@@ -374,55 +579,61 @@ class IronMQTests < TestBase
|
|
374
579
|
tries = MAX_TRIES
|
375
580
|
while tries > 0
|
376
581
|
tries -= 1
|
377
|
-
break if 0 == queue.
|
582
|
+
break if 0 == queue.size
|
378
583
|
sleep 0.5
|
379
584
|
end
|
380
585
|
assert_not_equal tries, 0
|
381
|
-
|
382
586
|
|
587
|
+
# delete queue on test complete
|
588
|
+
resp = queue.delete_queue
|
589
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
590
|
+
end
|
591
|
+
|
592
|
+
def test_queue_delete
|
593
|
+
queue = @client.queue("test_delete")
|
594
|
+
queue.post("hi")
|
595
|
+
old_id = queue.id
|
596
|
+
queue.delete_queue
|
597
|
+
|
598
|
+
LOG.info "sleeping for a bit to let queue delete..."
|
599
|
+
sleep 60
|
600
|
+
|
601
|
+
queue.post("hi2")
|
602
|
+
# p queue
|
603
|
+
q_info = queue.info
|
604
|
+
assert_not_equal old_id, q_info.id, "old queue ID (#{old_id}) must not be equal to new ID (#{q_info.id})"
|
605
|
+
assert_equal 1, q_info.size, "queue size must be 1, but got #{q_info.size}"
|
606
|
+
|
607
|
+
msg = queue.get
|
608
|
+
assert_equal "hi2", msg.body, "message body must be 'hi2', but got '#{msg.body}'"
|
609
|
+
|
610
|
+
# delete queue on test complete
|
611
|
+
resp = queue.delete_queue
|
612
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
383
613
|
end
|
384
|
-
#
|
385
|
-
#def test_delete
|
386
|
-
# queue = @client.queue("test_delete")
|
387
|
-
# queue.post("hi")
|
388
|
-
# queue.reload
|
389
|
-
# old_id = queue.id
|
390
|
-
# queue.delete_queue
|
391
|
-
#
|
392
|
-
# puts "sleeping for a bit to let queue delete..."
|
393
|
-
# sleep 60
|
394
|
-
#
|
395
|
-
# queue.post("hi2")
|
396
|
-
# p queue
|
397
|
-
# queue.reload
|
398
|
-
# assert queue.id != old_id, "old_id: #{old_id} is equal to new id: #{queue.id}"
|
399
|
-
# assert queue.size == 1
|
400
|
-
# queue.get("").body == "hi2"
|
401
|
-
#
|
402
|
-
#end
|
403
614
|
|
404
615
|
def test_webhooks
|
405
616
|
omit_if @skip
|
406
617
|
puts "skip webhooks: #{@skip}"
|
407
618
|
qname ="webhook_queue"
|
408
|
-
|
409
|
-
|
410
|
-
url << "?oauth=#{@client.token}"
|
411
|
-
p url
|
619
|
+
url = "#{@client.base_url}/#{qname}/messages/webhook?oauth=#{@client.token}"
|
620
|
+
# p url
|
412
621
|
|
413
622
|
v = "hello webhook"
|
414
623
|
|
415
624
|
@rest = Rest::Client.new
|
416
|
-
|
625
|
+
resp = @rest.post(url, :body => v)
|
626
|
+
# p resp
|
417
627
|
|
418
628
|
queue = @client.queue(qname)
|
419
629
|
msg = queue.get
|
420
|
-
p msg
|
630
|
+
# p msg
|
421
631
|
assert_equal v, msg.body
|
422
632
|
|
423
|
-
|
633
|
+
# delete queue on test complete
|
634
|
+
resp = queue.delete_queue
|
635
|
+
assert_equal 200, resp.code, "API must response with HTTP 200 status, but returned HTTP #{resp.code}"
|
424
636
|
end
|
425
637
|
|
426
|
-
|
427
638
|
end
|
428
639
|
|