shivam 0.0.0-java

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 (81) hide show
  1. checksums.yaml +7 -0
  2. data/.github/workflows/test.yml +57 -0
  3. data/.gitignore +10 -0
  4. data/.rspec +1 -0
  5. data/.yardopts +5 -0
  6. data/CHANGELOG.md +899 -0
  7. data/Gemfile +35 -0
  8. data/Guardfile +14 -0
  9. data/LICENSE +23 -0
  10. data/README.md +679 -0
  11. data/Rakefile +21 -0
  12. data/bin/ci/before_build.sh +20 -0
  13. data/bin/ci/before_build_docker.sh +20 -0
  14. data/bin/ci/install_on_debian.sh +46 -0
  15. data/bin/hutch +8 -0
  16. data/examples/consumer.rb +13 -0
  17. data/examples/producer.rb +10 -0
  18. data/hutch.gemspec +27 -0
  19. data/lib/hutch/acknowledgements/base.rb +16 -0
  20. data/lib/hutch/acknowledgements/nack_on_all_failures.rb +19 -0
  21. data/lib/hutch/adapter.rb +11 -0
  22. data/lib/hutch/adapters/bunny.rb +37 -0
  23. data/lib/hutch/adapters/march_hare.rb +41 -0
  24. data/lib/hutch/broker.rb +384 -0
  25. data/lib/hutch/cli.rb +246 -0
  26. data/lib/hutch/config.rb +305 -0
  27. data/lib/hutch/consumer.rb +125 -0
  28. data/lib/hutch/error_handlers/airbrake.rb +54 -0
  29. data/lib/hutch/error_handlers/base.rb +15 -0
  30. data/lib/hutch/error_handlers/bugsnag.rb +30 -0
  31. data/lib/hutch/error_handlers/honeybadger.rb +43 -0
  32. data/lib/hutch/error_handlers/logger.rb +22 -0
  33. data/lib/hutch/error_handlers/rollbar.rb +28 -0
  34. data/lib/hutch/error_handlers/sentry.rb +26 -0
  35. data/lib/hutch/error_handlers/sentry_raven.rb +31 -0
  36. data/lib/hutch/error_handlers.rb +11 -0
  37. data/lib/hutch/exceptions.rb +14 -0
  38. data/lib/hutch/logging.rb +32 -0
  39. data/lib/hutch/message.rb +31 -0
  40. data/lib/hutch/publisher.rb +75 -0
  41. data/lib/hutch/serializers/identity.rb +19 -0
  42. data/lib/hutch/serializers/json.rb +22 -0
  43. data/lib/hutch/tracers/datadog.rb +18 -0
  44. data/lib/hutch/tracers/newrelic.rb +19 -0
  45. data/lib/hutch/tracers/null_tracer.rb +15 -0
  46. data/lib/hutch/tracers.rb +7 -0
  47. data/lib/hutch/version.rb +3 -0
  48. data/lib/hutch/waiter.rb +104 -0
  49. data/lib/hutch/worker.rb +145 -0
  50. data/lib/hutch.rb +69 -0
  51. data/lib/yard-settings/handler.rb +38 -0
  52. data/lib/yard-settings/yard-settings.rb +2 -0
  53. data/spec/hutch/broker_spec.rb +462 -0
  54. data/spec/hutch/cli_spec.rb +93 -0
  55. data/spec/hutch/config_spec.rb +259 -0
  56. data/spec/hutch/consumer_spec.rb +208 -0
  57. data/spec/hutch/error_handlers/airbrake_spec.rb +49 -0
  58. data/spec/hutch/error_handlers/bugsnag_spec.rb +55 -0
  59. data/spec/hutch/error_handlers/honeybadger_spec.rb +58 -0
  60. data/spec/hutch/error_handlers/logger_spec.rb +28 -0
  61. data/spec/hutch/error_handlers/rollbar_spec.rb +45 -0
  62. data/spec/hutch/error_handlers/sentry_raven_spec.rb +37 -0
  63. data/spec/hutch/error_handlers/sentry_spec.rb +47 -0
  64. data/spec/hutch/logger_spec.rb +34 -0
  65. data/spec/hutch/message_spec.rb +38 -0
  66. data/spec/hutch/serializers/json_spec.rb +17 -0
  67. data/spec/hutch/tracers/datadog_spec.rb +44 -0
  68. data/spec/hutch/waiter_spec.rb +51 -0
  69. data/spec/hutch/worker_spec.rb +184 -0
  70. data/spec/hutch_spec.rb +87 -0
  71. data/spec/spec_helper.rb +42 -0
  72. data/templates/default/class/html/settings.erb +0 -0
  73. data/templates/default/class/setup.rb +4 -0
  74. data/templates/default/fulldoc/html/css/hutch.css +13 -0
  75. data/templates/default/layout/html/setup.rb +7 -0
  76. data/templates/default/method_details/html/settings.erb +5 -0
  77. data/templates/default/method_details/setup.rb +4 -0
  78. data/templates/default/method_details/text/settings.erb +0 -0
  79. data/templates/default/module/html/settings.erb +40 -0
  80. data/templates/default/module/setup.rb +4 -0
  81. metadata +205 -0
