batsir 0.1.0 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +9 -1
- data/CHANGES.md +54 -0
- data/Gemfile +7 -10
- data/README.md +49 -5
- data/Rakefile +23 -16
- data/batsir.gemspec +43 -15
- data/lib/batsir/acceptors/acceptor.rb +31 -5
- data/lib/batsir/acceptors/amqp_acceptor.rb +36 -8
- data/lib/batsir/amqp.rb +35 -7
- data/lib/batsir/amqp_consumer.rb +8 -0
- data/lib/batsir/compiler/stage_worker_compiler.rb +86 -0
- data/lib/batsir/config.rb +208 -24
- data/lib/batsir/dsl/conditional_notifier_declaration.rb +31 -0
- data/lib/batsir/dsl/dsl_mappings.rb +27 -2
- data/lib/batsir/errors.rb +18 -0
- data/lib/batsir/filter.rb +5 -0
- data/lib/batsir/log.rb +7 -0
- data/lib/batsir/logger.rb +37 -0
- data/lib/batsir/logo.rb +3 -8
- data/lib/batsir/notifiers/amqp_notifier.rb +14 -4
- data/lib/batsir/notifiers/conditional_notifier.rb +29 -0
- data/lib/batsir/notifiers/notifier.rb +6 -5
- data/lib/batsir/registry.rb +6 -2
- data/lib/batsir/stage.rb +9 -4
- data/lib/batsir/stage_worker.rb +3 -56
- data/lib/batsir/strategies/retry_strategy.rb +35 -0
- data/lib/batsir/strategies/strategy.rb +20 -0
- data/lib/batsir/transformers/field_transformer.rb +2 -3
- data/lib/batsir/transformers/json_input_transformer.rb +6 -2
- data/lib/batsir/transformers/json_output_transformer.rb +6 -2
- data/lib/batsir/transformers/transformer.rb +5 -1
- data/lib/batsir/version.rb +10 -0
- data/lib/batsir.rb +31 -13
- data/spec/batsir/acceptors/acceptor_spec.rb +7 -78
- data/spec/batsir/acceptors/amqp_acceptor_spec.rb +55 -66
- data/spec/batsir/acceptors/shared_examples.rb +102 -0
- data/spec/batsir/amqp_spec.rb +58 -0
- data/spec/batsir/chain_spec.rb +4 -4
- data/spec/batsir/config_spec.rb +97 -0
- data/spec/batsir/dsl/chain_mapping_spec.rb +5 -6
- data/spec/batsir/dsl/conditional_notifier_mapping_spec.rb +80 -0
- data/spec/batsir/dsl/stage_mapping_spec.rb +38 -20
- data/spec/batsir/filter_queue_spec.rb +9 -15
- data/spec/batsir/filter_spec.rb +4 -5
- data/spec/batsir/log_spec.rb +10 -0
- data/spec/batsir/logger_spec.rb +46 -0
- data/spec/batsir/notifiers/amqp_notifier_spec.rb +43 -22
- data/spec/batsir/notifiers/conditional_notifier_spec.rb +62 -0
- data/spec/batsir/notifiers/notifier_spec.rb +4 -66
- data/spec/batsir/notifiers/shared_examples.rb +100 -0
- data/spec/batsir/registry_spec.rb +48 -0
- data/spec/batsir/stage_spec.rb +91 -85
- data/spec/batsir/stage_worker_spec.rb +13 -13
- data/spec/batsir/strategies/retry_strategy_spec.rb +58 -0
- data/spec/batsir/strategies/strategy_spec.rb +28 -0
- data/spec/batsir/support/bunny_mocks.rb +78 -5
- data/spec/batsir/transformers/field_transformer_spec.rb +22 -22
- data/spec/batsir/transformers/json_input_transformer_spec.rb +8 -3
- data/spec/batsir/transformers/json_output_transformer_spec.rb +2 -2
- data/spec/batsir/transformers/transformer_spec.rb +18 -4
- data/spec/spec_helper.rb +6 -2
- metadata +78 -23
- data/VERSION +0 -1
data/spec/batsir/stage_spec.rb
CHANGED
@@ -19,36 +19,36 @@ describe Batsir::Stage do
|
|
19
19
|
@object_type = "SomeResource"
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
22
|
+
it "is a Celluloid Actor" do
|
23
23
|
Batsir::Stage.ancestors.should include Celluloid
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "can name the stage" do
|
27
27
|
stage = Batsir::Stage.new
|
28
28
|
name = "StageName"
|
29
29
|
stage.name = name
|
30
30
|
stage.name.should == name
|
31
31
|
end
|
32
32
|
|
33
|
-
it "
|
33
|
+
it "can set the name in the constructor" do
|
34
34
|
name = "StageName"
|
35
35
|
stage = Batsir::Stage.new(:name => name)
|
36
36
|
stage.name.should == name
|
37
37
|
end
|
38
38
|
|
39
|
-
it "
|
39
|
+
it "can set the aggregator chain to which the stage belongs" do
|
40
40
|
chain = "Chain"
|
41
41
|
stage = Batsir::Stage.new(:chain => chain)
|
42
42
|
stage.chain.should == chain
|
43
43
|
end
|
44
44
|
|
45
|
-
context "
|
46
|
-
it "
|
45
|
+
context "with respect to filters" do
|
46
|
+
it "cannot set the filters directly" do
|
47
47
|
stage = Batsir::Stage.new
|
48
48
|
lambda { stage.filters = {} }.should raise_error(NoMethodError)
|
49
49
|
end
|
50
50
|
|
51
|
-
it "
|
51
|
+
it "stores filters using filter declarations" do
|
52
52
|
filter = "Filter"
|
53
53
|
stage = Batsir::Stage.new
|
54
54
|
stage.add_filter(filter)
|
@@ -59,13 +59,13 @@ describe Batsir::Stage do
|
|
59
59
|
declaration.options.should == {}
|
60
60
|
end
|
61
61
|
|
62
|
-
it "
|
62
|
+
it "returns an empty array when the #filters method is called without any declared filters" do
|
63
63
|
stage = Batsir::Stage.new
|
64
64
|
stage.filters.should_not be_nil
|
65
65
|
stage.filters.should == []
|
66
66
|
end
|
67
67
|
|
68
|
-
it "
|
68
|
+
it "returns all filters when the #filters method is called" do
|
69
69
|
filter1 = "Filter"
|
70
70
|
filter2 = "Filter2"
|
71
71
|
filter3 = "Filter"
|
@@ -81,7 +81,7 @@ describe Batsir::Stage do
|
|
81
81
|
stage.filters[2].should == filter3
|
82
82
|
end
|
83
83
|
|
84
|
-
it "
|
84
|
+
it "adds a filter to its filters" do
|
85
85
|
filter = "Filter"
|
86
86
|
stage = Batsir::Stage.new
|
87
87
|
stage.add_filter(filter)
|
@@ -89,7 +89,7 @@ describe Batsir::Stage do
|
|
89
89
|
stage.filters.should include filter
|
90
90
|
end
|
91
91
|
|
92
|
-
it "
|
92
|
+
it "can have multiple filters of the same class but with different options" do
|
93
93
|
stage = Batsir::Stage.new
|
94
94
|
stage.add_filter(:filter)
|
95
95
|
stage.add_filter(:filter, :foo => :bar)
|
@@ -98,7 +98,7 @@ describe Batsir::Stage do
|
|
98
98
|
stage.filters.size.should == 2
|
99
99
|
end
|
100
100
|
|
101
|
-
it "
|
101
|
+
it "can add filters with on options hash" do
|
102
102
|
filter = :filter
|
103
103
|
options = {:foo => :bar}
|
104
104
|
|
@@ -111,7 +111,7 @@ describe Batsir::Stage do
|
|
111
111
|
stage.filter_declarations.first.options.should == options
|
112
112
|
end
|
113
113
|
|
114
|
-
it "
|
114
|
+
it "can add multiple filters with option hashes" do
|
115
115
|
filter1 = :filter1
|
116
116
|
filter2 = :filter2
|
117
117
|
options1 = {:foo1 => :bar1}
|
@@ -127,7 +127,7 @@ describe Batsir::Stage do
|
|
127
127
|
stage.filter_declarations[1].options.should == options2
|
128
128
|
end
|
129
129
|
|
130
|
-
it "
|
130
|
+
it "adds empty options hashes to filters when no option hash is given" do
|
131
131
|
filter = :filter
|
132
132
|
|
133
133
|
stage = Batsir::Stage.new
|
@@ -139,7 +139,7 @@ describe Batsir::Stage do
|
|
139
139
|
stage.filter_declarations.first.options.should == {}
|
140
140
|
end
|
141
141
|
|
142
|
-
it "
|
142
|
+
it "can add a filter more than once" do
|
143
143
|
filter = :filter
|
144
144
|
stage = Batsir::Stage.new
|
145
145
|
stage.add_filter(filter)
|
@@ -149,7 +149,7 @@ describe Batsir::Stage do
|
|
149
149
|
stage.filters.size.should == 2
|
150
150
|
end
|
151
151
|
|
152
|
-
it "
|
152
|
+
it "can add filter with different options and respect the order" do
|
153
153
|
filter = :filter
|
154
154
|
other_filter = :other_filter
|
155
155
|
|
@@ -161,19 +161,19 @@ describe Batsir::Stage do
|
|
161
161
|
end
|
162
162
|
end
|
163
163
|
|
164
|
-
context "
|
165
|
-
it "
|
164
|
+
context "with respect to acceptors" do
|
165
|
+
it "initially has an empty list of acceptors" do
|
166
166
|
stage = Batsir::Stage.new
|
167
167
|
stage.acceptors.should_not be_nil
|
168
168
|
stage.acceptors.should be_empty
|
169
169
|
end
|
170
170
|
|
171
|
-
it "
|
171
|
+
it "cannot set the acceptors directly" do
|
172
172
|
stage = Batsir::Stage.new
|
173
173
|
lambda { stage.acceptors = {} }.should raise_error(NoMethodError)
|
174
174
|
end
|
175
175
|
|
176
|
-
it "
|
176
|
+
it "can add new acceptors" do
|
177
177
|
stage = Batsir::Stage.new
|
178
178
|
stage.add_acceptor(:acceptor)
|
179
179
|
stage.acceptors.should_not be_nil
|
@@ -181,13 +181,13 @@ describe Batsir::Stage do
|
|
181
181
|
stage.acceptors.keys.should include :acceptor
|
182
182
|
end
|
183
183
|
|
184
|
-
it "
|
184
|
+
it "stores a set of different options for each acceptor" do
|
185
185
|
stage = Batsir::Stage.new
|
186
186
|
stage.add_acceptor(:acceptor)
|
187
187
|
stage.acceptors[:acceptor].should be_a Set
|
188
188
|
end
|
189
189
|
|
190
|
-
it "
|
190
|
+
it "can have multiple acceptors of the same class but with different options" do
|
191
191
|
stage = Batsir::Stage.new
|
192
192
|
stage.add_acceptor(:acceptor_class)
|
193
193
|
stage.add_acceptor(:acceptor_class, :foo => :bar)
|
@@ -198,7 +198,7 @@ describe Batsir::Stage do
|
|
198
198
|
stage.acceptors[:acceptor_class].size.should == 2
|
199
199
|
end
|
200
200
|
|
201
|
-
it "
|
201
|
+
it "can add an acceptor with an options hash" do
|
202
202
|
stage = Batsir::Stage.new
|
203
203
|
options = {:foo => :bar}
|
204
204
|
stage.add_acceptor(:acceptor, options)
|
@@ -209,7 +209,7 @@ describe Batsir::Stage do
|
|
209
209
|
stage.acceptors[:acceptor].first.should == options
|
210
210
|
end
|
211
211
|
|
212
|
-
it "
|
212
|
+
it "adds an empty options hash for added acceptors without options" do
|
213
213
|
stage = Batsir::Stage.new
|
214
214
|
stage.add_acceptor(:acceptor)
|
215
215
|
|
@@ -219,21 +219,21 @@ describe Batsir::Stage do
|
|
219
219
|
stage.acceptors[:acceptor].first.should == {}
|
220
220
|
end
|
221
221
|
|
222
|
-
it "
|
222
|
+
it "initially has an empty list of cancellators" do
|
223
223
|
stage = Batsir::Stage.new
|
224
224
|
stage.cancellators.should_not be_nil
|
225
225
|
stage.cancellators.should be_empty
|
226
226
|
end
|
227
227
|
|
228
228
|
context "with respect to acceptor transformers" do
|
229
|
-
it "
|
229
|
+
it "has an empty acceptor transformers queue by default" do
|
230
230
|
stage = Batsir::Stage.new
|
231
231
|
|
232
232
|
stage.acceptor_transformers.should_not be_nil
|
233
233
|
stage.acceptor_transformers.should be_empty
|
234
234
|
end
|
235
235
|
|
236
|
-
it "
|
236
|
+
it "can add a transformer to the acceptors" do
|
237
237
|
stage = Batsir::Stage.new
|
238
238
|
|
239
239
|
transformer = :transformer
|
@@ -244,7 +244,7 @@ describe Batsir::Stage do
|
|
244
244
|
stage.acceptor_transformers.first.transformer.should == transformer
|
245
245
|
end
|
246
246
|
|
247
|
-
it "
|
247
|
+
it "adds an empty options hash by default" do
|
248
248
|
stage = Batsir::Stage.new
|
249
249
|
|
250
250
|
transformer = :transformer
|
@@ -254,7 +254,7 @@ describe Batsir::Stage do
|
|
254
254
|
stage.acceptor_transformers.first.options.should == {}
|
255
255
|
end
|
256
256
|
|
257
|
-
it "
|
257
|
+
it "can add options to a transformer" do
|
258
258
|
stage = Batsir::Stage.new
|
259
259
|
|
260
260
|
transformer = :transformer
|
@@ -267,7 +267,7 @@ describe Batsir::Stage do
|
|
267
267
|
stage.acceptor_transformers.first.options.should == options
|
268
268
|
end
|
269
269
|
|
270
|
-
it "
|
270
|
+
it "can add multiple transformers" do
|
271
271
|
stage = Batsir::Stage.new
|
272
272
|
|
273
273
|
transformer1 = :transformer1
|
@@ -283,7 +283,7 @@ describe Batsir::Stage do
|
|
283
283
|
transformers.should include transformer2
|
284
284
|
end
|
285
285
|
|
286
|
-
it "
|
286
|
+
it "keeps the transformers in the order of declaration" do
|
287
287
|
stage = Batsir::Stage.new
|
288
288
|
|
289
289
|
transformer1 = :transformer1
|
@@ -298,7 +298,7 @@ describe Batsir::Stage do
|
|
298
298
|
stage.acceptor_transformers.last.transformer.should == transformer2
|
299
299
|
end
|
300
300
|
|
301
|
-
it "
|
301
|
+
it "can add a transformer more than once" do
|
302
302
|
stage = Batsir::Stage.new
|
303
303
|
|
304
304
|
transformer = :transformer
|
@@ -312,22 +312,22 @@ describe Batsir::Stage do
|
|
312
312
|
stage.acceptor_transformers.last.transformer.should == transformer
|
313
313
|
end
|
314
314
|
end
|
315
|
-
|
316
315
|
end
|
317
316
|
|
318
|
-
|
319
|
-
|
317
|
+
|
318
|
+
context "with respect to notifiers" do
|
319
|
+
it "initially has an empty notifiers queue" do
|
320
320
|
stage = Batsir::Stage.new
|
321
321
|
stage.notifiers.should_not be_nil
|
322
322
|
stage.notifiers.should be_empty
|
323
323
|
end
|
324
324
|
|
325
|
-
it "
|
325
|
+
it "cannot set the notifiers directly" do
|
326
326
|
stage = Batsir::Stage.new
|
327
327
|
lambda { stage.notifiers = {} }.should raise_error(NoMethodError)
|
328
328
|
end
|
329
329
|
|
330
|
-
it "
|
330
|
+
it "can add new notifiers" do
|
331
331
|
stage = Batsir::Stage.new
|
332
332
|
|
333
333
|
stage.add_notifier(:notifier)
|
@@ -336,13 +336,13 @@ describe Batsir::Stage do
|
|
336
336
|
stage.notifiers.keys.should include :notifier
|
337
337
|
end
|
338
338
|
|
339
|
-
it "
|
339
|
+
it "stores a set of different options for each notifier" do
|
340
340
|
stage = Batsir::Stage.new
|
341
341
|
stage.add_notifier(:notifier)
|
342
342
|
stage.notifiers[:notifier].should be_a Set
|
343
343
|
end
|
344
344
|
|
345
|
-
it "
|
345
|
+
it "can have multiple notifiers of the same class but with different options" do
|
346
346
|
stage = Batsir::Stage.new
|
347
347
|
stage.add_notifier(:notifier_class)
|
348
348
|
stage.add_notifier(:notifier_class, :foo => :bar)
|
@@ -352,7 +352,7 @@ describe Batsir::Stage do
|
|
352
352
|
stage.notifiers[:notifier_class].size.should == 2
|
353
353
|
end
|
354
354
|
|
355
|
-
it "
|
355
|
+
it "can set a notifier with an options hash" do
|
356
356
|
stage = Batsir::Stage.new
|
357
357
|
|
358
358
|
options = {:foo => :bar}
|
@@ -364,7 +364,7 @@ describe Batsir::Stage do
|
|
364
364
|
stage.notifiers[:notifier].first.should == options
|
365
365
|
end
|
366
366
|
|
367
|
-
it "
|
367
|
+
it "adds an empty options hash for added notifiers without options" do
|
368
368
|
stage = Batsir::Stage.new
|
369
369
|
|
370
370
|
stage.add_notifier(:notifier)
|
@@ -375,14 +375,14 @@ describe Batsir::Stage do
|
|
375
375
|
end
|
376
376
|
|
377
377
|
context "with respect to notifier transformers" do
|
378
|
-
it "
|
378
|
+
it "has an empty notifier transformers queue by default" do
|
379
379
|
stage = Batsir::Stage.new
|
380
380
|
|
381
381
|
stage.notifier_transformers.should_not be_nil
|
382
382
|
stage.notifier_transformers.should be_empty
|
383
383
|
end
|
384
384
|
|
385
|
-
it "
|
385
|
+
it "can add a transformer to the notifiers" do
|
386
386
|
stage = Batsir::Stage.new
|
387
387
|
|
388
388
|
transformer = :transformer
|
@@ -393,7 +393,7 @@ describe Batsir::Stage do
|
|
393
393
|
stage.notifier_transformers.first.transformer.should == transformer
|
394
394
|
end
|
395
395
|
|
396
|
-
it "
|
396
|
+
it "adds an empty options hash by default" do
|
397
397
|
stage = Batsir::Stage.new
|
398
398
|
|
399
399
|
transformer = :transformer
|
@@ -403,7 +403,7 @@ describe Batsir::Stage do
|
|
403
403
|
stage.notifier_transformers.first.options.should == {}
|
404
404
|
end
|
405
405
|
|
406
|
-
it "
|
406
|
+
it "can add options to a transformer" do
|
407
407
|
stage = Batsir::Stage.new
|
408
408
|
|
409
409
|
transformer = :transformer
|
@@ -416,7 +416,7 @@ describe Batsir::Stage do
|
|
416
416
|
stage.notifier_transformers.first.options.should == options
|
417
417
|
end
|
418
418
|
|
419
|
-
it "
|
419
|
+
it "can add multiple transformers" do
|
420
420
|
stage = Batsir::Stage.new
|
421
421
|
|
422
422
|
transformer1 = :transformer1
|
@@ -432,7 +432,7 @@ describe Batsir::Stage do
|
|
432
432
|
transformers.should include transformer2
|
433
433
|
end
|
434
434
|
|
435
|
-
it "
|
435
|
+
it "keeps the transformers in the order of declaration" do
|
436
436
|
stage = Batsir::Stage.new
|
437
437
|
|
438
438
|
transformer1 = :transformer1
|
@@ -447,7 +447,7 @@ describe Batsir::Stage do
|
|
447
447
|
stage.notifier_transformers.last.transformer.should == transformer2
|
448
448
|
end
|
449
449
|
|
450
|
-
it "
|
450
|
+
it "can add a transformer more than once" do
|
451
451
|
stage = Batsir::Stage.new
|
452
452
|
|
453
453
|
transformer = :transformer
|
@@ -463,10 +463,33 @@ describe Batsir::Stage do
|
|
463
463
|
end
|
464
464
|
end
|
465
465
|
|
466
|
+
context "with respect to conditional notifiers" do
|
467
|
+
it "initially has an empty conditional notifiers queue" do
|
468
|
+
stage = Batsir::Stage.new
|
469
|
+
stage.conditional_notifiers.should_not be_nil
|
470
|
+
stage.conditional_notifiers.should be_empty
|
471
|
+
end
|
472
|
+
|
473
|
+
it "cannot set the conditional notifiers directly" do
|
474
|
+
stage = Batsir::Stage.new
|
475
|
+
lambda { stage.conditional_notifiers = {} }.should raise_error(NoMethodError)
|
476
|
+
end
|
477
|
+
|
478
|
+
it "can add new conditional notifiers" do
|
479
|
+
stage = Batsir::Stage.new
|
480
|
+
|
481
|
+
stage.add_conditional_notifier(:notifier)
|
482
|
+
stage.conditional_notifiers.should_not be_nil
|
483
|
+
stage.conditional_notifiers.should_not be_empty
|
484
|
+
end
|
485
|
+
end
|
486
|
+
|
466
487
|
context "with respect to compiling the stage" do
|
467
488
|
before :all do
|
468
489
|
@stage_name = "Stage 1"
|
469
490
|
|
491
|
+
Celluloid.boot
|
492
|
+
|
470
493
|
stage = Batsir::Stage.new(:name => @stage_name)
|
471
494
|
|
472
495
|
stage.add_notifier_transformer(Batsir::Transformers::Transformer)
|
@@ -477,23 +500,23 @@ describe Batsir::Stage do
|
|
477
500
|
@created_class = eval( stage.compile )
|
478
501
|
end
|
479
502
|
|
480
|
-
it "
|
503
|
+
it "creates a class named after the stage name" do
|
481
504
|
@created_class.to_s.should == "Stage1Worker"
|
482
505
|
end
|
483
506
|
|
484
|
-
it "
|
507
|
+
it "creates a Batsir::StageWorker class" do
|
485
508
|
@created_class.ancestors.should include Batsir::StageWorker
|
486
509
|
end
|
487
510
|
|
488
|
-
it "
|
511
|
+
it "creates a class that includes Sidekiq::Worker" do
|
489
512
|
@created_class.ancestors.should include Sidekiq::Worker
|
490
513
|
end
|
491
514
|
|
492
|
-
it "
|
515
|
+
it "creates a worker class named after the stage name" do
|
493
516
|
@created_class.stage_name.should == @stage_name
|
494
517
|
end
|
495
518
|
|
496
|
-
it "
|
519
|
+
it "adds the notifier during compilation" do
|
497
520
|
instance = @created_class.new
|
498
521
|
instance.filter_queue.notifiers.should_not be_nil
|
499
522
|
instance.filter_queue.notifiers.should_not be_empty
|
@@ -501,14 +524,14 @@ describe Batsir::Stage do
|
|
501
524
|
instance.filter_queue.notifiers.first.should be_a Batsir::Notifiers::Notifier
|
502
525
|
end
|
503
526
|
|
504
|
-
it "
|
527
|
+
it "adds a transformer to the notifier during compilation" do
|
505
528
|
instance = @created_class.new
|
506
529
|
|
507
530
|
instance.filter_queue.notifiers.first.transformer_queue.should_not be_empty
|
508
531
|
instance.filter_queue.notifiers.first.transformer_queue.first.should be_a Batsir::Transformers::Transformer
|
509
532
|
end
|
510
533
|
|
511
|
-
it "
|
534
|
+
it "adds a JSONOutputTransformer by default when no transformers are defined" do
|
512
535
|
stage = Batsir::Stage.new(:name => "SomeName")
|
513
536
|
|
514
537
|
stage.add_notifier(Batsir::Notifiers::Notifier)
|
@@ -522,25 +545,25 @@ describe Batsir::Stage do
|
|
522
545
|
instance.filter_queue.notifiers.first.transformer_queue.first.should be_a Batsir::Transformers::JSONOutputTransformer
|
523
546
|
end
|
524
547
|
|
525
|
-
it "
|
548
|
+
it "initialises a class local filter queue" do
|
526
549
|
@created_class.filter_queue.should_not be_nil
|
527
550
|
@created_class.filter_queue.should_not be_empty
|
528
551
|
end
|
529
552
|
|
530
|
-
it "
|
553
|
+
it "has intitialized the filters" do
|
531
554
|
@created_class.filter_queue.map{|filter| filter.class.to_s}.should include "Batsir::Filter"
|
532
555
|
end
|
533
|
-
|
534
|
-
it "
|
556
|
+
|
557
|
+
it "can add a filter multiple times" do
|
535
558
|
@created_class.filter_queue.select{ |filter| filter.class == Batsir::Filter }.size.should == 2
|
536
559
|
end
|
537
560
|
|
538
|
-
it "
|
561
|
+
it "uses the class local filter queue once an instance is initialized" do
|
539
562
|
instance = @created_class.new
|
540
563
|
instance.filter_queue.should == @created_class.filter_queue
|
541
564
|
end
|
542
565
|
|
543
|
-
it "
|
566
|
+
it "initialises all filters in the filter queue" do
|
544
567
|
@created_class.filter_queue.each do |filter|
|
545
568
|
filter.should_not be_a Class
|
546
569
|
end
|
@@ -599,7 +622,7 @@ describe Batsir::Stage do
|
|
599
622
|
MockAcceptor.reset
|
600
623
|
end
|
601
624
|
|
602
|
-
it "
|
625
|
+
it "sets the stage name on acceptors when they are started" do
|
603
626
|
stage = create_stage
|
604
627
|
stage.add_acceptor MockAcceptor
|
605
628
|
stage.add_acceptor MockAcceptor, :foo => :bar
|
@@ -608,7 +631,7 @@ describe Batsir::Stage do
|
|
608
631
|
MockAcceptor.stage_name.should == stage.name
|
609
632
|
end
|
610
633
|
|
611
|
-
it "
|
634
|
+
it "initially has an empty list of running acceptors" do
|
612
635
|
stage = create_stage
|
613
636
|
stage.add_acceptor MockAcceptor
|
614
637
|
|
@@ -616,7 +639,7 @@ describe Batsir::Stage do
|
|
616
639
|
stage.running_acceptors.should be_empty
|
617
640
|
end
|
618
641
|
|
619
|
-
it "
|
642
|
+
it "keeps track of running acceptors" do
|
620
643
|
stage = create_stage
|
621
644
|
stage.add_acceptor MockAcceptor
|
622
645
|
|
@@ -624,24 +647,7 @@ describe Batsir::Stage do
|
|
624
647
|
stage.running_acceptors.size.should == 1
|
625
648
|
end
|
626
649
|
|
627
|
-
it "
|
628
|
-
stage = create_stage
|
629
|
-
stage.add_acceptor MockAcceptor
|
630
|
-
|
631
|
-
stage.start
|
632
|
-
stage.running_acceptors.first.cancellator.should_not be_nil
|
633
|
-
end
|
634
|
-
|
635
|
-
it "should add cancellators to the stage list of cancellators" do
|
636
|
-
stage = create_stage
|
637
|
-
stage.add_acceptor MockAcceptor
|
638
|
-
stage.add_acceptor MockAcceptor, :foo => :bar
|
639
|
-
|
640
|
-
stage.start
|
641
|
-
stage.cancellators.size.should == 2
|
642
|
-
end
|
643
|
-
|
644
|
-
it "should start all acceptors" do
|
650
|
+
it "starts all acceptors" do
|
645
651
|
stage = create_stage
|
646
652
|
stage.add_acceptor MockAcceptor
|
647
653
|
stage.add_acceptor MockAcceptor, :foo => :bar
|
@@ -649,12 +655,12 @@ describe Batsir::Stage do
|
|
649
655
|
MockAcceptor.start_count.should == 0
|
650
656
|
|
651
657
|
stage.start
|
652
|
-
sleep(0.
|
658
|
+
sleep(0.05)
|
653
659
|
|
654
660
|
MockAcceptor.start_count.should == 2
|
655
661
|
end
|
656
662
|
|
657
|
-
it "
|
663
|
+
it "adds a Batsir::Transformers::JSONInputTransformer to acceptors when no transformers are defined" do
|
658
664
|
stage = create_stage
|
659
665
|
stage.add_acceptor MockAcceptor
|
660
666
|
|
@@ -664,7 +670,7 @@ describe Batsir::Stage do
|
|
664
670
|
MockAcceptor.added_transformers.first.should be_a Batsir::Transformers::JSONInputTransformer
|
665
671
|
end
|
666
672
|
|
667
|
-
it "
|
673
|
+
it "adds defined transformers to the acceptors" do
|
668
674
|
stage = create_stage
|
669
675
|
stage.add_acceptor_transformer Batsir::Transformers::Transformer
|
670
676
|
stage.add_acceptor MockAcceptor
|
@@ -1,6 +1,10 @@
|
|
1
1
|
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
2
|
|
3
3
|
describe Batsir::StageWorker do
|
4
|
+
it "can set a filter queue" do
|
5
|
+
Batsir::StageWorker.instance_methods.map{|m| m.to_s}.should include "filter_queue="
|
6
|
+
end
|
7
|
+
|
4
8
|
context "with respect to including the StageWorker module" do
|
5
9
|
before :all do
|
6
10
|
class TestWorker
|
@@ -25,25 +29,21 @@ describe Batsir::StageWorker do
|
|
25
29
|
include Batsir::StageWorker
|
26
30
|
end
|
27
31
|
end
|
28
|
-
|
29
|
-
it "
|
32
|
+
|
33
|
+
it "registers workers once they include the stage worker" do
|
30
34
|
Batsir::Registry.get("TestWorker").should == TestWorker
|
31
35
|
end
|
32
36
|
|
33
|
-
it "
|
37
|
+
it "calls the queue initialization method" do
|
34
38
|
TestWorker.initialization_count.should == 1
|
35
39
|
end
|
36
40
|
|
37
|
-
it "
|
41
|
+
it "calls the stage name class method to register itself under" do
|
38
42
|
TestWorker.stage_name_called.should be_true
|
39
43
|
end
|
40
44
|
end
|
41
45
|
|
42
|
-
|
43
|
-
Batsir::StageWorker.instance_methods.map{|m| m.to_s}.should include "filter_queue="
|
44
|
-
end
|
45
|
-
|
46
|
-
context "With respect to executing" do
|
46
|
+
context "with respect to executing" do
|
47
47
|
before :all do
|
48
48
|
class TestWorker
|
49
49
|
def self.stage_name
|
@@ -54,7 +54,7 @@ describe Batsir::StageWorker do
|
|
54
54
|
@initialization_count ||= 0
|
55
55
|
@initialization_count += 1
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
include Batsir::StageWorker
|
59
59
|
end
|
60
60
|
|
@@ -84,12 +84,12 @@ describe Batsir::StageWorker do
|
|
84
84
|
stage.add_notifier( :notification_queue_2 )
|
85
85
|
end
|
86
86
|
|
87
|
-
it "
|
87
|
+
it "does not execute when no operation queue is set" do
|
88
88
|
stage_worker = TestWorker.new
|
89
89
|
stage_worker.execute({}).should be_false
|
90
90
|
end
|
91
91
|
|
92
|
-
it "
|
92
|
+
it "executes all operations in the operation queue when an #execute message is received" do
|
93
93
|
filter_queue = Batsir::FilterQueue.new
|
94
94
|
filter_queue.add SumFilter.new
|
95
95
|
filter_queue.add AverageFilter.new
|
@@ -109,7 +109,7 @@ describe Batsir::StageWorker do
|
|
109
109
|
end
|
110
110
|
end
|
111
111
|
|
112
|
-
it "
|
112
|
+
it "calls #notify on all notifiers in the filter queue when an #execute message is received" do
|
113
113
|
filter_queue = Batsir::FilterQueue.new
|
114
114
|
filter_queue.add_notifier TestNotifier.new
|
115
115
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
|
2
|
+
|
3
|
+
describe Batsir::Strategies::RetryStrategy do
|
4
|
+
let( :strategy_class ) {
|
5
|
+
Batsir::Strategies::RetryStrategy
|
6
|
+
}
|
7
|
+
|
8
|
+
before :all do
|
9
|
+
class MockError < RuntimeError; end
|
10
|
+
|
11
|
+
class MockRetryContext
|
12
|
+
attr_accessor :strategy
|
13
|
+
|
14
|
+
def initialize(failures, retries)
|
15
|
+
@total_iterations = 0
|
16
|
+
@failures = failures
|
17
|
+
@strategy = Batsir::Strategies::RetryStrategy.new(self, retries)
|
18
|
+
end
|
19
|
+
|
20
|
+
def execute(message)
|
21
|
+
if @total_iterations == @failures
|
22
|
+
return "test complete"
|
23
|
+
else
|
24
|
+
@total_iterations += 1
|
25
|
+
handle_error(message)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_error(message)
|
30
|
+
@strategy.execute(message, MockError.new)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
@context = MockRetryContext.new(2,2)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'stores the number of allowed retries' do
|
38
|
+
@context.strategy.retries.should == 2
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'stores the retry attempts per message' do
|
42
|
+
@context.strategy.attempts.should == {}
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'attempts to execute the given number of times' do
|
46
|
+
@context = MockRetryContext.new(3,3)
|
47
|
+
@context.strategy.log.level = Batsir::Logger::FATAL
|
48
|
+
@context.execute("test").should == "test complete"
|
49
|
+
@context.strategy.attempts.size.should == 0
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'throws an error when all retry attempts have been used' do
|
53
|
+
@context = MockRetryContext.new(3,2)
|
54
|
+
@context.strategy.log.level = Batsir::Logger::FATAL
|
55
|
+
lambda{@context.execute("test")}.should raise_error Batsir::Errors::RetryStrategyFailed
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|