batsir 0.3.7.1 → 0.4.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/CHANGES.md +9 -0
- data/README.md +1 -1
- data/lib/batsir/compiler/stage_worker_compiler.rb +42 -27
- data/lib/batsir/dsl/conditional_notifier_declaration.rb +7 -7
- data/lib/batsir/version.rb +3 -3
- metadata +81 -151
- data/.document +0 -5
- data/.rspec +0 -3
- data/.travis.yml +0 -18
- data/Gemfile +0 -19
- data/Rakefile +0 -62
- data/batsir.gemspec +0 -132
- data/batsir.png +0 -0
- data/spec/batsir/acceptors/acceptor_spec.rb +0 -65
- data/spec/batsir/acceptors/amqp_acceptor_spec.rb +0 -158
- data/spec/batsir/acceptors/shared_examples.rb +0 -102
- data/spec/batsir/amqp_spec.rb +0 -58
- data/spec/batsir/chain_spec.rb +0 -31
- data/spec/batsir/config_spec.rb +0 -97
- data/spec/batsir/dsl/chain_mapping_spec.rb +0 -116
- data/spec/batsir/dsl/conditional_notifier_mapping_spec.rb +0 -80
- data/spec/batsir/dsl/stage_mapping_spec.rb +0 -453
- data/spec/batsir/filter_queue_spec.rb +0 -68
- data/spec/batsir/filter_spec.rb +0 -11
- data/spec/batsir/log_spec.rb +0 -10
- data/spec/batsir/logger_spec.rb +0 -46
- data/spec/batsir/notifiers/amqp_notifier_spec.rb +0 -138
- data/spec/batsir/notifiers/conditional_notifier_spec.rb +0 -62
- data/spec/batsir/notifiers/notifier_spec.rb +0 -11
- data/spec/batsir/notifiers/shared_examples.rb +0 -100
- data/spec/batsir/registry_spec.rb +0 -48
- data/spec/batsir/stage_spec.rb +0 -684
- data/spec/batsir/stage_worker_spec.rb +0 -128
- data/spec/batsir/strategies/retry_strategy_spec.rb +0 -58
- data/spec/batsir/strategies/strategy_spec.rb +0 -28
- data/spec/batsir/support/bunny_mocks.rb +0 -135
- data/spec/batsir/support/mock_filters.rb +0 -43
- data/spec/batsir/transformers/field_transformer_spec.rb +0 -73
- data/spec/batsir/transformers/json_input_transformer_spec.rb +0 -27
- data/spec/batsir/transformers/json_output_transformer_spec.rb +0 -18
- data/spec/batsir/transformers/transformer_spec.rb +0 -36
- data/spec/spec_helper.rb +0 -26
data/spec/batsir/stage_spec.rb
DELETED
@@ -1,684 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
-
|
3
|
-
describe Batsir::Stage do
|
4
|
-
def create_stage(options = {})
|
5
|
-
defaults = {
|
6
|
-
:name => "Test Stage",
|
7
|
-
:chain => Batsir::Chain.new
|
8
|
-
}
|
9
|
-
Batsir::Stage.new(defaults.merge(options))
|
10
|
-
end
|
11
|
-
|
12
|
-
before :all do
|
13
|
-
class StubFilter < Batsir::Filter
|
14
|
-
end
|
15
|
-
|
16
|
-
class AnotherFilter < Batsir::Filter
|
17
|
-
end
|
18
|
-
|
19
|
-
@object_type = "SomeResource"
|
20
|
-
end
|
21
|
-
|
22
|
-
it "is a Celluloid Actor" do
|
23
|
-
Batsir::Stage.ancestors.should include Celluloid
|
24
|
-
end
|
25
|
-
|
26
|
-
it "can name the stage" do
|
27
|
-
stage = Batsir::Stage.new
|
28
|
-
name = "StageName"
|
29
|
-
stage.name = name
|
30
|
-
stage.name.should == name
|
31
|
-
end
|
32
|
-
|
33
|
-
it "can set the name in the constructor" do
|
34
|
-
name = "StageName"
|
35
|
-
stage = Batsir::Stage.new(:name => name)
|
36
|
-
stage.name.should == name
|
37
|
-
end
|
38
|
-
|
39
|
-
it "can set the aggregator chain to which the stage belongs" do
|
40
|
-
chain = "Chain"
|
41
|
-
stage = Batsir::Stage.new(:chain => chain)
|
42
|
-
stage.chain.should == chain
|
43
|
-
end
|
44
|
-
|
45
|
-
context "with respect to filters" do
|
46
|
-
it "cannot set the filters directly" do
|
47
|
-
stage = Batsir::Stage.new
|
48
|
-
lambda { stage.filters = {} }.should raise_error(NoMethodError)
|
49
|
-
end
|
50
|
-
|
51
|
-
it "stores filters using filter declarations" do
|
52
|
-
filter = "Filter"
|
53
|
-
stage = Batsir::Stage.new
|
54
|
-
stage.add_filter(filter)
|
55
|
-
stage.filter_declarations.should_not be_nil
|
56
|
-
stage.filter_declarations.size.should == 1
|
57
|
-
declaration = stage.filter_declarations.first
|
58
|
-
declaration.filter.should == filter
|
59
|
-
declaration.options.should == {}
|
60
|
-
end
|
61
|
-
|
62
|
-
it "returns an empty array when the #filters method is called without any declared filters" do
|
63
|
-
stage = Batsir::Stage.new
|
64
|
-
stage.filters.should_not be_nil
|
65
|
-
stage.filters.should == []
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns all filters when the #filters method is called" do
|
69
|
-
filter1 = "Filter"
|
70
|
-
filter2 = "Filter2"
|
71
|
-
filter3 = "Filter"
|
72
|
-
stage = Batsir::Stage.new
|
73
|
-
stage.add_filter(filter1)
|
74
|
-
stage.add_filter(filter2)
|
75
|
-
stage.add_filter(filter3)
|
76
|
-
|
77
|
-
stage.filters.should_not be_nil
|
78
|
-
stage.filters.size.should == 3
|
79
|
-
stage.filters[0].should == filter1
|
80
|
-
stage.filters[1].should == filter2
|
81
|
-
stage.filters[2].should == filter3
|
82
|
-
end
|
83
|
-
|
84
|
-
it "adds a filter to its filters" do
|
85
|
-
filter = "Filter"
|
86
|
-
stage = Batsir::Stage.new
|
87
|
-
stage.add_filter(filter)
|
88
|
-
stage.filters.should_not be_nil
|
89
|
-
stage.filters.should include filter
|
90
|
-
end
|
91
|
-
|
92
|
-
it "can have multiple filters of the same class but with different options" do
|
93
|
-
stage = Batsir::Stage.new
|
94
|
-
stage.add_filter(:filter)
|
95
|
-
stage.add_filter(:filter, :foo => :bar)
|
96
|
-
|
97
|
-
stage.filters.should include :filter
|
98
|
-
stage.filters.size.should == 2
|
99
|
-
end
|
100
|
-
|
101
|
-
it "can add filters with on options hash" do
|
102
|
-
filter = :filter
|
103
|
-
options = {:foo => :bar}
|
104
|
-
|
105
|
-
stage = Batsir::Stage.new
|
106
|
-
stage.add_filter(filter, options)
|
107
|
-
|
108
|
-
stage.filters.should_not be_nil
|
109
|
-
stage.filters.should_not be_empty
|
110
|
-
stage.filters.should include filter
|
111
|
-
stage.filter_declarations.first.options.should == options
|
112
|
-
end
|
113
|
-
|
114
|
-
it "can add multiple filters with option hashes" do
|
115
|
-
filter1 = :filter1
|
116
|
-
filter2 = :filter2
|
117
|
-
options1 = {:foo1 => :bar1}
|
118
|
-
options2 = {:foo2 => :bar2}
|
119
|
-
|
120
|
-
stage = Batsir::Stage.new
|
121
|
-
stage.add_filter(filter1, options1)
|
122
|
-
stage.add_filter(filter2, options2)
|
123
|
-
|
124
|
-
stage.filters.should include filter1
|
125
|
-
stage.filters.should include filter2
|
126
|
-
stage.filter_declarations[0].options.should == options1
|
127
|
-
stage.filter_declarations[1].options.should == options2
|
128
|
-
end
|
129
|
-
|
130
|
-
it "adds empty options hashes to filters when no option hash is given" do
|
131
|
-
filter = :filter
|
132
|
-
|
133
|
-
stage = Batsir::Stage.new
|
134
|
-
stage.add_filter(filter)
|
135
|
-
|
136
|
-
stage.filters.should_not be_nil
|
137
|
-
stage.filters.should_not be_empty
|
138
|
-
stage.filters.should include filter
|
139
|
-
stage.filter_declarations.first.options.should == {}
|
140
|
-
end
|
141
|
-
|
142
|
-
it "can add a filter more than once" do
|
143
|
-
filter = :filter
|
144
|
-
stage = Batsir::Stage.new
|
145
|
-
stage.add_filter(filter)
|
146
|
-
stage.add_filter(filter)
|
147
|
-
stage.filters.should_not be_nil
|
148
|
-
stage.filters.should_not be_empty
|
149
|
-
stage.filters.size.should == 2
|
150
|
-
end
|
151
|
-
|
152
|
-
it "can add filter with different options and respect the order" do
|
153
|
-
filter = :filter
|
154
|
-
other_filter = :other_filter
|
155
|
-
|
156
|
-
stage = Batsir::Stage.new
|
157
|
-
stage.add_filter(filter)
|
158
|
-
stage.add_filter(other_filter)
|
159
|
-
stage.add_filter(filter, :foo => :bar)
|
160
|
-
stage.filters.size.should == 3
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
context "with respect to acceptors" do
|
165
|
-
it "initially has an empty list of acceptors" do
|
166
|
-
stage = Batsir::Stage.new
|
167
|
-
stage.acceptors.should_not be_nil
|
168
|
-
stage.acceptors.should be_empty
|
169
|
-
end
|
170
|
-
|
171
|
-
it "cannot set the acceptors directly" do
|
172
|
-
stage = Batsir::Stage.new
|
173
|
-
lambda { stage.acceptors = {} }.should raise_error(NoMethodError)
|
174
|
-
end
|
175
|
-
|
176
|
-
it "can add new acceptors" do
|
177
|
-
stage = Batsir::Stage.new
|
178
|
-
stage.add_acceptor(:acceptor)
|
179
|
-
stage.acceptors.should_not be_nil
|
180
|
-
stage.acceptors.should_not be_empty
|
181
|
-
stage.acceptors.keys.should include :acceptor
|
182
|
-
end
|
183
|
-
|
184
|
-
it "stores a set of different options for each acceptor" do
|
185
|
-
stage = Batsir::Stage.new
|
186
|
-
stage.add_acceptor(:acceptor)
|
187
|
-
stage.acceptors[:acceptor].should be_a Set
|
188
|
-
end
|
189
|
-
|
190
|
-
it "can have multiple acceptors of the same class but with different options" do
|
191
|
-
stage = Batsir::Stage.new
|
192
|
-
stage.add_acceptor(:acceptor_class)
|
193
|
-
stage.add_acceptor(:acceptor_class, :foo => :bar)
|
194
|
-
|
195
|
-
stage.acceptors.should_not be_nil
|
196
|
-
stage.acceptors.should_not be_empty
|
197
|
-
stage.acceptors.keys.should include :acceptor_class
|
198
|
-
stage.acceptors[:acceptor_class].size.should == 2
|
199
|
-
end
|
200
|
-
|
201
|
-
it "can add an acceptor with an options hash" do
|
202
|
-
stage = Batsir::Stage.new
|
203
|
-
options = {:foo => :bar}
|
204
|
-
stage.add_acceptor(:acceptor, options)
|
205
|
-
|
206
|
-
stage.acceptors.should_not be_nil
|
207
|
-
stage.acceptors.should_not be_empty
|
208
|
-
stage.acceptors.keys.should include :acceptor
|
209
|
-
stage.acceptors[:acceptor].first.should == options
|
210
|
-
end
|
211
|
-
|
212
|
-
it "adds an empty options hash for added acceptors without options" do
|
213
|
-
stage = Batsir::Stage.new
|
214
|
-
stage.add_acceptor(:acceptor)
|
215
|
-
|
216
|
-
stage.acceptors.should_not be_nil
|
217
|
-
stage.acceptors.should_not be_empty
|
218
|
-
stage.acceptors.keys.should include :acceptor
|
219
|
-
stage.acceptors[:acceptor].first.should == {}
|
220
|
-
end
|
221
|
-
|
222
|
-
it "initially has an empty list of cancellators" do
|
223
|
-
stage = Batsir::Stage.new
|
224
|
-
stage.cancellators.should_not be_nil
|
225
|
-
stage.cancellators.should be_empty
|
226
|
-
end
|
227
|
-
|
228
|
-
context "with respect to acceptor transformers" do
|
229
|
-
it "has an empty acceptor transformers queue by default" do
|
230
|
-
stage = Batsir::Stage.new
|
231
|
-
|
232
|
-
stage.acceptor_transformers.should_not be_nil
|
233
|
-
stage.acceptor_transformers.should be_empty
|
234
|
-
end
|
235
|
-
|
236
|
-
it "can add a transformer to the acceptors" do
|
237
|
-
stage = Batsir::Stage.new
|
238
|
-
|
239
|
-
transformer = :transformer
|
240
|
-
|
241
|
-
stage.add_acceptor_transformer(transformer)
|
242
|
-
stage.acceptor_transformers.should_not be_empty
|
243
|
-
|
244
|
-
stage.acceptor_transformers.first.transformer.should == transformer
|
245
|
-
end
|
246
|
-
|
247
|
-
it "adds an empty options hash by default" do
|
248
|
-
stage = Batsir::Stage.new
|
249
|
-
|
250
|
-
transformer = :transformer
|
251
|
-
stage.add_acceptor_transformer(transformer)
|
252
|
-
stage.acceptor_transformers.should_not be_empty
|
253
|
-
|
254
|
-
stage.acceptor_transformers.first.options.should == {}
|
255
|
-
end
|
256
|
-
|
257
|
-
it "can add options to a transformer" do
|
258
|
-
stage = Batsir::Stage.new
|
259
|
-
|
260
|
-
transformer = :transformer
|
261
|
-
options = {:foo => :bar}
|
262
|
-
|
263
|
-
stage.add_acceptor_transformer(transformer, options)
|
264
|
-
stage.acceptor_transformers.should_not be_empty
|
265
|
-
|
266
|
-
stage.acceptor_transformers.first.transformer.should == transformer
|
267
|
-
stage.acceptor_transformers.first.options.should == options
|
268
|
-
end
|
269
|
-
|
270
|
-
it "can add multiple transformers" do
|
271
|
-
stage = Batsir::Stage.new
|
272
|
-
|
273
|
-
transformer1 = :transformer1
|
274
|
-
transformer2 = :transformer2
|
275
|
-
|
276
|
-
stage.add_acceptor_transformer(transformer1)
|
277
|
-
stage.add_acceptor_transformer(transformer2)
|
278
|
-
stage.acceptor_transformers.should_not be_empty
|
279
|
-
stage.acceptor_transformers.size.should == 2
|
280
|
-
|
281
|
-
transformers = stage.acceptor_transformers.map{|td| td.transformer}
|
282
|
-
transformers.should include transformer1
|
283
|
-
transformers.should include transformer2
|
284
|
-
end
|
285
|
-
|
286
|
-
it "keeps the transformers in the order of declaration" do
|
287
|
-
stage = Batsir::Stage.new
|
288
|
-
|
289
|
-
transformer1 = :transformer1
|
290
|
-
transformer2 = :transformer2
|
291
|
-
|
292
|
-
stage.add_acceptor_transformer(transformer1)
|
293
|
-
stage.add_acceptor_transformer(transformer2)
|
294
|
-
stage.acceptor_transformers.should_not be_empty
|
295
|
-
stage.acceptor_transformers.size.should == 2
|
296
|
-
|
297
|
-
stage.acceptor_transformers.first.transformer.should == transformer1
|
298
|
-
stage.acceptor_transformers.last.transformer.should == transformer2
|
299
|
-
end
|
300
|
-
|
301
|
-
it "can add a transformer more than once" do
|
302
|
-
stage = Batsir::Stage.new
|
303
|
-
|
304
|
-
transformer = :transformer
|
305
|
-
|
306
|
-
stage.add_acceptor_transformer(transformer)
|
307
|
-
stage.add_acceptor_transformer(transformer)
|
308
|
-
stage.acceptor_transformers.should_not be_empty
|
309
|
-
stage.acceptor_transformers.size.should == 2
|
310
|
-
|
311
|
-
stage.acceptor_transformers.first.transformer.should == transformer
|
312
|
-
stage.acceptor_transformers.last.transformer.should == transformer
|
313
|
-
end
|
314
|
-
end
|
315
|
-
end
|
316
|
-
|
317
|
-
|
318
|
-
context "with respect to notifiers" do
|
319
|
-
it "initially has an empty notifiers queue" do
|
320
|
-
stage = Batsir::Stage.new
|
321
|
-
stage.notifiers.should_not be_nil
|
322
|
-
stage.notifiers.should be_empty
|
323
|
-
end
|
324
|
-
|
325
|
-
it "cannot set the notifiers directly" do
|
326
|
-
stage = Batsir::Stage.new
|
327
|
-
lambda { stage.notifiers = {} }.should raise_error(NoMethodError)
|
328
|
-
end
|
329
|
-
|
330
|
-
it "can add new notifiers" do
|
331
|
-
stage = Batsir::Stage.new
|
332
|
-
|
333
|
-
stage.add_notifier(:notifier)
|
334
|
-
stage.notifiers.should_not be_nil
|
335
|
-
stage.notifiers.should_not be_empty
|
336
|
-
stage.notifiers.keys.should include :notifier
|
337
|
-
end
|
338
|
-
|
339
|
-
it "stores a set of different options for each notifier" do
|
340
|
-
stage = Batsir::Stage.new
|
341
|
-
stage.add_notifier(:notifier)
|
342
|
-
stage.notifiers[:notifier].should be_a Set
|
343
|
-
end
|
344
|
-
|
345
|
-
it "can have multiple notifiers of the same class but with different options" do
|
346
|
-
stage = Batsir::Stage.new
|
347
|
-
stage.add_notifier(:notifier_class)
|
348
|
-
stage.add_notifier(:notifier_class, :foo => :bar)
|
349
|
-
|
350
|
-
stage.notifiers.should_not be_nil
|
351
|
-
stage.notifiers.keys.should include :notifier_class
|
352
|
-
stage.notifiers[:notifier_class].size.should == 2
|
353
|
-
end
|
354
|
-
|
355
|
-
it "can set a notifier with an options hash" do
|
356
|
-
stage = Batsir::Stage.new
|
357
|
-
|
358
|
-
options = {:foo => :bar}
|
359
|
-
|
360
|
-
stage.add_notifier(:notifier, options)
|
361
|
-
stage.notifiers.should_not be_nil
|
362
|
-
stage.notifiers.should_not be_empty
|
363
|
-
stage.notifiers.keys.should include :notifier
|
364
|
-
stage.notifiers[:notifier].first.should == options
|
365
|
-
end
|
366
|
-
|
367
|
-
it "adds an empty options hash for added notifiers without options" do
|
368
|
-
stage = Batsir::Stage.new
|
369
|
-
|
370
|
-
stage.add_notifier(:notifier)
|
371
|
-
stage.notifiers.should_not be_nil
|
372
|
-
stage.notifiers.should_not be_empty
|
373
|
-
stage.notifiers.keys.should include :notifier
|
374
|
-
stage.notifiers[:notifier].first.should == {}
|
375
|
-
end
|
376
|
-
|
377
|
-
context "with respect to notifier transformers" do
|
378
|
-
it "has an empty notifier transformers queue by default" do
|
379
|
-
stage = Batsir::Stage.new
|
380
|
-
|
381
|
-
stage.notifier_transformers.should_not be_nil
|
382
|
-
stage.notifier_transformers.should be_empty
|
383
|
-
end
|
384
|
-
|
385
|
-
it "can add a transformer to the notifiers" do
|
386
|
-
stage = Batsir::Stage.new
|
387
|
-
|
388
|
-
transformer = :transformer
|
389
|
-
|
390
|
-
stage.add_notifier_transformer(transformer)
|
391
|
-
stage.notifier_transformers.should_not be_empty
|
392
|
-
|
393
|
-
stage.notifier_transformers.first.transformer.should == transformer
|
394
|
-
end
|
395
|
-
|
396
|
-
it "adds an empty options hash by default" do
|
397
|
-
stage = Batsir::Stage.new
|
398
|
-
|
399
|
-
transformer = :transformer
|
400
|
-
stage.add_notifier_transformer(transformer)
|
401
|
-
stage.notifier_transformers.should_not be_empty
|
402
|
-
|
403
|
-
stage.notifier_transformers.first.options.should == {}
|
404
|
-
end
|
405
|
-
|
406
|
-
it "can add options to a transformer" do
|
407
|
-
stage = Batsir::Stage.new
|
408
|
-
|
409
|
-
transformer = :transformer
|
410
|
-
options = {:foo => :bar}
|
411
|
-
|
412
|
-
stage.add_notifier_transformer(transformer, options)
|
413
|
-
stage.notifier_transformers.should_not be_empty
|
414
|
-
|
415
|
-
stage.notifier_transformers.first.transformer.should == transformer
|
416
|
-
stage.notifier_transformers.first.options.should == options
|
417
|
-
end
|
418
|
-
|
419
|
-
it "can add multiple transformers" do
|
420
|
-
stage = Batsir::Stage.new
|
421
|
-
|
422
|
-
transformer1 = :transformer1
|
423
|
-
transformer2 = :transformer2
|
424
|
-
|
425
|
-
stage.add_notifier_transformer(transformer1)
|
426
|
-
stage.add_notifier_transformer(transformer2)
|
427
|
-
stage.notifier_transformers.should_not be_empty
|
428
|
-
stage.notifier_transformers.size.should == 2
|
429
|
-
|
430
|
-
transformers = stage.notifier_transformers.map{|td| td.transformer}
|
431
|
-
transformers.should include transformer1
|
432
|
-
transformers.should include transformer2
|
433
|
-
end
|
434
|
-
|
435
|
-
it "keeps the transformers in the order of declaration" do
|
436
|
-
stage = Batsir::Stage.new
|
437
|
-
|
438
|
-
transformer1 = :transformer1
|
439
|
-
transformer2 = :transformer2
|
440
|
-
|
441
|
-
stage.add_notifier_transformer(transformer1)
|
442
|
-
stage.add_notifier_transformer(transformer2)
|
443
|
-
stage.notifier_transformers.should_not be_empty
|
444
|
-
stage.notifier_transformers.size.should == 2
|
445
|
-
|
446
|
-
stage.notifier_transformers.first.transformer.should == transformer1
|
447
|
-
stage.notifier_transformers.last.transformer.should == transformer2
|
448
|
-
end
|
449
|
-
|
450
|
-
it "can add a transformer more than once" do
|
451
|
-
stage = Batsir::Stage.new
|
452
|
-
|
453
|
-
transformer = :transformer
|
454
|
-
|
455
|
-
stage.add_notifier_transformer(transformer)
|
456
|
-
stage.add_notifier_transformer(transformer)
|
457
|
-
stage.notifier_transformers.should_not be_empty
|
458
|
-
stage.notifier_transformers.size.should == 2
|
459
|
-
|
460
|
-
stage.notifier_transformers.first.transformer.should == transformer
|
461
|
-
stage.notifier_transformers.last.transformer.should == transformer
|
462
|
-
end
|
463
|
-
end
|
464
|
-
end
|
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
|
-
|
487
|
-
context "with respect to compiling the stage" do
|
488
|
-
before :all do
|
489
|
-
@stage_name = "Stage 1"
|
490
|
-
|
491
|
-
Celluloid.boot
|
492
|
-
|
493
|
-
stage = Batsir::Stage.new(:name => @stage_name)
|
494
|
-
|
495
|
-
stage.add_notifier_transformer(Batsir::Transformers::Transformer)
|
496
|
-
stage.add_notifier(Batsir::Notifiers::Notifier)
|
497
|
-
stage.add_filter(Batsir::Filter)
|
498
|
-
stage.add_filter(Batsir::Filter)
|
499
|
-
|
500
|
-
@created_class = eval( stage.compile )
|
501
|
-
end
|
502
|
-
|
503
|
-
it "creates a class named after the stage name" do
|
504
|
-
@created_class.to_s.should == "Stage1Worker"
|
505
|
-
end
|
506
|
-
|
507
|
-
it "creates a Batsir::StageWorker class" do
|
508
|
-
@created_class.ancestors.should include Batsir::StageWorker
|
509
|
-
end
|
510
|
-
|
511
|
-
it "creates a class that includes Sidekiq::Worker" do
|
512
|
-
@created_class.ancestors.should include Sidekiq::Worker
|
513
|
-
end
|
514
|
-
|
515
|
-
it "creates a worker class named after the stage name" do
|
516
|
-
@created_class.stage_name.should == @stage_name
|
517
|
-
end
|
518
|
-
|
519
|
-
it "adds the notifier during compilation" do
|
520
|
-
instance = @created_class.new
|
521
|
-
instance.filter_queue.notifiers.should_not be_nil
|
522
|
-
instance.filter_queue.notifiers.should_not be_empty
|
523
|
-
instance.filter_queue.notifiers.size.should == 1
|
524
|
-
instance.filter_queue.notifiers.first.should be_a Batsir::Notifiers::Notifier
|
525
|
-
end
|
526
|
-
|
527
|
-
it "adds a transformer to the notifier during compilation" do
|
528
|
-
instance = @created_class.new
|
529
|
-
|
530
|
-
instance.filter_queue.notifiers.first.transformer_queue.should_not be_empty
|
531
|
-
instance.filter_queue.notifiers.first.transformer_queue.first.should be_a Batsir::Transformers::Transformer
|
532
|
-
end
|
533
|
-
|
534
|
-
it "adds a JSONOutputTransformer by default when no transformers are defined" do
|
535
|
-
stage = Batsir::Stage.new(:name => "SomeName")
|
536
|
-
|
537
|
-
stage.add_notifier(Batsir::Notifiers::Notifier)
|
538
|
-
|
539
|
-
created_class = eval( stage.compile )
|
540
|
-
instance = created_class.new
|
541
|
-
|
542
|
-
instance.filter_queue.notifiers.should_not be_nil
|
543
|
-
instance.filter_queue.notifiers.should_not be_empty
|
544
|
-
instance.filter_queue.notifiers.first.transformer_queue.should_not be_empty
|
545
|
-
instance.filter_queue.notifiers.first.transformer_queue.first.should be_a Batsir::Transformers::JSONOutputTransformer
|
546
|
-
end
|
547
|
-
|
548
|
-
it "initialises a class local filter queue" do
|
549
|
-
@created_class.filter_queue.should_not be_nil
|
550
|
-
@created_class.filter_queue.should_not be_empty
|
551
|
-
end
|
552
|
-
|
553
|
-
it "has intitialized the filters" do
|
554
|
-
@created_class.filter_queue.map{|filter| filter.class.to_s}.should include "Batsir::Filter"
|
555
|
-
end
|
556
|
-
|
557
|
-
it "can add a filter multiple times" do
|
558
|
-
@created_class.filter_queue.select{ |filter| filter.class == Batsir::Filter }.size.should == 2
|
559
|
-
end
|
560
|
-
|
561
|
-
it "uses the class local filter queue once an instance is initialized" do
|
562
|
-
instance = @created_class.new
|
563
|
-
instance.filter_queue.should == @created_class.filter_queue
|
564
|
-
end
|
565
|
-
|
566
|
-
it "initialises all filters in the filter queue" do
|
567
|
-
@created_class.filter_queue.each do |filter|
|
568
|
-
filter.should_not be_a Class
|
569
|
-
end
|
570
|
-
end
|
571
|
-
end
|
572
|
-
|
573
|
-
context "with respect to starting the stage" do
|
574
|
-
before :all do
|
575
|
-
class MockAcceptor < Batsir::Acceptors::Acceptor
|
576
|
-
|
577
|
-
def foo=(bar)
|
578
|
-
end
|
579
|
-
|
580
|
-
def stage_name=(name)
|
581
|
-
@@stage_name = name
|
582
|
-
end
|
583
|
-
|
584
|
-
def self.stage_name
|
585
|
-
@@stage_name
|
586
|
-
end
|
587
|
-
|
588
|
-
def start
|
589
|
-
@@start_count ||= 0
|
590
|
-
@@start_count += 1
|
591
|
-
end
|
592
|
-
|
593
|
-
def add_transformer(transformer)
|
594
|
-
@@added_transformers ||= []
|
595
|
-
@@added_transformers << transformer
|
596
|
-
end
|
597
|
-
|
598
|
-
def self.added_transformers
|
599
|
-
@@added_transformers ||= []
|
600
|
-
end
|
601
|
-
|
602
|
-
def self.start_count
|
603
|
-
@@start_count ||= 0
|
604
|
-
end
|
605
|
-
|
606
|
-
def self.reset
|
607
|
-
@@start_count = 0
|
608
|
-
@@stage_name = nil
|
609
|
-
@@added_transformers = []
|
610
|
-
end
|
611
|
-
|
612
|
-
end
|
613
|
-
|
614
|
-
class Celluloid::ActorProxy
|
615
|
-
def start!
|
616
|
-
Celluloid::Actor.call @mailbox, :start
|
617
|
-
end
|
618
|
-
end
|
619
|
-
end
|
620
|
-
|
621
|
-
before :each do
|
622
|
-
MockAcceptor.reset
|
623
|
-
end
|
624
|
-
|
625
|
-
it "sets the stage name on acceptors when they are started" do
|
626
|
-
stage = create_stage
|
627
|
-
stage.add_acceptor MockAcceptor
|
628
|
-
stage.add_acceptor MockAcceptor, :foo => :bar
|
629
|
-
|
630
|
-
stage.start
|
631
|
-
MockAcceptor.stage_name.should == stage.name
|
632
|
-
end
|
633
|
-
|
634
|
-
it "initially has an empty list of running acceptors" do
|
635
|
-
stage = create_stage
|
636
|
-
stage.add_acceptor MockAcceptor
|
637
|
-
|
638
|
-
stage.running_acceptors.should_not be_nil
|
639
|
-
stage.running_acceptors.should be_empty
|
640
|
-
end
|
641
|
-
|
642
|
-
it "keeps track of running acceptors" do
|
643
|
-
stage = create_stage
|
644
|
-
stage.add_acceptor MockAcceptor
|
645
|
-
|
646
|
-
stage.start
|
647
|
-
stage.running_acceptors.size.should == 1
|
648
|
-
end
|
649
|
-
|
650
|
-
it "starts all acceptors" do
|
651
|
-
stage = create_stage
|
652
|
-
stage.add_acceptor MockAcceptor
|
653
|
-
stage.add_acceptor MockAcceptor, :foo => :bar
|
654
|
-
|
655
|
-
MockAcceptor.start_count.should == 0
|
656
|
-
|
657
|
-
stage.start
|
658
|
-
sleep(0.05)
|
659
|
-
|
660
|
-
MockAcceptor.start_count.should == 2
|
661
|
-
end
|
662
|
-
|
663
|
-
it "adds a Batsir::Transformers::JSONInputTransformer to acceptors when no transformers are defined" do
|
664
|
-
stage = create_stage
|
665
|
-
stage.add_acceptor MockAcceptor
|
666
|
-
|
667
|
-
stage.start
|
668
|
-
|
669
|
-
MockAcceptor.added_transformers.size.should == 1
|
670
|
-
MockAcceptor.added_transformers.first.should be_a Batsir::Transformers::JSONInputTransformer
|
671
|
-
end
|
672
|
-
|
673
|
-
it "adds defined transformers to the acceptors" do
|
674
|
-
stage = create_stage
|
675
|
-
stage.add_acceptor_transformer Batsir::Transformers::Transformer
|
676
|
-
stage.add_acceptor MockAcceptor
|
677
|
-
|
678
|
-
stage.start
|
679
|
-
|
680
|
-
MockAcceptor.added_transformers.size.should == 1
|
681
|
-
MockAcceptor.added_transformers.first.should be_a Batsir::Transformers::Transformer
|
682
|
-
end
|
683
|
-
end
|
684
|
-
end
|