@@ -0,0 +1,259 @@
1
+ require 'hutch/config'
2
+ require 'tempfile'
3
+
4
+ describe Hutch::Config do
5
+ let(:new_value) { 'not-localhost' }
6
+
7
+ before do
8
+ Hutch::Config.instance_variable_set(:@config, nil)
9
+ Hutch::Config.initialize
10
+ end
11
+
12
+ after do
13
+ Hutch::Config.instance_variable_set(:@config, nil)
14
+ end
15
+
16
+ describe '.get' do
17
+ context 'for valid attributes' do
18
+ subject { Hutch::Config.get(:mq_host) }
19
+
20
+ context 'with no overridden value' do
21
+ it { is_expected.to eq('127.0.0.1') }
22
+ end
23
+
24
+ context 'with an overridden value' do
25
+ before do
26
+ Hutch::Config.set(:mq_host, new_value)
27
+ end
28
+
29
+ it { is_expected.to eq(new_value) }
30
+ end
31
+ end
32
+
33
+ context 'for invalid attributes' do
34
+ let(:invalid_get) { Hutch::Config.get(:invalid_attr) }
35
+
36
+ specify do
37
+ expect { invalid_get }.to raise_error Hutch::UnknownAttributeError
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.set' do
43
+ context 'for valid attributes' do
44
+ before { Hutch::Config.set(:mq_host, new_value) }
45
+ subject { Hutch::Config.user_config[:mq_host] }
46
+
47
+ context 'sets value in user config hash' do
48
+ it { is_expected.to eq(new_value) }
49
+ end
50
+
51
+ context 'type casting' do
52
+ context 'number attributes' do
53
+ before { Hutch::Config.set(:heartbeat, new_value) }
54
+ subject(:value) { Hutch::Config.user_config[:heartbeat] }
55
+
56
+ let(:new_value) { "0" }
57
+
58
+
59
+ specify 'casts values to integers' do
60
+ expect(value).to eq 0
61
+ end
62
+ end
63
+ end
64
+
65
+ context 'boolean attributes' do
66
+ context 'from non-empty string' do
67
+ before { Hutch::Config.set(:autoload_rails, new_value) }
68
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
69
+
70
+ let(:new_value) { "t" }
71
+
72
+
73
+ specify 'casts values to booleans' do
74
+ expect(value).to eq true
75
+ end
76
+ end
77
+
78
+ context 'from empty string' do
79
+ before { Hutch::Config.set(:autoload_rails, new_value) }
80
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
81
+
82
+ let(:new_value) { "" }
83
+
84
+
85
+ specify 'casts values to booleans' do
86
+ expect(value).to eq false
87
+ end
88
+ end
89
+
90
+ context 'from boolean' do
91
+ before { Hutch::Config.set(:autoload_rails, new_value) }
92
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
93
+
94
+ let(:new_value) { true }
95
+
96
+
97
+ specify 'casts values to booleans' do
98
+ expect(value).to eq true
99
+ end
100
+ end
101
+
102
+ context 'from nil' do
103
+ before { Hutch::Config.set(:autoload_rails, new_value) }
104
+ subject(:value) { Hutch::Config.user_config[:autoload_rails] }
105
+
106
+ let(:new_value) { nil }
107
+
108
+
109
+ specify 'casts values to booleans' do
110
+ expect(value).to eq false
111
+ end
112
+ end
113
+ end
114
+
115
+ context 'string attributes' do
116
+ before { Hutch::Config.set(:mq_exchange_type, new_value) }
117
+ subject(:value) { Hutch::Config.user_config[:mq_exchange_type] }
118
+
119
+ let(:new_value) { 1 }
120
+
121
+
122
+ specify 'does not perform any typecasting' do
123
+ expect(value).to eq new_value
124
+ end
125
+ end
126
+ end
127
+
128
+ context 'for invalid attributes' do
129
+ let(:invalid_set) { Hutch::Config.set(:invalid_attr, new_value) }
130
+
131
+ specify do
132
+ expect { invalid_set }.to raise_error Hutch::UnknownAttributeError
133
+ end
134
+ end
135
+ end
136
+
137
+ describe 'a magic getter' do
138
+ context 'for a valid attribute' do
139
+ it 'calls get' do
140
+ expect(Hutch::Config).to receive(:get).with(:mq_host)
141
+ Hutch::Config.mq_host
142
+ end
143
+ end
144
+
145
+ context 'for an invalid attribute' do
146
+ let(:invalid_getter) { Hutch::Config.invalid_attr }
147
+ specify { expect { invalid_getter }.to raise_error NoMethodError }
148
+ end
149
+
150
+ context 'for an ENV-overriden value attribute' do
151
+ around do |example|
152
+ ENV['HUTCH_MQ_HOST'] = 'example.com'
153
+ ENV['HUTCH_MQ_PORT'] = '10001'
154
+ ENV['HUTCH_MQ_TLS'] = 'true'
155
+ example.run
156
+ ENV.delete('HUTCH_MQ_HOST')
157
+ ENV.delete('HUTCH_MQ_PORT')
158
+ ENV.delete('HUTCH_MQ_TLS')
159
+ end
160
+
161
+ it 'returns the override' do
162
+ expect(Hutch::Config.mq_host).to eq 'example.com'
163
+ end
164
+
165
+ it 'returns the override for integers' do
166
+ expect(Hutch::Config.mq_port).to eq 10_001
167
+ end
168
+
169
+ it 'returns the override for booleans' do
170
+ expect(Hutch::Config.mq_tls).to eq true
171
+ end
172
+ end
173
+ end
174
+
175
+ describe 'a magic setter' do
176
+ context 'for a valid attribute' do
177
+ it 'calls set' do
178
+ expect(Hutch::Config).to receive(:set).with(:mq_host, new_value)
179
+ Hutch::Config.mq_host = new_value
180
+ end
181
+ end
182
+
183
+ context 'for an invalid attribute' do
184
+ let(:invalid_setter) { Hutch::Config.invalid_attr = new_value }
185
+ specify { expect { invalid_setter }.to raise_error NoMethodError }
186
+ end
187
+ end
188
+
189
+ describe '.load_from_file' do
190
+ let(:host) { 'broker.yourhost.com' }
191
+ let(:username) { 'calvin' }
192
+ let(:file) do
193
+ Tempfile.new('configs.yaml').tap do |t|
194
+ t.write(YAML.dump(config_data))
195
+ t.rewind
196
+ end
197
+ end
198
+
199
+ context 'when an attribute is invalid' do
200
+ let(:config_data) { { random_attribute: 'socks' } }
201
+ it 'raises an error' do
202
+ expect do
203
+ Hutch::Config.load_from_file(file)
204
+ end.to raise_error(NoMethodError)
205
+ end
206
+ end
207
+
208
+ context 'when attributes are valid' do
209
+ let(:config_data) { { mq_host: host, mq_username: username } }
210
+
211
+ it 'loads in the config data' do
212
+ Hutch::Config.load_from_file(file)
213
+ expect(Hutch::Config.mq_host).to eq host
214
+ expect(Hutch::Config.mq_username).to eq username
215
+ end
216
+ end
217
+
218
+ context 'when using ERB' do
219
+ let(:host) { 'localhost' }
220
+ let(:file) do
221
+ Tempfile.new('configs.yaml').tap do |t|
222
+ t.write(config_contents)
223
+ t.rewind
224
+ end
225
+ end
226
+ let(:config_contents) do
227
+ <<-YAML
228
+ mq_host: 'localhost'
229
+ mq_username: '<%= "calvin" %>'
230
+ YAML
231
+ end
232
+ it 'loads in the config data' do
233
+ Hutch::Config.load_from_file(file)
234
+ expect(Hutch::Config.mq_host).to eq host
235
+ expect(Hutch::Config.mq_username).to eq username
236
+ end
237
+ end
238
+ end
239
+
240
+ context 'developer ergonomics' do
241
+ it 'will accept strings and symbols as config keys' do
242
+ expect(Hutch::Config.get(:mq_host)).to eq '127.0.0.1'
243
+ expect(Hutch::Config.get('mq_host')).to eq '127.0.0.1'
244
+ end
245
+
246
+ describe 'it will not overwrite existing config' do
247
+ it 'with defaults' do
248
+ expect(Hutch::Config.get(:mq_host)).to eq '127.0.0.1'
249
+ Hutch::Config.initialize
250
+
251
+ Hutch::Config.set(:mq_host, 'example2.com')
252
+
253
+ expect(Hutch::Config.get(:mq_host)).to eq 'example2.com'
254
+ Hutch::Config.initialize
255
+ expect(Hutch::Config.get(:mq_host)).to eq 'example2.com'
256
+ end
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,208 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::Consumer do
4
+ around(:each) do |example|
5
+ isolate_constants do
6
+ example.run
7
+ end
8
+ end
9
+
10
+ let(:simple_consumer) do
11
+ unless defined? SimpleConsumer
12
+ class SimpleConsumer
13
+ include Hutch::Consumer
14
+ consume 'hutch.test1'
15
+ end
16
+ end
17
+ SimpleConsumer
18
+ end
19
+
20
+ let(:complex_consumer) do
21
+ unless defined? ComplexConsumer
22
+ class ComplexConsumer
23
+ include Hutch::Consumer
24
+ consume 'hutch.test1', 'hutch.test2'
25
+ arguments foo: :bar
26
+ end
27
+ end
28
+ ComplexConsumer
29
+ end
30
+
31
+ let(:consumer_using_quorum_queue) do
32
+ unless defined? ConsumerUsingQuorumQueue
33
+ class ConsumerUsingQuorumQueue
34
+ include Hutch::Consumer
35
+ consume 'hutch.test1'
36
+ arguments foo: :bar
37
+
38
+ quorum_queue
39
+ end
40
+ end
41
+ ConsumerUsingQuorumQueue
42
+ end
43
+
44
+ let(:consumer_using_classic_queue) do
45
+ unless defined? ConsumerUsingLazyQueue
46
+ class ConsumerUsingLazyQueue
47
+ include Hutch::Consumer
48
+ consume 'hutch.test1'
49
+ arguments foo: :bar
50
+ lazy_queue
51
+ classic_queue
52
+ end
53
+ end
54
+ ConsumerUsingLazyQueue
55
+ end
56
+
57
+ describe 'module inclusion' do
58
+ it 'registers the class as a consumer' do
59
+ expect(Hutch).to receive(:register_consumer) do |klass|
60
+ expect(klass).to eq(simple_consumer)
61
+ end
62
+
63
+ simple_consumer
64
+ end
65
+ end
66
+
67
+
68
+ describe '.consume' do
69
+ it 'saves the routing key to the consumer' do
70
+ expect(simple_consumer.routing_keys).to include 'hutch.test1'
71
+ end
72
+
73
+ context 'with multiple routing keys' do
74
+ it 'registers the class once for each routing key' do
75
+ expect(complex_consumer.routing_keys).to include 'hutch.test1'
76
+ expect(complex_consumer.routing_keys).to include 'hutch.test2'
77
+ end
78
+ end
79
+
80
+ context 'when given the same routing key multiple times' do
81
+ subject { simple_consumer.routing_keys }
82
+ before { simple_consumer.consume 'hutch.test1' }
83
+
84
+ describe '#length' do
85
+ subject { super().length }
86
+ it { is_expected.to eq(1)}
87
+ end
88
+ end
89
+ end
90
+
91
+ describe '.queue_name' do
92
+ let(:queue_name) { 'foo' }
93
+
94
+ it 'overrides the queue name' do
95
+ simple_consumer.queue_name(queue_name)
96
+ expect(simple_consumer.get_queue_name).to eq(queue_name)
97
+ end
98
+ end
99
+
100
+ describe 'default queue mode' do
101
+ it 'does not specify any mode by default' do
102
+ expect(simple_consumer.queue_mode).to eq(nil)
103
+ expect(simple_consumer.queue_type).to eq(nil)
104
+ end
105
+ end
106
+
107
+ describe '.lazy_queue' do
108
+ context 'when queue mode has been set explicitly to lazy' do
109
+ it 'sets queue mode to lazy' do
110
+ expect(consumer_using_classic_queue.queue_mode).to eq('lazy')
111
+ end
112
+ end
113
+ end
114
+
115
+ describe '.classic_queue' do
116
+ context 'when queue type has been set explicitly to classic' do
117
+ it 'sets queue type to classic' do
118
+ expect(consumer_using_classic_queue.queue_type).to eq('classic')
119
+ end
120
+ end
121
+ end
122
+
123
+ describe '.quorum_queue' do
124
+ context 'when queue type has been set explicitly to quorum' do
125
+ it 'sets queue type to quorum' do
126
+ expect(consumer_using_quorum_queue.queue_type).to eq('quorum')
127
+ end
128
+
129
+ it 'accepts initial group size as an option' do
130
+ consumer = simple_consumer
131
+ expect { consumer.quorum_queue(initial_group_size: 3) }
132
+ .to change { consumer.initial_group_size }.to(3)
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '.arguments' do
138
+ let(:args) { { foo: :bar} }
139
+
140
+ it 'overrides the arguments' do
141
+ simple_consumer.arguments(args)
142
+ expect(simple_consumer.get_arguments).to eq(args)
143
+ end
144
+
145
+ end
146
+
147
+ describe '.get_arguments' do
148
+ context 'when defined' do
149
+ it { expect(complex_consumer.get_arguments).to include(foo: :bar) }
150
+ end
151
+
152
+ context 'when queue is lazy' do
153
+ it 'has the x-queue-mode argument set to lazy' do
154
+ expect(consumer_using_classic_queue.get_arguments['x-queue-mode'])
155
+ .to eq('lazy')
156
+ end
157
+ end
158
+
159
+ context "when queue's type is quorum" do
160
+ let(:arguments) { consumer_using_quorum_queue.get_arguments }
161
+ it 'has the x-queue-type argument set to quorum' do
162
+ expect(arguments['x-queue-type']).to eq('quorum')
163
+ expect(arguments).to_not have_key('x-quorum-initial-group-size')
164
+ end
165
+
166
+ it 'has the x-quorum-initial-group-size argument set to quorum' do
167
+ consumer_using_quorum_queue.quorum_queue(initial_group_size: 5)
168
+ expect(arguments['x-queue-type']).to eq('quorum')
169
+ expect(arguments['x-quorum-initial-group-size']).to eq(5)
170
+ end
171
+ end
172
+ end
173
+
174
+ describe '.get_queue_name' do
175
+
176
+ context 'when queue name has been set explicitly' do
177
+ it 'returns the give queue name' do
178
+ class Foo
179
+ include Hutch::Consumer
180
+ queue_name "bar"
181
+ end
182
+
183
+ expect(Foo.get_queue_name).to eq("bar")
184
+ end
185
+ end
186
+
187
+ context 'when no queue name has been set' do
188
+ it 'replaces module separators with colons' do
189
+ module Foo
190
+ class Bar
191
+ include Hutch::Consumer
192
+ end
193
+ end
194
+
195
+ expect(Foo::Bar.get_queue_name).to eq('foo:bar')
196
+ end
197
+
198
+ it 'converts camelcase class names to snake case' do
199
+ class FooBarBAZ
200
+ include Hutch::Consumer
201
+ end
202
+
203
+ expect(FooBarBAZ.get_queue_name).to eq('foo_bar_baz')
204
+ end
205
+ end
206
+ end
207
+ end
208
+
@@ -0,0 +1,49 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::Airbrake do
4
+ let(:error_handler) { Hutch::ErrorHandlers::Airbrake.new }
5
+
6
+ describe '#handle' do
7
+ let(:error) do
8
+ begin
9
+ raise "Stuff went wrong"
10
+ rescue RuntimeError => err
11
+ err
12
+ end
13
+ end
14
+
15
+ it "logs the error to Airbrake" do
16
+ message_id = "1"
17
+ properties = OpenStruct.new(message_id: message_id)
18
+ payload = "{}"
19
+ consumer = double
20
+ ex = error
21
+ message = {
22
+ payload: payload,
23
+ consumer: consumer,
24
+ cgi_data: ENV.to_hash,
25
+ }
26
+ expect(::Airbrake).to receive(:notify).with(ex, message)
27
+ error_handler.handle(properties, payload, consumer, ex)
28
+ end
29
+ end
30
+
31
+ describe '#handle_setup_exception' do
32
+ let(:error) do
33
+ begin
34
+ raise "Stuff went wrong"
35
+ rescue RuntimeError => err
36
+ err
37
+ end
38
+ end
39
+
40
+ it "logs the error to Airbrake" do
41
+ ex = error
42
+ message = {
43
+ cgi_data: ENV.to_hash,
44
+ }
45
+ expect(::Airbrake).to receive(:notify).with(ex, message)
46
+ error_handler.handle_setup_exception(ex)
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ describe Hutch::ErrorHandlers::Bugsnag do
6
+ let(:error_handler) { described_class.new }
7
+
8
+ before do
9
+ Bugsnag.configure do |bugsnag|
10
+ bugsnag.api_key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
11
+ end
12
+ end
13
+
14
+ describe "#handle" do
15
+ let(:error) do
16
+ begin
17
+ raise "Stuff went wrong"
18
+ rescue RuntimeError => err
19
+ err
20
+ end
21
+ end
22
+
23
+ it "logs the error to Bugsnag" do
24
+ message_id = "1"
25
+ properties = OpenStruct.new(message_id: message_id)
26
+ payload = "{}"
27
+ consumer = double
28
+ ex = error
29
+ message = {
30
+ payload: payload,
31
+ consumer: consumer
32
+ }
33
+
34
+ expect(::Bugsnag).to receive(:notify).with(ex).and_call_original
35
+ expect_any_instance_of(::Bugsnag::Report).to receive(:add_tab).with(:hutch, message)
36
+ error_handler.handle(properties, payload, consumer, ex)
37
+ end
38
+ end
39
+
40
+ describe "#handle_setup_exception" do
41
+ let(:error) do
42
+ begin
43
+ raise "Stuff went wrong"
44
+ rescue RuntimeError => err
45
+ err
46
+ end
47
+ end
48
+
49
+ it "logs the error to Bugsnag" do
50
+ ex = error
51
+ expect(::Bugsnag).to receive(:notify).with(ex)
52
+ error_handler.handle_setup_exception(ex)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::Honeybadger do
4
+ let(:error_handler) { Hutch::ErrorHandlers::Honeybadger.new }
5
+
6
+ describe '#handle' do
7
+ let(:error) do
8
+ begin
9
+ raise "Stuff went wrong"
10
+ rescue RuntimeError => err
11
+ err
12
+ end
13
+ end
14
+
15
+ it "logs the error to Honeybadger" do
16
+ message_id = "1"
17
+ properties = OpenStruct.new(message_id: message_id)
18
+ payload = "{}"
19
+ consumer = double
20
+ ex = error
21
+ message = {
22
+ :error_class => ex.class.name,
23
+ :error_message => "#{ ex.class.name }: #{ ex.message }",
24
+ :backtrace => ex.backtrace,
25
+ :context => {
26
+ :message_id => message_id,
27
+ :consumer => consumer
28
+ },
29
+ :parameters => {
30
+ :payload => payload
31
+ }
32
+ }
33
+ expect(error_handler).to receive(:notify_honeybadger).with(message)
34
+ error_handler.handle(properties, payload, consumer, ex)
35
+ end
36
+ end
37
+
38
+ describe '#handle_setup_exception' do
39
+ let(:error) do
40
+ begin
41
+ raise "Stuff went wrong during setup"
42
+ rescue RuntimeError => err
43
+ err
44
+ end
45
+ end
46
+
47
+ it "logs the error to Honeybadger" do
48
+ ex = error
49
+ message = {
50
+ :error_class => ex.class.name,
51
+ :error_message => "#{ ex.class.name }: #{ ex.message }",
52
+ :backtrace => ex.backtrace,
53
+ }
54
+ expect(error_handler).to receive(:notify_honeybadger).with(message)
55
+ error_handler.handle_setup_exception(ex)
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::Logger do
4
+ let(:error_handler) { Hutch::ErrorHandlers::Logger.new }
5
+
6
+ describe '#handle' do
7
+ let(:properties) { OpenStruct.new(message_id: "1") }
8
+ let(:payload) { "{}" }
9
+ let(:error) { double(message: "Stuff went wrong", class: "RuntimeError",
10
+ backtrace: ["line 1", "line 2"]) }
11
+
12
+ it "logs three separate lines" do
13
+ expect(Hutch::Logging.logger).to receive(:error).exactly(3).times
14
+ error_handler.handle(properties, payload, double, error)
15
+ end
16
+ end
17
+
18
+ describe '#handle_setup_exception' do
19
+ let(:error) { double(message: "Stuff went wrong during setup",
20
+ class: "RuntimeError",
21
+ backtrace: ["line 1", "line 2"]) }
22
+
23
+ it "logs two separate lines" do
24
+ expect(Hutch::Logging.logger).to receive(:error).exactly(2).times
25
+ error_handler.handle_setup_exception(error)
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Hutch::ErrorHandlers::Rollbar do
4
+ let(:error_handler) { Hutch::ErrorHandlers::Rollbar.new }
5
+
6
+ describe '#handle' do
7
+ let(:error) do
8
+ begin
9
+ raise "Stuff went wrong"
10
+ rescue RuntimeError => err
11
+ err
12
+ end
13
+ end
14
+
15
+ it "logs the error to Rollbar" do
16
+ message_id = "1"
17
+ properties = OpenStruct.new(message_id: message_id)
18
+ payload = "{}"
19
+ consumer = double
20
+ ex = error
21
+ message = {
22
+ payload: payload,
23
+ consumer: consumer
24
+ }
25
+ expect(::Rollbar).to receive(:error).with(ex, message)
26
+ error_handler.handle(properties, payload, consumer, ex)
27
+ end
28
+ end
29
+
30
+ describe '#handle_setup_exception' do
31
+ let(:error) do
32
+ begin
33
+ raise "Stuff went wrong"
34
+ rescue RuntimeError => err
35
+ err
36
+ end
37
+ end
38
+
39
+ it "logs the error to Rollbar" do
40
+ ex = error
41
+ expect(::Rollbar).to receive(:error).with(ex)
42
+ error_handler.handle_setup_exception(ex)
43
+ end
44
+ end
45
+ end