batsir 0.1.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.
Files changed (48) hide show
  1. data/.document +5 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +10 -0
  4. data/Gemfile +22 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.md +79 -0
  7. data/Rakefile +55 -0
  8. data/VERSION +1 -0
  9. data/batsir.gemspec +104 -0
  10. data/batsir.png +0 -0
  11. data/lib/batsir.rb +73 -0
  12. data/lib/batsir/acceptors/acceptor.rb +45 -0
  13. data/lib/batsir/acceptors/amqp_acceptor.rb +19 -0
  14. data/lib/batsir/amqp.rb +45 -0
  15. data/lib/batsir/chain.rb +33 -0
  16. data/lib/batsir/config.rb +34 -0
  17. data/lib/batsir/dsl/dsl_mappings.rb +96 -0
  18. data/lib/batsir/filter.rb +12 -0
  19. data/lib/batsir/filter_queue.rb +30 -0
  20. data/lib/batsir/logo.rb +36 -0
  21. data/lib/batsir/notifiers/amqp_notifier.rb +16 -0
  22. data/lib/batsir/notifiers/notifier.rb +39 -0
  23. data/lib/batsir/registry.rb +15 -0
  24. data/lib/batsir/stage.rb +94 -0
  25. data/lib/batsir/stage_worker.rb +86 -0
  26. data/lib/batsir/transformers/field_transformer.rb +40 -0
  27. data/lib/batsir/transformers/json_input_transformer.rb +9 -0
  28. data/lib/batsir/transformers/json_output_transformer.rb +9 -0
  29. data/lib/batsir/transformers/transformer.rb +15 -0
  30. data/spec/batsir/acceptors/acceptor_spec.rb +136 -0
  31. data/spec/batsir/acceptors/amqp_acceptor_spec.rb +169 -0
  32. data/spec/batsir/chain_spec.rb +31 -0
  33. data/spec/batsir/dsl/chain_mapping_spec.rb +117 -0
  34. data/spec/batsir/dsl/stage_mapping_spec.rb +435 -0
  35. data/spec/batsir/filter_queue_spec.rb +74 -0
  36. data/spec/batsir/filter_spec.rb +12 -0
  37. data/spec/batsir/notifiers/amqp_notifier_spec.rb +117 -0
  38. data/spec/batsir/notifiers/notifier_spec.rb +73 -0
  39. data/spec/batsir/stage_spec.rb +678 -0
  40. data/spec/batsir/stage_worker_spec.rb +128 -0
  41. data/spec/batsir/support/bunny_mocks.rb +62 -0
  42. data/spec/batsir/support/mock_filters.rb +43 -0
  43. data/spec/batsir/transformers/field_transformer_spec.rb +73 -0
  44. data/spec/batsir/transformers/json_input_transformer_spec.rb +22 -0
  45. data/spec/batsir/transformers/json_output_transformer_spec.rb +18 -0
  46. data/spec/batsir/transformers/transformer_spec.rb +22 -0
  47. data/spec/spec_helper.rb +22 -0
  48. metadata +220 -0
