allq_client 1.0.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +0 -0
- data/README.md +0 -0
- data/Rakefile +0 -0
- data/allq_client-1.1.0.gem +0 -0
- data/allq_client.gemspec +0 -0
- data/deploy.sh +3 -0
- data/docs/ActionsApi.md +0 -0
- data/docs/AdminApi.md +0 -0
- data/docs/BasicPayload.md +0 -0
- data/docs/BasicResponse.md +0 -0
- data/docs/JobRef.md +0 -0
- data/docs/JobResponse.md +0 -0
- data/docs/NewJob.md +0 -0
- data/docs/NewParentJob.md +0 -0
- data/docs/StatsInfo.md +0 -0
- data/docs/StatsResults.md +0 -0
- data/docs/StatsTube.md +0 -0
- data/docs/Throttle.md +0 -0
- data/docs/TubeRef.md +0 -0
- data/lib/.DS_Store +0 -0
- data/lib/allq_client.rb +2 -1
- data/lib/allq_client/.DS_Store +0 -0
- data/lib/allq_client/api/actions_api.rb +96 -45
- data/lib/allq_client/api/admin_api.rb +62 -9
- data/lib/allq_client/api_client.rb +9 -9
- data/lib/allq_client/api_error.rb +1 -1
- data/lib/allq_client/configuration.rb +2 -2
- data/lib/allq_client/models/basic_payload.rb +7 -12
- data/lib/allq_client/models/basic_response.rb +7 -12
- data/lib/allq_client/models/job_ref.rb +7 -11
- data/lib/allq_client/models/job_response.rb +10 -14
- data/lib/allq_client/models/multiple_job_response.rb +187 -0
- data/lib/allq_client/models/new_job.rb +14 -18
- data/lib/allq_client/models/new_parent_job.rb +14 -18
- data/lib/allq_client/models/stats_info.rb +8 -12
- data/lib/allq_client/models/stats_results.rb +9 -13
- data/lib/allq_client/models/stats_tube.rb +12 -16
- data/lib/allq_client/models/throttle.rb +9 -13
- data/lib/allq_client/models/tube_ref.rb +7 -11
- data/lib/allq_client/version.rb +2 -2
- data/spec/api/actions_api_spec.rb +414 -12
- data/spec/api/admin_api_spec.rb +0 -0
- data/spec/api_client_spec.rb +0 -0
- data/spec/configuration_spec.rb +0 -0
- data/spec/models/basic_payload_spec.rb +0 -0
- data/spec/models/basic_response_spec.rb +0 -0
- data/spec/models/job_ref_spec.rb +0 -0
- data/spec/models/job_response_spec.rb +0 -0
- data/spec/models/new_job_spec.rb +0 -0
- data/spec/models/new_parent_job_spec.rb +0 -0
- data/spec/models/stats_info_spec.rb +0 -0
- data/spec/models/stats_results_spec.rb +0 -0
- data/spec/models/stats_tube_spec.rb +0 -0
- data/spec/models/throttle_spec.rb +0 -0
- data/spec/models/tube_ref_spec.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +7 -2
@@ -13,6 +13,8 @@ Swagger Codegen version: 2.3.1
|
|
13
13
|
require 'spec_helper'
|
14
14
|
require 'json'
|
15
15
|
|
16
|
+
DEFAULT_TUBE = "default"
|
17
|
+
ALT_TUBE = ""
|
16
18
|
# Unit tests for Allq::ActionsApi
|
17
19
|
# Automatically generated by swagger-codegen (github.com/swagger-api/swagger-codegen)
|
18
20
|
# Please update as you see appropriate
|
@@ -20,6 +22,10 @@ describe 'ActionsApi' do
|
|
20
22
|
before do
|
21
23
|
# run before each test
|
22
24
|
@instance = Allq::ActionsApi.new
|
25
|
+
stats_result = AllQTools::get_stats[0]
|
26
|
+
stats_result.stats.each do |stat|
|
27
|
+
@instance.tube_delete(stat.tube)
|
28
|
+
end
|
23
29
|
end
|
24
30
|
|
25
31
|
after do
|
@@ -40,7 +46,12 @@ describe 'ActionsApi' do
|
|
40
46
|
# @return [BasicResponse]
|
41
47
|
describe 'bury_put test' do
|
42
48
|
it "should work" do
|
43
|
-
|
49
|
+
AllQTools::add_job
|
50
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
51
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
52
|
+
@instance.bury_put(job.id)
|
53
|
+
expect(AllQTools::get_buried(DEFAULT_TUBE)).to eq(1)
|
54
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
44
55
|
end
|
45
56
|
end
|
46
57
|
|
@@ -53,7 +64,11 @@ describe 'ActionsApi' do
|
|
53
64
|
# @return [BasicResponse]
|
54
65
|
describe 'job_delete test' do
|
55
66
|
it "should work" do
|
56
|
-
|
67
|
+
AllQTools::add_job
|
68
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
69
|
+
job = @instance.peek_get(DEFAULT_TUBE)
|
70
|
+
@instance.job_delete(job.id, tube: DEFAULT_TUBE)
|
71
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
57
72
|
end
|
58
73
|
end
|
59
74
|
|
@@ -65,7 +80,31 @@ describe 'ActionsApi' do
|
|
65
80
|
# @return [JobResponse]
|
66
81
|
describe 'job_get test' do
|
67
82
|
it "should work" do
|
68
|
-
|
83
|
+
AllQTools::add_job
|
84
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
85
|
+
expect(AllQTools::get_reserved(DEFAULT_TUBE)).to eq(1)
|
86
|
+
expect(job.id).to be_truthy
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# unit tests for multiple job_get
|
91
|
+
# Job
|
92
|
+
# Get job from queue
|
93
|
+
# @param tube Name of tube
|
94
|
+
# @param [Hash] opts the optional parameters
|
95
|
+
# @return [JobResponse]
|
96
|
+
describe 'mulitple_job_get test' do
|
97
|
+
it "should work" do
|
98
|
+
1.upto(6) do
|
99
|
+
AllQTools::add_job
|
100
|
+
end
|
101
|
+
multiple_jobs = @instance.multiple_job_get(DEFAULT_TUBE, 4)
|
102
|
+
expect(multiple_jobs.jobs.length).to eq(4)
|
103
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(2)
|
104
|
+
|
105
|
+
multiple_jobs = @instance.multiple_job_get(DEFAULT_TUBE, 4)
|
106
|
+
expect(multiple_jobs.jobs.length).to eq(2)
|
107
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
69
108
|
end
|
70
109
|
end
|
71
110
|
|
@@ -77,7 +116,10 @@ describe 'ActionsApi' do
|
|
77
116
|
# @return [JobRef]
|
78
117
|
describe 'job_post test' do
|
79
118
|
it "should work" do
|
80
|
-
|
119
|
+
AllQTools::add_job
|
120
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
121
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
122
|
+
expect(job.id).to be_truthy
|
81
123
|
end
|
82
124
|
end
|
83
125
|
|
@@ -88,8 +130,91 @@ describe 'ActionsApi' do
|
|
88
130
|
# @param [Hash] opts the optional parameters
|
89
131
|
# @return [JobRef]
|
90
132
|
describe 'parent_job_post test' do
|
91
|
-
it "should work" do
|
92
|
-
|
133
|
+
it "should work" do
|
134
|
+
new_parent_job = Allq::NewParentJob.new(tube: 'default',
|
135
|
+
body: '<PARENT_BODY>',
|
136
|
+
ttl: 1200,
|
137
|
+
delay: 0,
|
138
|
+
priority: 5,
|
139
|
+
timeout: 1000,
|
140
|
+
run_on_timeout: false,
|
141
|
+
limit: 2)
|
142
|
+
new_parent_job_response = @instance.parent_job_post(new_parent_job)
|
143
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
144
|
+
job = AllQTools::new_job(DEFAULT_TUBE, nil, new_parent_job_response.job_id)
|
145
|
+
@instance.job_post(job)
|
146
|
+
job = AllQTools::new_job(DEFAULT_TUBE, nil, new_parent_job_response.job_id)
|
147
|
+
@instance.job_post(job)
|
148
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(2)
|
149
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
150
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
151
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
152
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(0)
|
153
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
154
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# unit tests for parent_job_post
|
159
|
+
# Parent Job
|
160
|
+
# Create a parent job
|
161
|
+
# @param new_parent_job New Parent Job Data
|
162
|
+
# @param [Hash] opts the optional parameters
|
163
|
+
# @return [JobRef]
|
164
|
+
describe 'parent_job_post test with different tubes' do
|
165
|
+
it "should work" do
|
166
|
+
new_parent_job = Allq::NewParentJob.new(tube: 'default',
|
167
|
+
body: '<PARENT_BODY>',
|
168
|
+
ttl: 1200,
|
169
|
+
delay: 0,
|
170
|
+
priority: 5,
|
171
|
+
timeout: 1000,
|
172
|
+
run_on_timeout: false,
|
173
|
+
limit: 2)
|
174
|
+
new_parent_job_response = @instance.parent_job_post(new_parent_job)
|
175
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
176
|
+
|
177
|
+
job = AllQTools::new_job('foo', nil, new_parent_job_response.job_id)
|
178
|
+
@instance.job_post(job)
|
179
|
+
job = AllQTools::new_job('foo', nil, new_parent_job_response.job_id)
|
180
|
+
@instance.job_post(job)
|
181
|
+
expect(AllQTools::get_ready('foo')).to eq(2)
|
182
|
+
AllQTools::get_finish('foo')
|
183
|
+
AllQTools::get_finish('foo')
|
184
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
185
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(0)
|
186
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
187
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
# unit tests for parent_job_post
|
192
|
+
# Parent Job
|
193
|
+
# Create a parent job
|
194
|
+
# @param new_parent_job New Parent Job Data
|
195
|
+
# @param [Hash] opts the optional parameters
|
196
|
+
# @return [JobRef]
|
197
|
+
describe 'parent_job_post should timeout if child not completed in time' do
|
198
|
+
fit "should work" do
|
199
|
+
new_parent_job = Allq::NewParentJob.new(tube: 'default',
|
200
|
+
body: '<PARENT_BODY>',
|
201
|
+
ttl: 1200,
|
202
|
+
delay: 0,
|
203
|
+
priority: 5,
|
204
|
+
timeout: 2,
|
205
|
+
run_on_timeout: true,
|
206
|
+
limit: 2)
|
207
|
+
new_parent_job_response = @instance.parent_job_post(new_parent_job)
|
208
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
209
|
+
|
210
|
+
job = AllQTools::new_job('foo', nil, new_parent_job_response.job_id)
|
211
|
+
@instance.job_post(job)
|
212
|
+
expect(AllQTools::get_ready('foo')).to eq(1)
|
213
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
214
|
+
|
215
|
+
sleep(7)
|
216
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(0)
|
217
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
93
218
|
end
|
94
219
|
end
|
95
220
|
|
@@ -102,7 +227,36 @@ describe 'ActionsApi' do
|
|
102
227
|
# @return [JobResponse]
|
103
228
|
describe 'peek_get test' do
|
104
229
|
it "should work" do
|
105
|
-
|
230
|
+
AllQTools::add_job
|
231
|
+
job = @instance.peek_get(DEFAULT_TUBE)
|
232
|
+
expect(job.id).to be_truthy
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'peek_get buried test' do
|
237
|
+
it "should work" do
|
238
|
+
AllQTools::add_job
|
239
|
+
job = @instance.peek_get(DEFAULT_TUBE, buried: true)
|
240
|
+
expect(job.id).to be_falsey
|
241
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
242
|
+
@instance.bury_put(job.id)
|
243
|
+
job = @instance.peek_get(DEFAULT_TUBE, buried: true)
|
244
|
+
expect(job.id).to be_truthy
|
245
|
+
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
# unit tests for peek_get
|
250
|
+
# Peek
|
251
|
+
# Peek at next job
|
252
|
+
# @param tube Tube name
|
253
|
+
# @param [Hash] opts the optional parameters
|
254
|
+
# @option opts [String] :buried Look in buried
|
255
|
+
# @return [JobResponse]
|
256
|
+
describe 'peek_get test(no jobs)' do
|
257
|
+
it "should work" do
|
258
|
+
job = @instance.peek_get(DEFAULT_TUBE)
|
259
|
+
expect(job.id).to be_falsey
|
106
260
|
end
|
107
261
|
end
|
108
262
|
|
@@ -114,7 +268,31 @@ describe 'ActionsApi' do
|
|
114
268
|
# @return [BasicResponse]
|
115
269
|
describe 'release_put test' do
|
116
270
|
it "should work" do
|
117
|
-
|
271
|
+
AllQTools::add_job
|
272
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
273
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
274
|
+
expect(AllQTools::get_reserved(DEFAULT_TUBE)).to eq(1)
|
275
|
+
expect(job.id).to be_truthy
|
276
|
+
@instance.release_put(job.id)
|
277
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
describe 'release should increment release' do
|
282
|
+
it "should work" do
|
283
|
+
AllQTools::add_job
|
284
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
285
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
286
|
+
expect(job.releases).to eq(0)
|
287
|
+
@instance.release_put(job.id)
|
288
|
+
sleep(1)
|
289
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
290
|
+
expect(job.releases).to eq(1)
|
291
|
+
@instance.release_put(job.id)
|
292
|
+
sleep(1)
|
293
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
294
|
+
expect(job.releases).to eq(2)
|
295
|
+
|
118
296
|
end
|
119
297
|
end
|
120
298
|
|
@@ -126,7 +304,34 @@ describe 'ActionsApi' do
|
|
126
304
|
# @return [BasicResponse]
|
127
305
|
describe 'set_children_started_put test' do
|
128
306
|
it "should work" do
|
129
|
-
|
307
|
+
new_parent_job = Allq::NewParentJob.new(tube: 'default',
|
308
|
+
body: '<PARENT_BODY>',
|
309
|
+
ttl: 1200,
|
310
|
+
delay: 0,
|
311
|
+
priority: 5,
|
312
|
+
timeout: 1000,
|
313
|
+
run_on_timeout: false,
|
314
|
+
limit: nil)
|
315
|
+
new_parent_job_response = @instance.parent_job_post(new_parent_job)
|
316
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
317
|
+
job = AllQTools::new_job(DEFAULT_TUBE, nil, new_parent_job_response.job_id)
|
318
|
+
@instance.job_post(job)
|
319
|
+
job = AllQTools::new_job(DEFAULT_TUBE, nil, new_parent_job_response.job_id)
|
320
|
+
@instance.job_post(job)
|
321
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(2)
|
322
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
323
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
324
|
+
# After jobs have already finished
|
325
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
326
|
+
# Parent still waiting
|
327
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(1)
|
328
|
+
# Set limit on parent
|
329
|
+
@instance.set_children_started_put(new_parent_job_response.job_id)
|
330
|
+
# Now parent gets moved to ready
|
331
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
332
|
+
expect(AllQTools::get_parents(DEFAULT_TUBE)).to eq(0)
|
333
|
+
AllQTools::get_finish(DEFAULT_TUBE)
|
334
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0)
|
130
335
|
end
|
131
336
|
end
|
132
337
|
|
@@ -138,7 +343,24 @@ describe 'ActionsApi' do
|
|
138
343
|
# @return [TubeRef]
|
139
344
|
describe 'throttle_post test' do
|
140
345
|
it "should work" do
|
141
|
-
|
346
|
+
throttle = Allq::Throttle.new(tps: 5, tube: "throttled")
|
347
|
+
@instance.throttle_post(throttle)
|
348
|
+
end
|
349
|
+
end
|
350
|
+
|
351
|
+
# unit tests for stats
|
352
|
+
# Stats Action Count
|
353
|
+
# Checks action count
|
354
|
+
# @param throttle Throttle info
|
355
|
+
# @param [Hash] opts the optional parameters
|
356
|
+
# @return [TubeRef]
|
357
|
+
describe 'throttle_post test' do
|
358
|
+
it "should work" do
|
359
|
+
AllQTools::add_job
|
360
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
361
|
+
@instance.job_get(DEFAULT_TUBE)
|
362
|
+
stats_result = AllQTools::get_stats[0]
|
363
|
+
expect(stats_result.action_count > 1).to eq(true)
|
142
364
|
end
|
143
365
|
end
|
144
366
|
|
@@ -150,7 +372,10 @@ describe 'ActionsApi' do
|
|
150
372
|
# @return [BasicResponse]
|
151
373
|
describe 'touch_put test' do
|
152
374
|
it "should work" do
|
153
|
-
|
375
|
+
AllQTools::add_job
|
376
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1)
|
377
|
+
job = @instance.job_get(DEFAULT_TUBE)
|
378
|
+
@instance.touch_put(job.id)
|
154
379
|
end
|
155
380
|
end
|
156
381
|
|
@@ -162,8 +387,185 @@ describe 'ActionsApi' do
|
|
162
387
|
# @return [BasicResponse]
|
163
388
|
describe 'tube_delete test' do
|
164
389
|
it "should work" do
|
165
|
-
|
390
|
+
alt_tube_name = "alt_tube"
|
391
|
+
new_job = Allq::NewJob.new(tube: alt_tube_name,
|
392
|
+
body: "Some body",
|
393
|
+
ttl: 1200,
|
394
|
+
delay: 0,
|
395
|
+
priority: 5,
|
396
|
+
parent_id: nil)
|
397
|
+
@instance.job_post(new_job)
|
398
|
+
new_job = Allq::NewJob.new(tube: alt_tube_name,
|
399
|
+
body: "Some body",
|
400
|
+
ttl: 1200,
|
401
|
+
delay: 0,
|
402
|
+
priority: 5,
|
403
|
+
parent_id: nil)
|
404
|
+
@instance.job_post(new_job)
|
405
|
+
new_job = Allq::NewJob.new(tube: alt_tube_name,
|
406
|
+
body: "Some body",
|
407
|
+
ttl: 1200,
|
408
|
+
delay: 0,
|
409
|
+
priority: 5,
|
410
|
+
parent_id: nil)
|
411
|
+
@instance.job_post(new_job)
|
412
|
+
new_job = Allq::NewJob.new(tube: "alt_tube2",
|
413
|
+
body: "Some body",
|
414
|
+
ttl: 1200,
|
415
|
+
delay: 0,
|
416
|
+
priority: 5,
|
417
|
+
parent_id: nil)
|
418
|
+
@instance.job_post(new_job)
|
419
|
+
new_job = Allq::NewJob.new(tube: "alt_tube2",
|
420
|
+
body: "Some body",
|
421
|
+
ttl: 1200,
|
422
|
+
delay: 0,
|
423
|
+
priority: 5,
|
424
|
+
parent_id: nil)
|
425
|
+
@instance.job_post(new_job)
|
426
|
+
expect(AllQTools::get_ready("alt_tube2")).to eq(2) # OK..it's there
|
427
|
+
reserved_job = @instance.job_get("alt_tube2")
|
428
|
+
|
429
|
+
# Other tube has 1 ready, 1 reserved
|
430
|
+
expect(AllQTools::get_ready("alt_tube2")).to eq(1)
|
431
|
+
expect(AllQTools::get_reserved("alt_tube2")).to eq(1)
|
432
|
+
|
433
|
+
# Get 1 into buried, 1 into reserved, and 1 in ready so we can clear it
|
434
|
+
expect(AllQTools::get_ready(alt_tube_name)).to eq(3) # OK..it's there
|
435
|
+
reserved_job = @instance.job_get(alt_tube_name)
|
436
|
+
expect(AllQTools::get_reserved(alt_tube_name)).to eq(1) # OK..it's there
|
437
|
+
reserved_job = @instance.job_get(alt_tube_name)
|
438
|
+
expect(AllQTools::get_reserved(alt_tube_name)).to eq(2) # OK..it's there
|
439
|
+
@instance.bury_put(reserved_job.id)
|
440
|
+
expect(AllQTools::get_buried(alt_tube_name)).to eq(1)
|
441
|
+
|
442
|
+
# Now check that first tube is empty
|
443
|
+
@instance.tube_delete(alt_tube_name)
|
444
|
+
expect(AllQTools::get_buried(alt_tube_name)).to eq(0)
|
445
|
+
expect(AllQTools::get_reserved(alt_tube_name)).to eq(0) # OK..it's there
|
446
|
+
expect(AllQTools::get_ready(alt_tube_name)).to eq(0)
|
447
|
+
|
448
|
+
# ..and other tubes are fine
|
449
|
+
expect(AllQTools::get_ready("alt_tube2")).to eq(1)
|
450
|
+
expect(AllQTools::get_reserved("alt_tube2")).to eq(1)
|
166
451
|
end
|
167
452
|
end
|
168
453
|
|
454
|
+
# unit tests for delay
|
455
|
+
# Delay
|
456
|
+
describe 'delay test' do
|
457
|
+
it "should work" do
|
458
|
+
new_job = Allq::NewJob.new(tube: DEFAULT_TUBE,
|
459
|
+
body: "Some body",
|
460
|
+
ttl: 1200,
|
461
|
+
delay: 1,
|
462
|
+
priority: 5,
|
463
|
+
parent_id: nil)
|
464
|
+
@instance.job_post(new_job)
|
465
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(0) # Too soon to show up
|
466
|
+
sleep(4)
|
467
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1) # OK..it's there
|
468
|
+
end
|
469
|
+
end
|
470
|
+
|
471
|
+
# unit tests for expire
|
472
|
+
# Expire
|
473
|
+
describe 'expire test' do
|
474
|
+
it "should work" do
|
475
|
+
new_job = Allq::NewJob.new(tube: DEFAULT_TUBE,
|
476
|
+
body: "Some body",
|
477
|
+
ttl: 1,
|
478
|
+
delay: 0,
|
479
|
+
priority: 5,
|
480
|
+
parent_id: nil)
|
481
|
+
@instance.job_post(new_job)
|
482
|
+
sleep(1)
|
483
|
+
@instance.job_get(DEFAULT_TUBE)
|
484
|
+
expect(AllQTools::get_reserved(DEFAULT_TUBE)).to eq(1)
|
485
|
+
sleep(5)
|
486
|
+
expect(AllQTools::get_reserved(DEFAULT_TUBE)).to eq(0) # Should expire
|
487
|
+
expect(AllQTools::get_ready(DEFAULT_TUBE)).to eq(1) # ..and be back in ready
|
488
|
+
end
|
489
|
+
end
|
490
|
+
|
491
|
+
end
|
492
|
+
|
493
|
+
|
494
|
+
module AllQTools
|
495
|
+
class << self
|
496
|
+
|
497
|
+
def new_job(tube = 'default', body = nil, parent_id = nil)
|
498
|
+
body = (0...8).map { (65 + rand(26)).chr }.join unless body
|
499
|
+
|
500
|
+
new_job = Allq::NewJob.new(tube: tube,
|
501
|
+
body: body,
|
502
|
+
ttl: 1200,
|
503
|
+
delay: 0,
|
504
|
+
priority: 5,
|
505
|
+
parent_id:parent_id)
|
506
|
+
return new_job
|
507
|
+
end
|
508
|
+
|
509
|
+
def add_job(tube = DEFAULT_TUBE)
|
510
|
+
client = Allq::ActionsApi.new
|
511
|
+
job = new_job(tube)
|
512
|
+
job = client.job_post(new_job)
|
513
|
+
return job
|
514
|
+
end
|
515
|
+
|
516
|
+
def get_finish(tube)
|
517
|
+
client = Allq::ActionsApi.new
|
518
|
+
job = client.job_get(tube)
|
519
|
+
client.job_delete(job.id)
|
520
|
+
end
|
521
|
+
|
522
|
+
def get_stats
|
523
|
+
client = Allq::AdminApi.new
|
524
|
+
client.stats_get
|
525
|
+
end
|
526
|
+
|
527
|
+
def get_ready(tube)
|
528
|
+
stats = get_stats
|
529
|
+
count = 0
|
530
|
+
find_tueq(stats, tube) do |found_stat|
|
531
|
+
count += found_stat.ready.to_i
|
532
|
+
end
|
533
|
+
return count
|
534
|
+
end
|
535
|
+
|
536
|
+
def get_reserved(tube)
|
537
|
+
stats = get_stats
|
538
|
+
count = 0
|
539
|
+
find_tueq(stats, tube) do |found_stat|
|
540
|
+
count += found_stat.reserved.to_i
|
541
|
+
end
|
542
|
+
return count
|
543
|
+
end
|
544
|
+
|
545
|
+
def get_buried(tube)
|
546
|
+
stats = get_stats
|
547
|
+
count = 0
|
548
|
+
find_tueq(stats, tube) do |found_stat|
|
549
|
+
count += found_stat.buried.to_i
|
550
|
+
end
|
551
|
+
return count
|
552
|
+
end
|
553
|
+
|
554
|
+
def get_parents(tube)
|
555
|
+
stats = get_stats
|
556
|
+
count = 0
|
557
|
+
find_tueq(stats, tube) do |found_stat|
|
558
|
+
count += found_stat.parents.to_i
|
559
|
+
end
|
560
|
+
return count
|
561
|
+
end
|
562
|
+
|
563
|
+
def find_tueq(all_stats, tube)
|
564
|
+
all_stats.each do |server_stat|
|
565
|
+
server_stat.stats.each do |stat|
|
566
|
+
yield stat if stat.tube == tube
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
169
571
|
end
|