batsir 0.3.7.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/filter_spec.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
-
|
3
|
-
describe Batsir::Filter do
|
4
|
-
it "has an #execute method" do
|
5
|
-
Batsir::Filter.instance_methods.map{|im| im.to_s}.should include "execute"
|
6
|
-
end
|
7
|
-
|
8
|
-
it "throws an NotImplementedError when #execute method is not overridden" do
|
9
|
-
lambda{subject.execute("testing..1..2..3")}.should raise_error NotImplementedError
|
10
|
-
end
|
11
|
-
end
|
data/spec/batsir/log_spec.rb
DELETED
@@ -1,10 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
-
|
3
|
-
describe Batsir::Log do
|
4
|
-
it 'provides a convenience method for logging' do
|
5
|
-
class TestClass
|
6
|
-
include Batsir::Log
|
7
|
-
end
|
8
|
-
TestClass.instance_methods.map{|im| im.to_s}.should include 'log'
|
9
|
-
end
|
10
|
-
end
|
data/spec/batsir/logger_spec.rb
DELETED
@@ -1,46 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
-
|
3
|
-
describe Batsir::Logger do
|
4
|
-
before :all do
|
5
|
-
@logger = Batsir::Logger
|
6
|
-
end
|
7
|
-
|
8
|
-
it 'returns an object of Log4r::Logger class' do
|
9
|
-
@logger.log.should be_a Log4r::Logger
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'allows changing its settings' do
|
13
|
-
@logger.level.should_not == Log4r::DEBUG
|
14
|
-
@logger.level = Log4r::DEBUG
|
15
|
-
@logger.level.should == Log4r::DEBUG
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'can be reset' do
|
19
|
-
current_log = @logger.level
|
20
|
-
Batsir::Logger.reset
|
21
|
-
@logger.level.should_not == current_log
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'is able to use various log levels' do
|
25
|
-
@logger.level = Log4r::DEBUG
|
26
|
-
debug = @logger.debug("debug test message")
|
27
|
-
debug.should be_an Array
|
28
|
-
debug.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
|
29
|
-
|
30
|
-
info = @logger.info("info test message")
|
31
|
-
info.should be_an Array
|
32
|
-
info.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
|
33
|
-
|
34
|
-
warn = @logger.warn("warning test message")
|
35
|
-
warn.should be_an Array
|
36
|
-
warn.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
|
37
|
-
|
38
|
-
err = @logger.error("error test message")
|
39
|
-
err.should be_an Array
|
40
|
-
err.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
|
41
|
-
|
42
|
-
fatal = @logger.fatal("fatal test message")
|
43
|
-
fatal.should be_an Array
|
44
|
-
fatal.select{|e| e.is_a?(Log4r::StdoutOutputter)}.should_not be_empty
|
45
|
-
end
|
46
|
-
end
|
@@ -1,138 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
|
2
|
-
require File.join( File.dirname(__FILE__), 'shared_examples')
|
3
|
-
|
4
|
-
describe Batsir::Notifiers::AMQPNotifier do
|
5
|
-
let(:notifier_class){
|
6
|
-
Batsir::Notifiers::AMQPNotifier
|
7
|
-
}
|
8
|
-
|
9
|
-
def new_notifier(options = {})
|
10
|
-
notifier_class.new(options)
|
11
|
-
end
|
12
|
-
|
13
|
-
it_should_behave_like "a notifier", Batsir::Notifiers::AMQPNotifier
|
14
|
-
|
15
|
-
context "with respect to setting options" do
|
16
|
-
it "is a Batsir::Notifiers::Notifier" do
|
17
|
-
notifier_class.ancestors.should include Batsir::Notifiers::Notifier
|
18
|
-
end
|
19
|
-
|
20
|
-
it "can set the queue on which to listen" do
|
21
|
-
notifier = notifier_class.new(:queue => :queue)
|
22
|
-
notifier.queue.should == :queue
|
23
|
-
end
|
24
|
-
|
25
|
-
it "can set the host of the amqp broker" do
|
26
|
-
notifier = notifier_class.new(:host => 'localhost')
|
27
|
-
notifier.host.should == 'localhost'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "can set the port of the amqp broker" do
|
31
|
-
notifier = notifier_class.new(:port => 1234)
|
32
|
-
notifier.port.should == 1234
|
33
|
-
end
|
34
|
-
|
35
|
-
it "can set the username with which to connect to the broker" do
|
36
|
-
notifier = notifier_class.new(:username => 'some_user')
|
37
|
-
notifier.username.should == 'some_user'
|
38
|
-
end
|
39
|
-
|
40
|
-
it "can set the password with which to connect to the broker" do
|
41
|
-
notifier = notifier_class.new(:password => 'password')
|
42
|
-
notifier.password.should == 'password'
|
43
|
-
end
|
44
|
-
|
45
|
-
it "can set the vhost to use on the broker" do
|
46
|
-
notifier = notifier_class.new(:vhost => '/blah')
|
47
|
-
notifier.vhost.should == '/blah'
|
48
|
-
end
|
49
|
-
|
50
|
-
it "can set the exchange to use on the broker" do
|
51
|
-
notifier = notifier_class.new(:exchange => 'amq.direct')
|
52
|
-
notifier.exchange.should == 'amq.direct'
|
53
|
-
end
|
54
|
-
|
55
|
-
it "defaults to amqp://guest:guest@localhost:5672/ with direct exchange on vhost ''" do
|
56
|
-
notifier = notifier_class.new(:queue => :somequeue)
|
57
|
-
notifier.queue.should == :somequeue
|
58
|
-
notifier.host.should == 'localhost'
|
59
|
-
notifier.port.should == 5672
|
60
|
-
notifier.username.should == 'guest'
|
61
|
-
notifier.password.should == 'guest'
|
62
|
-
notifier.vhost.should == '/'
|
63
|
-
notifier.exchange.should == 'amq.direct'
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
context "with respect to notifying" do
|
68
|
-
before :each do
|
69
|
-
Batsir::Registry.reset
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'has an #execute method' do
|
73
|
-
notifier_class.instance_methods.map{|m| m.to_s}.should include "execute"
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'has a #handle_error method' do
|
77
|
-
notifier_class.instance_methods.map{|m| m.to_s}.should include "handle_error"
|
78
|
-
end
|
79
|
-
|
80
|
-
it "connects to the configured host" do
|
81
|
-
notifier = new_notifier(:host => 'somehost')
|
82
|
-
notifier.execute({})
|
83
|
-
instance = Bunny.instance
|
84
|
-
instance.options[:host].should == 'somehost'
|
85
|
-
end
|
86
|
-
|
87
|
-
it "connects to the configured port" do
|
88
|
-
notifier = new_notifier(:port => 1234)
|
89
|
-
notifier.execute({})
|
90
|
-
instance = Bunny.instance
|
91
|
-
instance.options[:port].should == 1234
|
92
|
-
end
|
93
|
-
|
94
|
-
it "connects with the configured username" do
|
95
|
-
notifier = new_notifier(:username => 'user')
|
96
|
-
notifier.execute({})
|
97
|
-
instance = Bunny.instance
|
98
|
-
instance.user.should == 'user'
|
99
|
-
end
|
100
|
-
|
101
|
-
it "connects with the configured password" do
|
102
|
-
notifier = new_notifier(:password => 'pass')
|
103
|
-
notifier.execute({})
|
104
|
-
instance = Bunny.instance
|
105
|
-
instance.options[:pass].should == 'pass'
|
106
|
-
end
|
107
|
-
|
108
|
-
it "connects to the configured vhost" do
|
109
|
-
notifier = new_notifier(:vhost => '/vhost')
|
110
|
-
notifier.execute({})
|
111
|
-
instance = Bunny.instance
|
112
|
-
instance.options[:vhost].should == '/vhost'
|
113
|
-
end
|
114
|
-
|
115
|
-
it "declares the configured exchange" do
|
116
|
-
notifier = new_notifier(:exchange => 'some_exchange')
|
117
|
-
notifier.execute({})
|
118
|
-
instance = Bunny.instance
|
119
|
-
instance.exchange.name.should == 'some_exchange'
|
120
|
-
end
|
121
|
-
|
122
|
-
it "binds the configured exchange to the queue and publish the message with the queue set as routing key" do
|
123
|
-
notifier = new_notifier(:exchange => 'some_exchange', :queue => :queue)
|
124
|
-
notifier.execute({})
|
125
|
-
instance = Bunny.instance
|
126
|
-
instance.exchange.name.should == 'some_exchange'
|
127
|
-
instance.exchange.message.should == {}
|
128
|
-
instance.exchange.key.should == :queue
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
context "with respect to error handling" do
|
133
|
-
it 'uses a strategy object to resolve notification errors' do
|
134
|
-
notifier = new_notifier(:exchange => 'some_exchange', :queue => :queue)
|
135
|
-
notifier.error_strategy.should be_a Batsir::Strategies::RetryStrategy
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
@@ -1,62 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
|
2
|
-
require File.join( File.dirname(__FILE__), 'shared_examples')
|
3
|
-
|
4
|
-
describe Batsir::Notifiers::ConditionalNotifier do
|
5
|
-
|
6
|
-
it_should_behave_like "a notifier", Batsir::Notifiers::ConditionalNotifier
|
7
|
-
|
8
|
-
true_block = ::Proc.new { |message| true }
|
9
|
-
|
10
|
-
let(:notifier){ Batsir::Notifiers::Notifier }
|
11
|
-
|
12
|
-
it "can add notifiers" do
|
13
|
-
subject.notifiers.size.should == 0
|
14
|
-
subject.add_notifier( true_block, notifier)
|
15
|
-
subject.notifiers.size.should == 1
|
16
|
-
end
|
17
|
-
|
18
|
-
it "stores notifier conditions" do
|
19
|
-
subject.add_notifier(true_block, notifier)
|
20
|
-
|
21
|
-
notifier_condition = subject.notifiers.first
|
22
|
-
notifier_condition.should be_a Batsir::Notifiers::ConditionalNotifier::NotifierCondition
|
23
|
-
notifier_condition.condition.should == true_block
|
24
|
-
notifier_condition.notifier.should == notifier
|
25
|
-
end
|
26
|
-
|
27
|
-
it "stores optional options for the notifier" do
|
28
|
-
subject.add_notifier( true_block, notifier, :some => :extra, :options => :foryou)
|
29
|
-
|
30
|
-
notifier_condition = subject.notifiers.first
|
31
|
-
notifier_condition.options.size.should == 2
|
32
|
-
notifier_condition.options.should have_key :some
|
33
|
-
notifier_condition.options.should have_key :options
|
34
|
-
end
|
35
|
-
|
36
|
-
context "sending messages" do
|
37
|
-
class FakeNotifier < Batsir::Notifiers::Notifier; end
|
38
|
-
|
39
|
-
it "executes notifiers if condition is true" do
|
40
|
-
|
41
|
-
notifier_class = FakeNotifier
|
42
|
-
notifier_class.any_instance.stub(:execute)
|
43
|
-
notifier_class.any_instance.should_receive(:execute)
|
44
|
-
|
45
|
-
conditional = Batsir::Notifiers::ConditionalNotifier.new
|
46
|
-
conditional.add_notifier( true_block, notifier_class.new({}) )
|
47
|
-
conditional.execute("some message")
|
48
|
-
end
|
49
|
-
|
50
|
-
it "does not execute when condition is false" do
|
51
|
-
false_block = lambda {|message| false}
|
52
|
-
|
53
|
-
notifier_class = FakeNotifier
|
54
|
-
notifier_class.any_instance.stub(:execute)
|
55
|
-
notifier_class.any_instance.should_not_receive(:execute)
|
56
|
-
|
57
|
-
conditional = Batsir::Notifiers::ConditionalNotifier.new
|
58
|
-
conditional.add_notifier( false_block, notifier_class.new({}) )
|
59
|
-
conditional.execute("some message")
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "..", "spec_helper" )
|
2
|
-
require File.join( File.dirname(__FILE__), 'shared_examples')
|
3
|
-
|
4
|
-
describe Batsir::Notifiers::Notifier do
|
5
|
-
|
6
|
-
it_should_behave_like "a notifier", Batsir::Notifiers::Notifier
|
7
|
-
|
8
|
-
it 'raises an error when the #execute method is not implemented' do
|
9
|
-
lambda{ subject.notify({})}.should raise_error NotImplementedError
|
10
|
-
end
|
11
|
-
end
|
@@ -1,100 +0,0 @@
|
|
1
|
-
shared_examples_for "a notifier" do |notifier_class|
|
2
|
-
before :each do
|
3
|
-
subject{notifier_class.new}
|
4
|
-
end
|
5
|
-
|
6
|
-
context 'transformers' do
|
7
|
-
it "has a transformer_queue" do
|
8
|
-
subject.transformer_queue.should_not be_nil
|
9
|
-
end
|
10
|
-
|
11
|
-
it "initially has an empty transformer_queue" do
|
12
|
-
subject.transformer_queue.should_not be_nil
|
13
|
-
subject.transformer_queue.should be_empty
|
14
|
-
end
|
15
|
-
|
16
|
-
it "can add a transformer to the transformer_queue" do
|
17
|
-
transformer = :transformer
|
18
|
-
|
19
|
-
subject.add_transformer transformer
|
20
|
-
|
21
|
-
subject.transformer_queue.should_not be_empty
|
22
|
-
subject.transformer_queue.size.should == 1
|
23
|
-
subject.transformer_queue.first.should == :transformer
|
24
|
-
end
|
25
|
-
|
26
|
-
it "can add a transformer multiple times" do
|
27
|
-
transformer = :transformer
|
28
|
-
|
29
|
-
subject.add_transformer transformer
|
30
|
-
subject.add_transformer transformer
|
31
|
-
|
32
|
-
subject.transformer_queue.should_not be_empty
|
33
|
-
subject.transformer_queue.size.should == 2
|
34
|
-
end
|
35
|
-
|
36
|
-
it "creates a FieldTransformer when the 'fields' option is given during initialization" do
|
37
|
-
fields = {:foo => :bar}
|
38
|
-
subject = notifier_class.new(:fields => fields)
|
39
|
-
subject.transformer_queue.should_not be_empty
|
40
|
-
subject.transformer_queue.first.class.should == Batsir::Transformers::FieldTransformer
|
41
|
-
subject.transformer_queue.first.fields.should == fields
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
context 'methods calls' do
|
46
|
-
it "has an #execute method" do
|
47
|
-
notifier_class.instance_methods.map{|m| m.to_s}.should include "execute"
|
48
|
-
end
|
49
|
-
|
50
|
-
|
51
|
-
it "calls #transform when #notify is called" do
|
52
|
-
subject.stub(:execute)
|
53
|
-
subject.should_receive(:transform).with({})
|
54
|
-
subject.notify({})
|
55
|
-
end
|
56
|
-
|
57
|
-
it "calls #transform on all transformers when #transform is called" do
|
58
|
-
class MockTransformer < Batsir::Transformers::Transformer
|
59
|
-
end
|
60
|
-
|
61
|
-
subject.stub(:execute)
|
62
|
-
transformer = MockTransformer.new
|
63
|
-
subject.add_transformer transformer
|
64
|
-
subject.transformer_queue.size.should == 1
|
65
|
-
|
66
|
-
transformer.should_receive(:transform).with({})
|
67
|
-
subject.notify({})
|
68
|
-
end
|
69
|
-
|
70
|
-
it "calls #execute when #notify is called" do
|
71
|
-
subject.stub(:execute)
|
72
|
-
subject.should_receive(:execute)
|
73
|
-
subject.notify({})
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
context 'message unmodified' do
|
78
|
-
it 'has no transformers' do
|
79
|
-
message = {'test_id' => 123}
|
80
|
-
subject.add_transformer(Batsir::Transformers::JSONOutputTransformer.new)
|
81
|
-
begin
|
82
|
-
subject.notify(message).should == {'test_id' => 123}
|
83
|
-
rescue NotImplementedError => e
|
84
|
-
end
|
85
|
-
message.should == {'test_id' => 123}
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'has a FieldTransformer' do
|
89
|
-
fields = {:foo => 'bar', 'test_id' => 'test'}
|
90
|
-
message = {'test_id' => 123}
|
91
|
-
subject = notifier_class.new(:fields => fields)
|
92
|
-
subject.add_transformer(Batsir::Transformers::JSONOutputTransformer.new)
|
93
|
-
begin
|
94
|
-
subject.notify(message).should == {'test_id' => 123}
|
95
|
-
rescue NotImplementedError => e
|
96
|
-
end
|
97
|
-
message.should == {'test_id' => 123}
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
require File.join( File.dirname(__FILE__), "..", "spec_helper" )
|
2
|
-
|
3
|
-
describe Batsir::Registry do
|
4
|
-
|
5
|
-
before :all do
|
6
|
-
@class = Batsir::Registry
|
7
|
-
end
|
8
|
-
|
9
|
-
before :each do
|
10
|
-
@class.reset
|
11
|
-
end
|
12
|
-
|
13
|
-
it "outputs the whole registry" do
|
14
|
-
@class.registry.should == {}
|
15
|
-
end
|
16
|
-
|
17
|
-
it "registers a value" do
|
18
|
-
@class.register(:foo, :bar)
|
19
|
-
@class.registry.keys.size.should == 1
|
20
|
-
@class.registry.keys.should include :foo
|
21
|
-
@class.registry.values.size.should == 1
|
22
|
-
@class.registry.values.should include :bar
|
23
|
-
end
|
24
|
-
|
25
|
-
it "is able to retrieve a registered variable" do
|
26
|
-
@class.register('test', 'value')
|
27
|
-
@class.get('test').should == 'value'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "returns nil when the requested key is not found" do
|
31
|
-
@class.get('foobar').should be_nil
|
32
|
-
end
|
33
|
-
|
34
|
-
context "resetting" do
|
35
|
-
it "is possible" do
|
36
|
-
@class.register('foo', 'bar')
|
37
|
-
@class.registry.should == {'foo' => 'bar'}
|
38
|
-
@class.reset
|
39
|
-
@class.registry.should == {}
|
40
|
-
end
|
41
|
-
|
42
|
-
it "returns its new state" do
|
43
|
-
@class.register('foo', 'bar')
|
44
|
-
result = @class.reset
|
45
|
-
result.should == {}
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|