@@ -0,0 +1,31 @@
1
+ require File.join( File.dirname(__FILE__), "..", "spec_helper" )
2
+
3
+ describe Batsir::Chain do
4
+ it "should have a list of stages" do
5
+ chain = Batsir::Chain.new
6
+ chain.stages.should_not be_nil
7
+ end
8
+
9
+ it "should initially have an empty list of stages" do
10
+ chain = Batsir::Chain.new
11
+ chain.stages.should be_empty
12
+ end
13
+
14
+ it "should be possible to add a stage" do
15
+ chain = Batsir::Chain.new
16
+ stage = Batsir::Stage.new(:name => "Stage")
17
+ chain.add_stage(stage)
18
+ chain.stages.should include stage
19
+ end
20
+
21
+ it "should be possible to compile a chain" do
22
+ chain = Batsir::Chain.new
23
+ stage = Batsir::Stage.new(:name => "Stage")
24
+ chain.add_stage(stage)
25
+ compiled_code = chain.compile
26
+ compiled_code.should_not be_nil
27
+
28
+ klazz = eval(compiled_code)
29
+ klazz.name.to_s.should == "StageWorker"
30
+ end
31
+ end
@@ -0,0 +1,117 @@
1
+ require File.join( File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe Batsir::DSL::ChainMapping do
4
+ it "should create a chain" do
5
+ block = ::Proc.new do
6
+ aggregator_chain do
7
+ end
8
+ end
9
+
10
+ chain = ::Blockenspiel.invoke(block, Batsir::DSL::ChainMapping.new)
11
+ chain.should_not be_nil
12
+ end
13
+
14
+ it "should be possible to add a stage" do
15
+ block = ::Proc.new do
16
+ aggregator_chain do
17
+ stage "simple_stage" do
18
+
19
+ end
20
+ end
21
+ end
22
+
23
+ chain = ::Blockenspiel.invoke(block, Batsir::DSL::ChainMapping.new)
24
+ chain.stages.should_not be_empty
25
+ chain.stages.size.should == 1
26
+ chain.stages.first.name.should == "simple_stage"
27
+ end
28
+
29
+ it "should set the chain of the stage to the current chain" do
30
+ block = ::Proc.new do
31
+ aggregator_chain do
32
+ stage "simple_stage" do
33
+
34
+ end
35
+ end
36
+ end
37
+
38
+ chain = ::Blockenspiel.invoke(block, Batsir::DSL::ChainMapping.new)
39
+ chain.stages.size.should == 1
40
+ chain.stages.first.chain.should == chain
41
+ end
42
+
43
+ it "should be possible to add multiple stages" do
44
+ block = ::Proc.new do
45
+ aggregator_chain do
46
+ stage "first_stage" do
47
+
48
+ end
49
+ stage "second_stage" do
50
+
51
+ end
52
+ end
53
+ end
54
+
55
+ chain = ::Blockenspiel.invoke(block, Batsir::DSL::ChainMapping.new)
56
+ chain.stages.should_not be_empty
57
+ chain.stages.size.should == 2
58
+ chain.stages.first.name.should == "first_stage"
59
+ chain.stages.last.name.should == "second_stage"
60
+ end
61
+
62
+ it "should be possible to create a complete aggregator chain" do
63
+ stage_name = "Complete Stage"
64
+ operation1 = "Some Operation"
65
+ operation2 = "Another Operation"
66
+ notification_class1 = :notification_class1
67
+ options = {:queue => :somequeue}
68
+ notification_class2 = :notification_class2
69
+
70
+ block = ::Proc.new do
71
+ aggregator_chain do
72
+ stage stage_name do
73
+ filter operation1
74
+ filter operation2
75
+ outbound do
76
+ notifier notification_class1, options
77
+ notifier notification_class2
78
+ end
79
+ end
80
+
81
+ stage "#{stage_name}2" do
82
+ filter operation1
83
+ filter operation2
84
+ outbound do
85
+ notifier notification_class1, options
86
+ notifier notification_class2
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ chain = ::Blockenspiel.invoke(block, Batsir::DSL::ChainMapping.new)
93
+ chain.should_not be_nil
94
+ chain.stages.size.should == 2
95
+ stage1 = chain.stages.first
96
+ stage1.should_not be_nil
97
+ stage1.name.should == stage_name
98
+
99
+ stage2 = chain.stages.last
100
+ stage2.should_not be_nil
101
+ stage2.name.should == "#{stage_name}2"
102
+
103
+ chain.stages.each do |stage|
104
+ stage.filters.should_not be_nil
105
+ stage.filters.should_not be_empty
106
+ stage.filters.should include operation1
107
+ stage.filters.should include operation2
108
+ stage.notifiers.should_not be_nil
109
+ stage.notifiers.should_not be_empty
110
+ stage.notifiers.should have_key notification_class1
111
+ stage.notifiers[notification_class1].first.should == options
112
+ stage.notifiers.should have_key notification_class2
113
+ stage.notifiers[notification_class2].first.should == {}
114
+ end
115
+ end
116
+
117
+ end
@@ -0,0 +1,435 @@
1
+ require File.join( File.dirname(__FILE__), "..", "..", "spec_helper")
2
+
3
+ describe Batsir::DSL::StageMapping do
4
+ it "should create a simple stage with a name" do
5
+ block = ::Proc.new do
6
+ stage "simple_stage" do
7
+ end
8
+ end
9
+
10
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
11
+ stage.should_not be_nil
12
+ stage.name.should == "simple_stage"
13
+ end
14
+
15
+ it "should be possible to add an filter to the stage" do
16
+ filter = "Operation"
17
+
18
+ block = ::Proc.new do
19
+ stage "simple_stage" do
20
+ filter filter
21
+ end
22
+ end
23
+
24
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
25
+ stage.should_not be_nil
26
+ stage.filters.should_not be_nil
27
+ stage.filters.should_not be_empty
28
+ stage.filters.should include filter
29
+ end
30
+
31
+ it "should be possible to add multiple filters to the stage" do
32
+ filter1 = "Operation 1"
33
+ filter2 = "Operation 2"
34
+
35
+ block = ::Proc.new do
36
+ stage "simple_stage" do
37
+ filter filter1
38
+ filter filter2
39
+ end
40
+ end
41
+
42
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
43
+ stage.should_not be_nil
44
+ stage.filters.should_not be_nil
45
+ stage.filters.should_not be_empty
46
+ stage.filters.should include filter1
47
+ stage.filters.should include filter2
48
+ end
49
+
50
+ it "should be possible to add an inbound section to a stage" do
51
+ block = ::Proc.new do
52
+ stage "simple_stage" do
53
+ inbound do
54
+
55
+ end
56
+ end
57
+ end
58
+
59
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
60
+ stage.should_not be_nil
61
+ stage.acceptors.should_not be_nil
62
+ stage.acceptors.should be_empty
63
+ end
64
+
65
+ it "should be possible to add a transformers section to the inbound section of a stage" do
66
+ block = ::Proc.new do
67
+ stage "simple_stage" do
68
+ inbound do
69
+ transformers do
70
+
71
+ end
72
+ end
73
+ end
74
+ end
75
+
76
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
77
+ stage.should_not be_nil
78
+ stage.acceptors.should_not be_nil
79
+ stage.acceptors.should be_empty
80
+ stage.acceptor_transformers.should be_empty
81
+ end
82
+
83
+ it "should be possible to add a transformer to the transformers section of the inbound section of a stage" do
84
+ transformer = :transformer
85
+
86
+ block = ::Proc.new do
87
+ stage "simple_stage" do
88
+ inbound do
89
+ transformers do
90
+ transformer transformer
91
+ end
92
+ end
93
+ end
94
+ end
95
+
96
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
97
+ stage.should_not be_nil
98
+ stage.acceptors.should_not be_nil
99
+ stage.acceptors.should be_empty
100
+ stage.acceptor_transformers.should_not be_empty
101
+ stage.acceptor_transformers.size.should == 1
102
+ stage.acceptor_transformers.first.transformer.should == transformer
103
+ end
104
+
105
+ it "should be possible to add a transformer with options to the transformers section of the inbound section of a stage" do
106
+ transformer = :transformer
107
+ options = {:foo => :bar}
108
+
109
+ block = ::Proc.new do
110
+ stage "simple_stage" do
111
+ inbound do
112
+ transformers do
113
+ transformer transformer, options
114
+ end
115
+ end
116
+ end
117
+ end
118
+
119
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
120
+ stage.should_not be_nil
121
+ stage.acceptors.should_not be_nil
122
+ stage.acceptors.should be_empty
123
+ stage.acceptor_transformers.should_not be_empty
124
+ stage.acceptor_transformers.size.should == 1
125
+ stage.acceptor_transformers.first.transformer.should == transformer
126
+ stage.acceptor_transformers.first.options.should == options
127
+ end
128
+
129
+ it "should be possible to add multiple transformers to the transformers section of the inbound section of a stage" do
130
+ transformer1 = :transformer1
131
+ options = {:foo => :bar}
132
+ transformer2 = :transformer2
133
+
134
+ block = ::Proc.new do
135
+ stage "simple_stage" do
136
+ inbound do
137
+ transformers do
138
+ transformer transformer1, options
139
+ transformer transformer2
140
+ end
141
+ end
142
+ end
143
+ end
144
+
145
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
146
+ stage.should_not be_nil
147
+ stage.acceptors.should_not be_nil
148
+ stage.acceptors.should be_empty
149
+ stage.acceptor_transformers.should_not be_empty
150
+ stage.acceptor_transformers.size.should == 2
151
+ stage.acceptor_transformers.first.transformer.should == transformer1
152
+ stage.acceptor_transformers.first.options.should == options
153
+ stage.acceptor_transformers.last.transformer.should == transformer2
154
+ stage.acceptor_transformers.last.options.should == {}
155
+ end
156
+
157
+ it "should be possible to add an acceptor to a stage" do
158
+ acceptor_class = :acceptor_class
159
+
160
+ block = ::Proc.new do
161
+ stage "simple_stage" do
162
+ inbound do
163
+ acceptor acceptor_class
164
+ end
165
+ end
166
+ end
167
+
168
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
169
+ stage.should_not be_nil
170
+ stage.acceptors.should_not be_nil
171
+ stage.acceptors.should_not be_empty
172
+ stage.acceptors.keys.should include acceptor_class
173
+ stage.acceptors[acceptor_class].first.should == {}
174
+ end
175
+
176
+ it "should be possible to add an inbound section with an acceptor with options to the stage" do
177
+ acceptor_class = :acceptor_class
178
+ options = {:foo => :bar}
179
+
180
+ block = ::Proc.new do
181
+ stage "simple_stage" do
182
+ inbound do
183
+ acceptor acceptor_class, options
184
+ end
185
+ end
186
+ end
187
+
188
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
189
+ stage.should_not be_nil
190
+ stage.acceptors.should_not be_nil
191
+ stage.acceptors.should_not be_empty
192
+ stage.acceptors.keys.should include acceptor_class
193
+ stage.acceptors[acceptor_class].first.should == options
194
+ end
195
+
196
+ it "should be possible to add multiple acceptors to a stage" do
197
+ acceptor_class1 = :acceptor_class1
198
+ options = {:foo => :bar}
199
+ acceptor_class2 = :acceptor_class2
200
+
201
+ block = ::Proc.new do
202
+ stage "simple_stage" do
203
+ inbound do
204
+ acceptor acceptor_class1, options
205
+ acceptor acceptor_class2
206
+ end
207
+ end
208
+ end
209
+
210
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
211
+ stage.should_not be_nil
212
+ stage.acceptors.should_not be_nil
213
+ stage.acceptors.should_not be_empty
214
+ stage.acceptors.keys.should include acceptor_class1
215
+ stage.acceptors[acceptor_class1].first.should == options
216
+ stage.acceptors.keys.should include acceptor_class2
217
+ stage.acceptors[acceptor_class2].first.should == {}
218
+ end
219
+
220
+ it "should be possible to add an outbound section without any notifiers" do
221
+ block = ::Proc.new do
222
+ stage "simple_stage" do
223
+ outbound do
224
+
225
+ end
226
+ end
227
+ end
228
+
229
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
230
+ stage.should_not be_nil
231
+ stage.notifiers.should_not be_nil
232
+ stage.notifiers.should be_empty
233
+ end
234
+
235
+ it "should be possible to add a transformers section to the outbound section of a stage" do
236
+ block = ::Proc.new do
237
+ stage "simple_stage" do
238
+ outbound do
239
+ transformers do
240
+
241
+ end
242
+ end
243
+ end
244
+ end
245
+
246
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
247
+ stage.should_not be_nil
248
+ stage.notifiers.should_not be_nil
249
+ stage.notifiers.should be_empty
250
+ stage.notifier_transformers.should be_empty
251
+ end
252
+
253
+ it "should be possible to add a transformer to the transformers section of the outbound section of a stage" do
254
+ transformer = :transformer
255
+
256
+ block = ::Proc.new do
257
+ stage "simple_stage" do
258
+ outbound do
259
+ transformers do
260
+ transformer transformer
261
+ end
262
+ end
263
+ end
264
+ end
265
+
266
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
267
+ stage.should_not be_nil
268
+ stage.notifiers.should_not be_nil
269
+ stage.notifiers.should be_empty
270
+ stage.notifier_transformers.should_not be_empty
271
+ stage.notifier_transformers.size.should == 1
272
+ stage.notifier_transformers.first.transformer.should == transformer
273
+ end
274
+
275
+ it "should be possible to add a transformer with options to the transformers section of the outbound section of a stage" do
276
+ transformer = :transformer
277
+ options = {:foo => :bar}
278
+
279
+ block = ::Proc.new do
280
+ stage "simple_stage" do
281
+ outbound do
282
+ transformers do
283
+ transformer transformer, options
284
+ end
285
+ end
286
+ end
287
+ end
288
+
289
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
290
+ stage.should_not be_nil
291
+ stage.notifiers.should_not be_nil
292
+ stage.notifiers.should be_empty
293
+ stage.notifier_transformers.should_not be_empty
294
+ stage.notifier_transformers.size.should == 1
295
+ stage.notifier_transformers.first.transformer.should == transformer
296
+ stage.notifier_transformers.first.options.should == options
297
+ end
298
+
299
+ it "should be possible to add multiple transformers to the transformers section of the outbound section of a stage" do
300
+ transformer1 = :transformer1
301
+ options = {:foo => :bar}
302
+ transformer2 = :transformer2
303
+
304
+ block = ::Proc.new do
305
+ stage "simple_stage" do
306
+ outbound do
307
+ transformers do
308
+ transformer transformer1, options
309
+ transformer transformer2
310
+ end
311
+ end
312
+ end
313
+ end
314
+
315
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
316
+ stage.should_not be_nil
317
+ stage.notifiers.should_not be_nil
318
+ stage.notifiers.should be_empty
319
+ stage.notifier_transformers.should_not be_empty
320
+ stage.notifier_transformers.size.should == 2
321
+ stage.notifier_transformers.first.transformer.should == transformer1
322
+ stage.notifier_transformers.first.options.should == options
323
+ stage.notifier_transformers.last.transformer.should == transformer2
324
+ stage.notifier_transformers.last.options.should == {}
325
+ end
326
+
327
+ it "should be possible to add an outbound section to the stage" do
328
+ notification_class = :notification_class
329
+
330
+ block = ::Proc.new do
331
+ stage "simple_stage" do
332
+ outbound do
333
+ notifier notification_class
334
+ end
335
+ end
336
+ end
337
+
338
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
339
+ stage.should_not be_nil
340
+ stage.notifiers.should_not be_empty
341
+ stage.notifiers.should have_key notification_class
342
+ stage.notifiers[notification_class].first.should == {}
343
+ end
344
+
345
+ it "should be possible to add an outbound section with a notifier with options to the stage" do
346
+ notification_class = :notification_class
347
+ options = {:queue => :somequeue}
348
+
349
+ block = ::Proc.new do
350
+ stage "simple_stage" do
351
+ outbound do
352
+ notifier notification_class, options
353
+ end
354
+ end
355
+ end
356
+
357
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
358
+ stage.should_not be_nil
359
+ stage.notifiers.should_not be_empty
360
+ stage.notifiers.should have_key notification_class
361
+ stage.notifiers[notification_class].first.should == options
362
+ end
363
+
364
+ it "should be possible to add multiple notifiers to the stage" do
365
+ notification_class1 = :notification_class1
366
+ options = {:queue => :somequeue}
367
+ notification_class2 = :notification_class2
368
+
369
+ block = ::Proc.new do
370
+ stage "simple_stage" do
371
+ outbound do
372
+ notifier notification_class1, options
373
+ notifier notification_class2
374
+ end
375
+ end
376
+ end
377
+
378
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
379
+ stage.should_not be_nil
380
+ stage.notifiers.should_not be_empty
381
+ stage.notifiers.should have_key notification_class1
382
+ stage.notifiers[notification_class1].first.should == options
383
+
384
+ stage.notifiers.should have_key notification_class2
385
+ stage.notifiers[notification_class2].first.should == {}
386
+ end
387
+
388
+ it "should be possible to create a complete stage" do
389
+ acceptor_class1 = :acceptor_class1
390
+ options = {:foo => :bar}
391
+ acceptor_class2 = :acceptor_class2
392
+ stage_name = "Complete Stage"
393
+ filter1 = "Some Filter"
394
+ filter2 = "Another Filter"
395
+ notification_class1 = :notification_class1
396
+ options = {:queue => :somequeue}
397
+ notification_class2 = :notification_class2
398
+
399
+ block = ::Proc.new do
400
+ stage stage_name do
401
+ inbound do
402
+ acceptor acceptor_class1, options
403
+ acceptor acceptor_class2
404
+ end
405
+ filter filter1
406
+ filter filter2
407
+ outbound do
408
+ notifier notification_class1, options
409
+ notifier notification_class2
410
+ end
411
+ end
412
+ end
413
+
414
+ stage = ::Blockenspiel.invoke(block, Batsir::DSL::StageMapping.new)
415
+ stage.should_not be_nil
416
+ stage.name.should == stage_name
417
+ stage.acceptors.should_not be_nil
418
+ stage.acceptors.should_not be_empty
419
+ stage.acceptors.keys.should include acceptor_class1
420
+ stage.acceptors[acceptor_class1].first.should == options
421
+ stage.acceptors.keys.should include acceptor_class2
422
+ stage.acceptors[acceptor_class2].first.should == {}
423
+ stage.filters.should_not be_nil
424
+ stage.filters.should_not be_empty
425
+ stage.filters.should include filter1
426
+ stage.filters.should include filter2
427
+ stage.notifiers.should_not be_nil
428
+ stage.notifiers.should_not be_empty
429
+ stage.notifiers.should have_key notification_class1
430
+ stage.notifiers[notification_class1].first.should == options
431
+
432
+ stage.notifiers.should have_key notification_class2
433
+ stage.notifiers[notification_class2].first.should == {}
434
+ end
435
+ end