iron 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
1
+ require_relative 'test_base'
2
+
3
+ class TestBulk < TestBase
4
+
5
+ def setup
6
+ super
7
+
8
+ end
9
+
10
+ def test_bulk
11
+
12
+ q_name = 'ironmq-gem-bulk'
13
+ queue = @client.queue(q_name)
14
+
15
+ times = 50
16
+ t = Time.now
17
+ times.times do |i|
18
+ puts "Posting #{i}"
19
+ res = queue.post("hello world #{i}!")
20
+ end
21
+ puts "#{times} posts took #{Time.now.to_f - t.to_f}"
22
+
23
+ t = Time.now
24
+ res = nil
25
+ while (res = queue.get())
26
+ del = res.delete
27
+ end
28
+ puts "#{times} gets and deletes took #{Time.now.to_f - t.to_f}"
29
+
30
+ end
31
+
32
+ end
33
+
@@ -0,0 +1,356 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+ require_relative 'test_base'
5
+
6
+ class IronMQTests < TestBase
7
+ def setup
8
+ super
9
+
10
+ queues = @client.queues.list
11
+ p queues
12
+
13
+ clear_queue()
14
+
15
+ end
16
+
17
+ def test_performance_post_100_messages
18
+ @client.queue_name = 'test_basics_6'
19
+ # slower to rackspace since this is running on aws
20
+ timeout = @client.host.include?('rackspace') ? 40 : 12
21
+ assert_performance timeout do
22
+ 100.times do
23
+ @client.messages.post("hello world!")
24
+ end
25
+ end
26
+ end
27
+
28
+
29
+ def test_basics
30
+ queue_name = 'test_basics_6'
31
+ @client.queue_name = queue_name
32
+ clear_queue
33
+
34
+ res = @client.messages.post("hello world!")
35
+ p res
36
+ assert res["id"]
37
+ assert res.id
38
+ assert res.msg
39
+
40
+ queue = @client.queues.get(:name => @client.queue_name)
41
+ p queue
42
+ assert_equal 1, queue.reload.size
43
+ res = @client.messages.get()
44
+ p res
45
+ assert res["id"]
46
+ assert res.id
47
+
48
+ res = @client.messages.delete(res["id"])
49
+ p res
50
+ puts "shouldn't be any more"
51
+ res = @client.messages.get()
52
+ p res
53
+ assert_nil res
54
+
55
+ queue = @client.queues.get(:name => @client.queue_name)
56
+ assert_equal 0, queue.size
57
+
58
+ res = @client.messages.post("hello world 2!")
59
+ p res
60
+
61
+ msg = @client.messages.get()
62
+ p msg
63
+ assert msg
64
+
65
+ res = msg.delete
66
+ p res
67
+
68
+ puts "shouldn't be any more"
69
+ res = @client.messages.get()
70
+ p res
71
+ assert_nil res
72
+
73
+
74
+ # new style of referencing queue
75
+ queue = @client.queue(queue_name)
76
+ v = "hello big world"
77
+ res = queue.post(v)
78
+ p res
79
+ assert res.msg
80
+
81
+ res = queue.get()
82
+ p res
83
+ assert res["id"]
84
+ assert res.id
85
+ assert_equal v, res.body
86
+
87
+ res = queue.delete(res.id)
88
+ p res
89
+ puts "shouldn't be any more"
90
+ res = queue.get()
91
+ p res
92
+ assert_nil res
93
+
94
+ # test delete by item
95
+ res = queue.post(v)
96
+ p res
97
+ assert res.msg
98
+
99
+ res = queue.get()
100
+ p res
101
+ assert res.body
102
+ res = res.delete
103
+ p res
104
+ puts "shouldn't be any more"
105
+ res = queue.get()
106
+ p res
107
+ assert_nil res
108
+
109
+ end
110
+
111
+ # TODO: pass :timeout in post/get messages and test those
112
+ def test_timeout
113
+ @client.queue_name = "test_timeout_6"
114
+ clear_queue
115
+
116
+ res = @client.messages.post("hello world timeout!")
117
+ p res
118
+
119
+ msg = @client.messages.get()
120
+ p msg
121
+ assert msg
122
+
123
+ msg4 = @client.messages.get()
124
+ p msg4
125
+ assert_nil msg4
126
+
127
+ puts 'sleeping 45 seconds...'
128
+ sleep 45
129
+
130
+ msg3 = @client.messages.get()
131
+ p msg3
132
+ assert_nil msg3
133
+
134
+ puts 'sleeping another 45 seconds...'
135
+ sleep 45
136
+
137
+ msg2 = @client.messages.get()
138
+ assert msg2
139
+ assert_equal msg2.id, msg.id
140
+
141
+ msg2.delete
142
+
143
+ # now try explicit timeout
144
+ res = @client.messages.post("hello world timeout2!", :timeout => 10)
145
+ p res
146
+ msg = @client.messages.get()
147
+ p msg
148
+ assert msg
149
+ msg4 = @client.messages.get()
150
+ p msg4
151
+ assert_nil msg4
152
+ puts 'sleeping 15 seconds...'
153
+ sleep 15
154
+ msg2 = @client.messages.get()
155
+ assert msg2
156
+ assert_equal msg2.id, msg.id
157
+
158
+ end
159
+
160
+ def test_queues
161
+ puts 'test_queues'
162
+
163
+ assert_raise Rest::HttpError do
164
+ # should raise a 404
165
+ q = @client.queues.get(:name => "some_queue_that_does_not_exist")
166
+ end
167
+
168
+ res = @client.queues.list()
169
+ puts "res.size: " + res.size.to_s
170
+ res.each do |q|
171
+ puts "queue_name: " + q.name
172
+ puts "queue size: " + q.size.to_s
173
+ assert q.size >= 0
174
+ end
175
+ assert res.size > 0
176
+
177
+ res = @client.queues.list(:page => 15)
178
+ puts "res.size 2: " + res.size.to_s
179
+ res.each do |q|
180
+ p q.name
181
+ end
182
+ assert_equal 0, res.size
183
+
184
+
185
+ queue = @client.queue("test_basics_6")
186
+ assert queue.name
187
+ assert queue.size
188
+
189
+
190
+ end
191
+
192
+ def test_delay
193
+ puts 'test_delay'
194
+ @client.queue_name = "test_delay_6"
195
+ clear_queue
196
+ msgTxt = "testMessage-"+Time.now.to_s
197
+ puts msgTxt
198
+ @client.messages.post(msgTxt, {:delay => 10})
199
+ msg = @client.messages.get
200
+ p msg
201
+ assert_nil msg
202
+ sleep 10
203
+ msg = @client.messages.get
204
+ p msg
205
+ assert msg
206
+ end
207
+
208
+ def test_batch
209
+ puts 'test_batch'
210
+ @client.queue_name = "test_batch_6"
211
+ clear_queue
212
+
213
+ x = []
214
+ 10.times do |i|
215
+ x << {:body => "body #{i}"}
216
+ end
217
+ resp = @client.messages.post(x)
218
+ assert resp["ids"]
219
+ assert resp["ids"].is_a?(Array)
220
+ assert_equal 10, resp["ids"].size
221
+
222
+ msg = @client.messages.get()
223
+ assert msg
224
+ assert msg['id']
225
+ msg.delete
226
+
227
+ msgs = @client.messages.get(:n => 10)
228
+ assert msgs.is_a?(Array)
229
+ assert msgs.size == 9, "size should be 9, but it's #{msgs.size}"
230
+ assert msgs[0]["id"]
231
+
232
+ msgs.each do |m|
233
+ m.delete
234
+ end
235
+ end
236
+
237
+ def test_release
238
+ puts 'test_release'
239
+ @client.queue_name = "test_release_6"
240
+ clear_queue
241
+ msgTxt = "testMessage-"+Time.now.to_s
242
+ puts msgTxt
243
+ msg_id = @client.messages.post(msgTxt, {:timeout => 60*5}).id
244
+ puts "msg_id: #{msg_id}"
245
+ msg = @client.messages.get
246
+ p msg
247
+ assert_equal msg_id, msg.id
248
+ # Ok, so should have received same message, now let's release it quicker than the original timeout
249
+
250
+ # but first, ensure the next get is nil
251
+ msg = @client.messages.get
252
+ p msg
253
+ assert_nil msg
254
+
255
+ # now release it instantly
256
+ @client.messages.release(msg_id)
257
+ msg = @client.messages.get
258
+ p msg
259
+ assert msg
260
+ assert_equal msg_id, msg.id
261
+
262
+ # ok, so should be reserved again
263
+ msgr = @client.messages.get
264
+ p msgr
265
+ assert_nil msgr
266
+
267
+ # let's release it in 10 seconds
268
+ @client.messages.release(msg_id, :delay => 10)
269
+ msg = @client.messages.get
270
+ p msg
271
+ assert_nil msg
272
+
273
+ sleep 11
274
+
275
+ msg = @client.messages.get
276
+ p msg
277
+ assert msg
278
+
279
+ msg.release(:delay => 5)
280
+ msg = @client.messages.get
281
+ p msg
282
+ assert_nil msg
283
+
284
+ sleep 6
285
+
286
+ msg = @client.messages.get
287
+ p msg
288
+ assert msg
289
+
290
+ end
291
+
292
+ def test_clear
293
+
294
+ q = @client.queue("clearer_6")
295
+
296
+ clear_queue(q.name)
297
+
298
+ val = "hi mr clean"
299
+ q.post(val)
300
+
301
+ sleep 0.5 # make sure the counter has time to update
302
+ assert_equal 1, q.size
303
+
304
+ q.clear
305
+
306
+ msg = q.get
307
+ assert_nil msg
308
+
309
+ assert_equal 0, q.reload.size
310
+ end
311
+
312
+
313
+
314
+ def test_poll
315
+ queue = @client.queue("test_poll_6")
316
+ queue.clear
317
+
318
+ v = "hello world"
319
+ 5.times do
320
+ queue.post(v)
321
+ end
322
+
323
+ i = 0
324
+ queue.poll(:break_if_nil=>true) do |msg|
325
+ assert msg.body.include?("hello")
326
+ i += 1
327
+ end
328
+
329
+ assert_equal 5, i
330
+
331
+ assert_equal 0, queue.reload.size
332
+
333
+ end
334
+ #
335
+ #def test_delete
336
+ # queue = @client.queue("test_delete")
337
+ # queue.post("hi")
338
+ # queue.reload
339
+ # old_id = queue.id
340
+ # queue.delete_queue
341
+ #
342
+ # puts "sleeping for a bit to let queue delete..."
343
+ # sleep 60
344
+ #
345
+ # queue.post("hi2")
346
+ # p queue
347
+ # queue.reload
348
+ # assert queue.id != old_id, "old_id: #{old_id} is equal to new id: #{queue.id}"
349
+ # assert queue.size == 1
350
+ # queue.get("").body == "hi2"
351
+ #
352
+ #end
353
+
354
+
355
+ end
356
+
@@ -0,0 +1,45 @@
1
+ gem 'test-unit'
2
+ require 'test/unit'
3
+ require 'yaml'
4
+ require_relative 'test_base'
5
+
6
+ class IronMQTests < TestBase
7
+ def setup
8
+ super
9
+
10
+ @queue_name = "fixed_num2_migration"
11
+
12
+ end
13
+
14
+ def test_put_x
15
+ q = @client.queue(@queue_name)
16
+ 1000.times do |i|
17
+ puts "#{i}"
18
+ q.post("msg #{i}")
19
+ end
20
+ p q.reload.size
21
+ assert_equal 1800, q.size
22
+ end
23
+
24
+ def test_get_x
25
+ #q = @client.queue(@queue_name)
26
+ #puts "q.size: #{q.size}"
27
+ #100.times do |i|
28
+ # puts "#{i}"
29
+ # msg = q.get
30
+ # msg.delete
31
+ #end
32
+ #p q.reload.size
33
+ #assert_equal 900, q.reload.size
34
+ end
35
+ #
36
+ #def test_poll_all
37
+ # q = @client.queue(@queue_name)
38
+ # puts "q.size: #{q.size}"
39
+ # q.poll do |msg|
40
+ # p msg
41
+ # end
42
+ # p queue.reload.size
43
+ #end
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,218 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: iron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Travis Reeder
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: iron_core
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.4.2
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.4.2
30
+ - !ruby/object:Gem::Dependency
31
+ name: test-unit
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: minitest
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: beanstalk-client
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: uber_config
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: typhoeus
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: concur
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: net-http-persistent
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ description: Ruby client for IronMQ by www.iron.io
159
+ email:
160
+ - treeder@gmail.com
161
+ executables: []
162
+ extensions: []
163
+ extra_rdoc_files: []
164
+ files:
165
+ - .gitignore
166
+ - Gemfile
167
+ - Gemfile.lock
168
+ - README.md
169
+ - Rakefile
170
+ - iron_mq.gemspec
171
+ - lib/iron_mq.rb
172
+ - lib/iron_mq/client.rb
173
+ - lib/iron_mq/messages.rb
174
+ - lib/iron_mq/queues.rb
175
+ - lib/iron_mq/version.rb
176
+ - test/long_run.rb
177
+ - test/long_run_worker.rb
178
+ - test/quick_run.rb
179
+ - test/schedule_abt.rb
180
+ - test/test_base.rb
181
+ - test/test_beanstalkd.rb
182
+ - test/test_bulk.rb
183
+ - test/test_iron_mq.rb
184
+ - test/tmp.rb
185
+ homepage: https://github.com/iron-io/iron_mq_ruby
186
+ licenses: []
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ none: false
193
+ requirements:
194
+ - - ! '>='
195
+ - !ruby/object:Gem::Version
196
+ version: '1.9'
197
+ required_rubygems_version: !ruby/object:Gem::Requirement
198
+ none: false
199
+ requirements:
200
+ - - ! '>='
201
+ - !ruby/object:Gem::Version
202
+ version: 1.3.6
203
+ requirements: []
204
+ rubyforge_project:
205
+ rubygems_version: 1.8.24
206
+ signing_key:
207
+ specification_version: 3
208
+ summary: Ruby client for IronMQ by www.iron.io
209
+ test_files:
210
+ - test/long_run.rb
211
+ - test/long_run_worker.rb
212
+ - test/quick_run.rb
213
+ - test/schedule_abt.rb
214
+ - test/test_base.rb
215
+ - test/test_beanstalkd.rb
216
+ - test/test_bulk.rb
217
+ - test/test_iron_mq.rb
218
+ - test/tmp.rb