rabbit_feed 2.4.4 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +81 -0
- data/README.md +39 -5
- data/Rakefile +3 -19
- data/bin/rabbit_feed +0 -1
- data/example/non_rails_app/Gemfile.lock +29 -32
- data/example/non_rails_app/Rakefile +1 -1
- data/example/non_rails_app/bin/benchmark +3 -3
- data/example/non_rails_app/lib/non_rails_app/event_handler.rb +1 -1
- data/example/non_rails_app/spec/lib/non_rails_app/event_handler_spec.rb +3 -4
- data/example/non_rails_app/spec/lib/non_rails_app/event_routing_spec.rb +3 -3
- data/example/rails_app/Gemfile +4 -16
- data/example/rails_app/Gemfile.lock +131 -137
- data/example/rails_app/app/assets/javascripts/application.js +0 -1
- data/example/rails_app/app/controllers/application_controller.rb +0 -3
- data/example/rails_app/app/controllers/beavers_controller.rb +14 -15
- data/example/rails_app/bin/rails +1 -1
- data/example/rails_app/config/environments/development.rb +1 -1
- data/example/rails_app/config/environments/test.rb +2 -2
- data/example/rails_app/config/initializers/cookies_serializer.rb +1 -1
- data/example/rails_app/config/unicorn.rb +1 -1
- data/example/rails_app/config.ru +1 -1
- data/example/rails_app/db/schema.rb +5 -7
- data/example/rails_app/lib/event_handler.rb +1 -1
- data/example/rails_app/spec/controllers/beavers_controller_spec.rb +9 -10
- data/example/rails_app/spec/event_routing_spec.rb +1 -2
- data/example/rails_app/test/controllers/beavers_controller_test.rb +12 -12
- data/lib/dsl.rb +4 -4
- data/lib/rabbit_feed/client.rb +17 -23
- data/lib/rabbit_feed/configuration.rb +10 -9
- data/lib/rabbit_feed/connection.rb +3 -3
- data/lib/rabbit_feed/console_consumer.rb +22 -24
- data/lib/rabbit_feed/consumer.rb +2 -2
- data/lib/rabbit_feed/consumer_connection.rb +21 -22
- data/lib/rabbit_feed/event.rb +8 -28
- data/lib/rabbit_feed/event_definitions.rb +14 -15
- data/lib/rabbit_feed/event_routing.rb +26 -27
- data/lib/rabbit_feed/json_log_formatter.rb +1 -1
- data/lib/rabbit_feed/producer.rb +13 -13
- data/lib/rabbit_feed/producer_connection.rb +8 -9
- data/lib/rabbit_feed/testing_support/rspec_matchers/publish_event.rb +52 -89
- data/lib/rabbit_feed/testing_support/test_rabbit_feed_consumer.rb +1 -2
- data/lib/rabbit_feed/testing_support/testing_helpers.rb +0 -1
- data/lib/rabbit_feed/testing_support.rb +5 -6
- data/lib/rabbit_feed/version.rb +1 -1
- data/lib/rabbit_feed.rb +12 -13
- data/rabbit_feed.gemspec +16 -14
- data/run_benchmark +4 -3
- data/run_example +1 -1
- data/spec/features/step_definitions/connectivity_steps.rb +6 -9
- data/spec/lib/rabbit_feed/client_spec.rb +8 -9
- data/spec/lib/rabbit_feed/configuration_spec.rb +20 -23
- data/spec/lib/rabbit_feed/console_consumer_spec.rb +11 -13
- data/spec/lib/rabbit_feed/consumer_connection_spec.rb +26 -28
- data/spec/lib/rabbit_feed/event_definitions_spec.rb +31 -31
- data/spec/lib/rabbit_feed/event_routing_spec.rb +35 -62
- data/spec/lib/rabbit_feed/event_spec.rb +40 -87
- data/spec/lib/rabbit_feed/producer_connection_spec.rb +11 -7
- data/spec/lib/rabbit_feed/producer_spec.rb +16 -19
- data/spec/lib/rabbit_feed/testing_support/rspec_matchers/publish_event_spec.rb +82 -87
- data/spec/lib/rabbit_feed/testing_support/testing_helper_spec.rb +2 -2
- data/spec/spec_helper.rb +4 -10
- metadata +67 -45
- data/example/rails_app/README.rdoc +0 -28
@@ -5,7 +5,7 @@ module RabbitFeed
|
|
5
5
|
let(:pidfile) { './test.pid' }
|
6
6
|
let(:config_file) { 'spec/fixtures/configuration.yml' }
|
7
7
|
let(:environment) { 'test' }
|
8
|
-
let(:require_file){ 'rabbit_feed.rb' }
|
8
|
+
let(:require_file) { 'rabbit_feed.rb' }
|
9
9
|
let(:application) { 'rabbit_feed_test' }
|
10
10
|
let(:arguments) do
|
11
11
|
[
|
@@ -31,10 +31,9 @@ module RabbitFeed
|
|
31
31
|
RabbitFeed.log = nil
|
32
32
|
RabbitFeed.configuration_file_path = nil
|
33
33
|
end
|
34
|
-
subject{ described_class.new arguments }
|
34
|
+
subject { described_class.new arguments }
|
35
35
|
|
36
36
|
describe '.new' do
|
37
|
-
|
38
37
|
it { should be_valid }
|
39
38
|
|
40
39
|
it 'sets the environment' do
|
@@ -61,7 +60,7 @@ module RabbitFeed
|
|
61
60
|
let(:command) { 'blah' }
|
62
61
|
|
63
62
|
it 'should be invalid' do
|
64
|
-
expect{subject}.to raise_error Error
|
63
|
+
expect { subject }.to raise_error Error
|
65
64
|
end
|
66
65
|
end
|
67
66
|
|
@@ -69,7 +68,7 @@ module RabbitFeed
|
|
69
68
|
let(:logfile) { '/blah/blah.log' }
|
70
69
|
|
71
70
|
it 'should be invalid' do
|
72
|
-
expect{subject}.to raise_error Error
|
71
|
+
expect { subject }.to raise_error Error
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
@@ -77,7 +76,7 @@ module RabbitFeed
|
|
77
76
|
let(:pidfile) { '/blah/blah.pid' }
|
78
77
|
|
79
78
|
it 'should be invalid' do
|
80
|
-
expect{subject}.to raise_error Error
|
79
|
+
expect { subject }.to raise_error Error
|
81
80
|
end
|
82
81
|
end
|
83
82
|
|
@@ -85,7 +84,7 @@ module RabbitFeed
|
|
85
84
|
let(:config_file) { '/blah/blah.yml' }
|
86
85
|
|
87
86
|
it 'should be invalid' do
|
88
|
-
expect{subject}.to raise_error Error
|
87
|
+
expect { subject }.to raise_error Error
|
89
88
|
end
|
90
89
|
end
|
91
90
|
|
@@ -97,7 +96,7 @@ module RabbitFeed
|
|
97
96
|
end
|
98
97
|
|
99
98
|
it 'should be invalid' do
|
100
|
-
expect{subject}.to raise_error Error
|
99
|
+
expect { subject }.to raise_error Error
|
101
100
|
end
|
102
101
|
|
103
102
|
context 'when the RAILS_ENV is present' do
|
@@ -115,7 +114,7 @@ module RabbitFeed
|
|
115
114
|
let(:require_file) { './' }
|
116
115
|
|
117
116
|
it 'should be invalid' do
|
118
|
-
expect{subject}.to raise_error Error
|
117
|
+
expect { subject }.to raise_error Error
|
119
118
|
end
|
120
119
|
end
|
121
120
|
end
|
@@ -1,11 +1,10 @@
|
|
1
1
|
module RabbitFeed
|
2
2
|
describe Configuration do
|
3
|
-
|
4
3
|
describe '#queue' do
|
5
4
|
let(:options) do
|
6
5
|
{
|
7
6
|
application: 'rabbit_feed',
|
8
|
-
environment: 'test'
|
7
|
+
environment: 'test'
|
9
8
|
}
|
10
9
|
end
|
11
10
|
subject { (described_class.new options).queue }
|
@@ -13,13 +12,13 @@ module RabbitFeed
|
|
13
12
|
it { should eq 'test.rabbit_feed' }
|
14
13
|
|
15
14
|
context 'when a route_prefix_extension is set' do
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
let(:options) do
|
16
|
+
{
|
17
|
+
application: 'rabbit_feed',
|
18
|
+
environment: 'test',
|
19
|
+
route_prefix_extension: 'foobar'
|
20
|
+
}
|
21
|
+
end
|
23
22
|
|
24
23
|
it { should eq 'test.foobar.rabbit_feed' }
|
25
24
|
end
|
@@ -32,7 +31,7 @@ module RabbitFeed
|
|
32
31
|
let(:options) do
|
33
32
|
{
|
34
33
|
application: 'rabbit_feed',
|
35
|
-
environment: 'test'
|
34
|
+
environment: 'test'
|
36
35
|
}
|
37
36
|
end
|
38
37
|
|
@@ -59,7 +58,7 @@ module RabbitFeed
|
|
59
58
|
user: 'guest',
|
60
59
|
password: 'guest',
|
61
60
|
port: 1234,
|
62
|
-
network_recovery_interval: 1
|
61
|
+
network_recovery_interval: 1
|
63
62
|
}
|
64
63
|
end
|
65
64
|
|
@@ -79,14 +78,14 @@ module RabbitFeed
|
|
79
78
|
describe '.load' do
|
80
79
|
let(:file_path) { 'spec/fixtures/configuration.yml' }
|
81
80
|
let(:environment) { 'test_config' }
|
82
|
-
let(:application) {
|
81
|
+
let(:application) {}
|
83
82
|
subject { described_class.load file_path, environment, application }
|
84
83
|
|
85
84
|
context 'with missing configuration' do
|
86
85
|
let(:environment) { 'production' }
|
87
86
|
|
88
87
|
it 'raises an error' do
|
89
|
-
expect{ subject }.to raise_error ConfigurationError
|
88
|
+
expect { subject }.to raise_error ConfigurationError
|
90
89
|
end
|
91
90
|
end
|
92
91
|
|
@@ -94,12 +93,11 @@ module RabbitFeed
|
|
94
93
|
let(:file_path) { 'I do not exist' }
|
95
94
|
|
96
95
|
it 'raises an error' do
|
97
|
-
expect{ subject }.to raise_error ConfigurationError
|
96
|
+
expect { subject }.to raise_error ConfigurationError
|
98
97
|
end
|
99
98
|
end
|
100
99
|
|
101
100
|
context 'with configuration' do
|
102
|
-
|
103
101
|
its(:host) { should eq 'localhost' }
|
104
102
|
its(:port) { should eq 5672 }
|
105
103
|
its(:user) { should eq 'guest' }
|
@@ -132,14 +130,14 @@ module RabbitFeed
|
|
132
130
|
end
|
133
131
|
|
134
132
|
describe '.new' do
|
135
|
-
let(:options) {{}}
|
133
|
+
let(:options) { {} }
|
136
134
|
subject { described_class.new options }
|
137
135
|
|
138
136
|
context 'with default options' do
|
139
137
|
let(:options) do
|
140
138
|
{
|
141
139
|
application: 'rabbit_feed',
|
142
|
-
environment: 'test'
|
140
|
+
environment: 'test'
|
143
141
|
}
|
144
142
|
end
|
145
143
|
|
@@ -161,8 +159,8 @@ module RabbitFeed
|
|
161
159
|
let(:options) do
|
162
160
|
{
|
163
161
|
host: 'host_name',
|
164
|
-
hosts:
|
165
|
-
port:
|
162
|
+
hosts: %w(host_name0 host_name1),
|
163
|
+
port: 12_345,
|
166
164
|
user: 'user_name',
|
167
165
|
password: 'password',
|
168
166
|
application: 'rabbit_feed',
|
@@ -178,8 +176,8 @@ module RabbitFeed
|
|
178
176
|
end
|
179
177
|
|
180
178
|
its(:host) { should eq 'host_name' }
|
181
|
-
its(:hosts) { should eq
|
182
|
-
its(:port) { should eq
|
179
|
+
its(:hosts) { should eq %w(host_name0 host_name1) }
|
180
|
+
its(:port) { should eq 12_345 }
|
183
181
|
its(:user) { should eq 'user_name' }
|
184
182
|
its(:password) { should eq 'password' }
|
185
183
|
its(:application) { should eq 'rabbit_feed' }
|
@@ -194,9 +192,8 @@ module RabbitFeed
|
|
194
192
|
end
|
195
193
|
|
196
194
|
context 'with empty options' do
|
197
|
-
|
198
195
|
it 'should raise an error' do
|
199
|
-
expect{ subject }.to raise_error ConfigurationError
|
196
|
+
expect { subject }.to raise_error ConfigurationError
|
200
197
|
end
|
201
198
|
end
|
202
199
|
end
|
@@ -11,22 +11,19 @@ module RabbitFeed
|
|
11
11
|
end
|
12
12
|
|
13
13
|
describe '#init' do
|
14
|
-
|
15
14
|
it 'prints a welcome message' do
|
16
|
-
expect{ subject.init }.to output(
|
17
|
-
/RabbitFeed console starting at .* UTC
|
18
|
-
|
19
|
-
Queue: test\.rabbit_feed_console
|
20
|
-
Ready\. Press CTRL\+C to exit\./).to_stdout
|
15
|
+
expect { subject.init }.to output(
|
16
|
+
/RabbitFeed console starting at .* UTC\.\.\.\nEnvironment: test\nQueue: test\.rabbit_feed_console\nReady\. Press CTRL\+C to exit\./
|
17
|
+
).to_stdout
|
21
18
|
end
|
22
19
|
|
23
20
|
context 'when there are events on the rabbit_feed_console queue' do
|
24
21
|
let(:queue_depth) { 1 }
|
25
22
|
|
26
23
|
it 'asks to purge the queue' do
|
27
|
-
expect{ subject.init }.to output(
|
28
|
-
|
29
|
-
|
24
|
+
expect { subject.init }.to output(
|
25
|
+
%r{There are currently 1 message\(s\) in the console's queue\.\nWould you like to purge the queue before proceeding\? \(y\/N\)>}
|
26
|
+
).to_stdout
|
30
27
|
end
|
31
28
|
|
32
29
|
context 'when the user wishes to purge the queue' do
|
@@ -34,18 +31,18 @@ Would you like to purge the queue before proceeding\? \(y\/N\)>/).to_stdout
|
|
34
31
|
|
35
32
|
it 'purges the queue' do
|
36
33
|
expect(connection).to receive(:purge_queue)
|
37
|
-
expect{ subject.init }.to output(/Queue purged\./).to_stdout
|
34
|
+
expect { subject.init }.to output(/Queue purged\./).to_stdout
|
38
35
|
end
|
39
36
|
end
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
43
40
|
describe 'receiving an event' do
|
44
|
-
let(:event) { Event.new({name: 'name'},
|
41
|
+
let(:event) { Event.new({ name: 'name' }, key: :value) }
|
45
42
|
before { subject.init }
|
46
43
|
|
47
44
|
it 'prints the event' do
|
48
|
-
expect{ rabbit_feed_consumer.consume_event event }.to output(
|
45
|
+
expect { rabbit_feed_consumer.consume_event event }.to output(
|
49
46
|
/-----------------------------------------------name: -----------------------------------------------
|
50
47
|
#Event metadata
|
51
48
|
name: name
|
@@ -53,7 +50,8 @@ name: name
|
|
53
50
|
#Event payload
|
54
51
|
key: value
|
55
52
|
----------------------------------------------------------------------------------------------------
|
56
|
-
1 events received\./
|
53
|
+
1 events received\./
|
54
|
+
).to_stdout
|
57
55
|
end
|
58
56
|
end
|
59
57
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module RabbitFeed
|
2
2
|
describe ConsumerConnection do
|
3
|
-
let(:bunny_queue) { double(:bunny_queue, bind: nil, subscribe: nil)}
|
4
|
-
let(:bunny_channel) { double(:bunny_channel, prefetch: nil, nack: nil, ack: nil, queue: bunny_queue, id: 1)}
|
3
|
+
let(:bunny_queue) { double(:bunny_queue, bind: nil, subscribe: nil) }
|
4
|
+
let(:bunny_channel) { double(:bunny_channel, prefetch: nil, nack: nil, ack: nil, queue: bunny_queue, id: 1) }
|
5
5
|
let(:bunny_connection) { double(:bunny_connection, start: nil, closed?: false, close: nil, create_channel: bunny_channel) }
|
6
6
|
before do
|
7
7
|
allow(Bunny).to receive(:new).and_return(bunny_connection)
|
@@ -15,13 +15,13 @@ module RabbitFeed
|
|
15
15
|
before do
|
16
16
|
EventRouting do
|
17
17
|
accept_from('rabbit_feed') do
|
18
|
-
event('test') {|event|}
|
18
|
+
event('test') { |event| }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'binds the queue to the exchange' do
|
24
|
-
expect(bunny_queue).to receive(:bind).with('amq.topic',
|
24
|
+
expect(bunny_queue).to receive(:bind).with('amq.topic', routing_key: 'test.rabbit_feed.test')
|
25
25
|
subject
|
26
26
|
end
|
27
27
|
|
@@ -36,8 +36,7 @@ module RabbitFeed
|
|
36
36
|
|
37
37
|
it 'appends the route_prefix_extension to the routing_key' do
|
38
38
|
expect(bunny_queue).to receive(:bind).with('amq.topic',
|
39
|
-
|
40
|
-
)
|
39
|
+
routing_key: 'test_route_prefix_extension.foobar.rabbit_feed.test')
|
41
40
|
subject
|
42
41
|
end
|
43
42
|
end
|
@@ -51,34 +50,33 @@ module RabbitFeed
|
|
51
50
|
end
|
52
51
|
|
53
52
|
it 'yields the payload' do
|
54
|
-
subject.consume { |payload| payload.should eq 'payload'}
|
53
|
+
subject.consume { |payload| payload.should eq 'payload' }
|
55
54
|
end
|
56
55
|
|
57
56
|
it 'acknowledges the message' do
|
58
57
|
expect(bunny_channel).to receive(:ack)
|
59
|
-
subject.consume {
|
58
|
+
subject.consume {}
|
60
59
|
end
|
61
60
|
|
62
61
|
it 'is synchronized' do
|
63
62
|
expect(subject).to receive(:synchronized).and_call_original
|
64
|
-
subject.consume {
|
63
|
+
subject.consume {}
|
65
64
|
end
|
66
65
|
|
67
66
|
it 'cancels the consumer' do
|
68
67
|
expect_any_instance_of(described_class).to receive(:cancel_consumer)
|
69
|
-
subject.consume {
|
68
|
+
subject.consume {}
|
70
69
|
end
|
71
70
|
|
72
71
|
context 'when consuming' do
|
73
72
|
before { allow(subject.send(:mutex)).to receive(:locked?).and_return(true) }
|
74
73
|
|
75
74
|
it 'raises when attempting to consume in parallel' do
|
76
|
-
expect{ subject.consume {
|
75
|
+
expect { subject.consume {} }.to raise_error 'This connection already has a consumer subscribed'
|
77
76
|
end
|
78
77
|
end
|
79
78
|
|
80
79
|
context 'when an exception is raised' do
|
81
|
-
|
82
80
|
context 'when the exception is' do
|
83
81
|
[SystemExit.new, Interrupt.new, SignalException.new('SIGTERM')].each do |exception|
|
84
82
|
context exception.to_s do
|
@@ -86,7 +84,6 @@ module RabbitFeed
|
|
86
84
|
test_logger_string_io = StringIO.new
|
87
85
|
logger = Logger.new test_logger_string_io
|
88
86
|
logger.formatter = RabbitFeed::JsonLogFormatter
|
89
|
-
old_logger = RabbitFeed.log
|
90
87
|
RabbitFeed.log = logger
|
91
88
|
test_logger_string_io
|
92
89
|
end
|
@@ -94,15 +91,14 @@ module RabbitFeed
|
|
94
91
|
before { allow(subject).to receive(:handle_message).and_raise(exception) }
|
95
92
|
|
96
93
|
it 'does not re-raise error' do
|
97
|
-
expect { subject.consume {
|
94
|
+
expect { subject.consume {} }.to_not raise_error
|
98
95
|
end
|
99
96
|
|
100
97
|
it 'logs unsubscribe_from_queue' do
|
101
|
-
subject.consume {
|
98
|
+
subject.consume {}
|
102
99
|
|
103
|
-
expect(logger.string).to match
|
100
|
+
expect(logger.string).to match(/unsubscribe_from_queue/)
|
104
101
|
end
|
105
|
-
|
106
102
|
end
|
107
103
|
end
|
108
104
|
end
|
@@ -116,17 +112,20 @@ module RabbitFeed
|
|
116
112
|
end
|
117
113
|
end
|
118
114
|
|
119
|
-
|
120
115
|
context 'when consumer_exit_after_fail is false' do
|
121
116
|
before { allow(RabbitFeed.configuration).to receive(:consumer_exit_after_fail).and_return(false) }
|
122
117
|
|
123
118
|
context 'when Airbrake is defined' do
|
124
|
-
after
|
119
|
+
after do
|
120
|
+
begin
|
121
|
+
Object.send(:remove_const, 'Airbrake'.to_sym)
|
122
|
+
rescue NameError; end
|
123
|
+
end
|
125
124
|
|
126
125
|
context 'when the version is lower than 5' do
|
127
126
|
before do
|
128
127
|
module ::Airbrake
|
129
|
-
VERSION = '4.0.0'
|
128
|
+
VERSION = '4.0.0'.freeze
|
130
129
|
end
|
131
130
|
allow(Airbrake).to receive(:configuration).and_return(airbrake_configuration)
|
132
131
|
end
|
@@ -135,9 +134,9 @@ module RabbitFeed
|
|
135
134
|
let(:airbrake_configuration) { double(:airbrake_configuration, public?: true) }
|
136
135
|
|
137
136
|
it 'notifies airbrake' do
|
138
|
-
expect(Airbrake).to receive(:notify_or_ignore).with(an_instance_of
|
137
|
+
expect(Airbrake).to receive(:notify_or_ignore).with(an_instance_of(RuntimeError))
|
139
138
|
|
140
|
-
expect{ subject.consume { raise 'Consuming time' } }.not_to raise_error
|
139
|
+
expect { subject.consume { raise 'Consuming time' } }.not_to raise_error
|
141
140
|
end
|
142
141
|
end
|
143
142
|
end
|
@@ -145,23 +144,23 @@ module RabbitFeed
|
|
145
144
|
context 'when the version is greater than 4' do
|
146
145
|
before do
|
147
146
|
module ::Airbrake
|
148
|
-
AIRBRAKE_VERSION = '5.0.0'
|
147
|
+
AIRBRAKE_VERSION = '5.0.0'.freeze
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
152
151
|
context 'and consumer_exit_after_fail is true' do
|
153
152
|
before { allow(RabbitFeed.configuration).to receive(:consumer_exit_after_fail).and_return(true) }
|
154
153
|
it 'notifies airbrake synchronously' do
|
155
|
-
expect(Airbrake).to receive(:notify_sync).with(an_instance_of
|
156
|
-
expect{ subject.consume { raise 'Consuming time' } }.not_to raise_error
|
154
|
+
expect(Airbrake).to receive(:notify_sync).with(an_instance_of(RuntimeError))
|
155
|
+
expect { subject.consume { raise 'Consuming time' } }.not_to raise_error
|
157
156
|
end
|
158
157
|
end
|
159
158
|
|
160
159
|
context 'and consumer_exit_after_fail is not true' do
|
161
160
|
before { allow(RabbitFeed.configuration).to receive(:consumer_exit_after_fail).and_return(false) }
|
162
161
|
it 'notifies airbrake' do
|
163
|
-
expect(Airbrake).to receive(:notify).with(an_instance_of
|
164
|
-
expect{ subject.consume { raise 'Consuming time' } }.not_to raise_error
|
162
|
+
expect(Airbrake).to receive(:notify).with(an_instance_of(RuntimeError))
|
163
|
+
expect { subject.consume { raise 'Consuming time' } }.not_to raise_error
|
165
164
|
end
|
166
165
|
end
|
167
166
|
end
|
@@ -172,7 +171,6 @@ module RabbitFeed
|
|
172
171
|
subject.consume { raise 'Consuming time' }
|
173
172
|
end
|
174
173
|
end
|
175
|
-
|
176
174
|
end
|
177
175
|
end
|
178
176
|
end
|
@@ -19,7 +19,7 @@ module RabbitFeed
|
|
19
19
|
it { should_not be_nil }
|
20
20
|
it { should be_valid }
|
21
21
|
its(:name) { should eq 'customer_purchases_policy' }
|
22
|
-
its(:sensitive_fields) { should match_array(
|
22
|
+
its(:sensitive_fields) { should match_array(%w(price policy_id)) }
|
23
23
|
|
24
24
|
describe EventDefinitions::Event do
|
25
25
|
let(:name) { 'event_name' }
|
@@ -31,7 +31,7 @@ module RabbitFeed
|
|
31
31
|
definition
|
32
32
|
end
|
33
33
|
event.payload_contains do
|
34
|
-
field 'field',
|
34
|
+
field 'field', type: 'string', definition: 'field definition'
|
35
35
|
end
|
36
36
|
end
|
37
37
|
end
|
@@ -39,30 +39,30 @@ module RabbitFeed
|
|
39
39
|
it { should be_valid }
|
40
40
|
its(:fields) { should_not be_empty }
|
41
41
|
its(:schema) { should be_a Avro::Schema }
|
42
|
-
its(:metadata_schema)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
its(:payload_schema)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
42
|
+
its(:metadata_schema) do
|
43
|
+
should eq(name: 'event_metadata',
|
44
|
+
type: 'record',
|
45
|
+
fields: [
|
46
|
+
{ name: 'application', type: 'string', doc: 'The name of the application that created the event' },
|
47
|
+
{ name: 'host', type: 'string', doc: 'The hostname of the server on which the event was created' },
|
48
|
+
{ name: 'environment', type: 'string', doc: 'The environment in which the event was created' },
|
49
|
+
{ name: 'version', type: 'string', doc: 'The version of the event payload' },
|
50
|
+
{ name: 'schema_version', type: 'string', doc: 'The version of the event schema' },
|
51
|
+
{ name: 'name', type: 'string', doc: 'The name of the event' },
|
52
|
+
{ name: 'created_at_utc', type: 'string', doc: 'The UTC time that the event was created' }
|
53
|
+
])
|
54
|
+
end
|
55
|
+
its(:payload_schema) do
|
56
|
+
should eq(name: 'event_name_payload',
|
57
|
+
type: 'record',
|
58
|
+
fields: [{ name: 'field', type: 'string', doc: 'field definition' }])
|
59
|
+
end
|
60
|
+
its(:event_schema) do
|
61
|
+
should match([
|
62
|
+
{ name: 'payload', type: an_instance_of(Hash), doc: 'The event payload (defined by the source system)' },
|
63
|
+
{ name: 'metadata', type: an_instance_of(Hash), doc: 'The event metadata (defined by rabbit feed)' }
|
64
|
+
])
|
65
|
+
end
|
66
66
|
|
67
67
|
context 'when the name is nil' do
|
68
68
|
let(:name) {}
|
@@ -99,16 +99,16 @@ module RabbitFeed
|
|
99
99
|
let(:name) { 'event_name' }
|
100
100
|
let(:type) { 'string' }
|
101
101
|
let(:definition) { 'event definition' }
|
102
|
-
subject{ EventDefinitions::Field.new name, type, definition }
|
102
|
+
subject { EventDefinitions::Field.new name, type, definition }
|
103
103
|
|
104
104
|
it { should be_valid }
|
105
|
-
its(:schema) { should eq(
|
105
|
+
its(:schema) { should eq(name: name, type: type, doc: definition) }
|
106
106
|
|
107
107
|
context 'when the name is nil' do
|
108
108
|
let(:name) {}
|
109
109
|
|
110
110
|
it 'raises a configuration error' do
|
111
|
-
expect{ subject }.to raise_error ConfigurationError
|
111
|
+
expect { subject }.to raise_error ConfigurationError
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
@@ -116,7 +116,7 @@ module RabbitFeed
|
|
116
116
|
let(:type) {}
|
117
117
|
|
118
118
|
it 'raises a configuration error' do
|
119
|
-
expect{ subject }.to raise_error ConfigurationError
|
119
|
+
expect { subject }.to raise_error ConfigurationError
|
120
120
|
end
|
121
121
|
end
|
122
122
|
|
@@ -124,7 +124,7 @@ module RabbitFeed
|
|
124
124
|
let(:definition) {}
|
125
125
|
|
126
126
|
it 'raises a configuration error' do
|
127
|
-
expect{ subject }.to raise_error ConfigurationError
|
127
|
+
expect { subject }.to raise_error ConfigurationError
|
128
128
|
end
|
129
129
|
end
|
130
130
|
end
|