dispatch-rider 1.5.3 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/lib/dispatch-rider.rb +1 -0
  4. data/lib/dispatch-rider/configuration.rb +12 -5
  5. data/lib/dispatch-rider/demultiplexer.rb +3 -27
  6. data/lib/dispatch-rider/logging.rb +10 -0
  7. data/lib/dispatch-rider/logging/base_formatter.rb +30 -0
  8. data/lib/dispatch-rider/logging/json_formatter.rb +75 -0
  9. data/lib/dispatch-rider/logging/lifecycle_logger.rb +53 -0
  10. data/lib/dispatch-rider/logging/text_formatter.rb +48 -0
  11. data/lib/dispatch-rider/queue_services/file_system/queue.rb +13 -2
  12. data/lib/dispatch-rider/version.rb +1 -1
  13. data/spec/lib/dispatch-rider/airbrake_error_handler_spec.rb +10 -3
  14. data/spec/lib/dispatch-rider/callbacks/access_spec.rb +16 -18
  15. data/spec/lib/dispatch-rider/callbacks/storage_spec.rb +4 -9
  16. data/spec/lib/dispatch-rider/configuration_spec.rb +3 -3
  17. data/spec/lib/dispatch-rider/default_error_handler_spec.rb +2 -2
  18. data/spec/lib/dispatch-rider/demultiplexer_spec.rb +14 -14
  19. data/spec/lib/dispatch-rider/dispatcher_spec.rb +10 -8
  20. data/spec/lib/dispatch-rider/handlers/base_spec.rb +27 -22
  21. data/spec/lib/dispatch-rider/handlers/inheritance_tracking_spec.rb +6 -6
  22. data/spec/lib/dispatch-rider/logging/json_formatter_spec.rb +72 -0
  23. data/spec/lib/dispatch-rider/logging/lifecycle_logger_spec.rb +73 -0
  24. data/spec/lib/dispatch-rider/logging/text_formatter_spec.rb +61 -0
  25. data/spec/lib/dispatch-rider/message_spec.rb +11 -11
  26. data/spec/lib/dispatch-rider/notification_services/aws_sns_spec.rb +14 -13
  27. data/spec/lib/dispatch-rider/notification_services/base_spec.rb +18 -13
  28. data/spec/lib/dispatch-rider/notification_services/file_system/channel_spec.rb +2 -3
  29. data/spec/lib/dispatch-rider/notification_services/file_system/notifier_spec.rb +1 -3
  30. data/spec/lib/dispatch-rider/notification_services/file_system_spec.rb +3 -4
  31. data/spec/lib/dispatch-rider/publisher/configuration/destination_spec.rb +30 -21
  32. data/spec/lib/dispatch-rider/publisher/configuration/notification_service_spec.rb +22 -16
  33. data/spec/lib/dispatch-rider/publisher/configuration_reader_spec.rb +11 -10
  34. data/spec/lib/dispatch-rider/publisher/configuration_spec.rb +12 -12
  35. data/spec/lib/dispatch-rider/publisher/configuration_support_spec.rb +11 -11
  36. data/spec/lib/dispatch-rider/publisher_spec.rb +22 -15
  37. data/spec/lib/dispatch-rider/queue_services/aws_sqs_spec.rb +44 -36
  38. data/spec/lib/dispatch-rider/queue_services/base_spec.rb +41 -28
  39. data/spec/lib/dispatch-rider/queue_services/file_system_spec.rb +15 -14
  40. data/spec/lib/dispatch-rider/queue_services/received_message_spec.rb +3 -3
  41. data/spec/lib/dispatch-rider/queue_services/simple_spec.rb +9 -9
  42. data/spec/lib/dispatch-rider/registrars/base_spec.rb +5 -5
  43. data/spec/lib/dispatch-rider/registrars/file_system_channel_spec.rb +3 -3
  44. data/spec/lib/dispatch-rider/registrars/handler_spec.rb +1 -1
  45. data/spec/lib/dispatch-rider/registrars/notification_service_spec.rb +1 -1
  46. data/spec/lib/dispatch-rider/registrars/publishing_destination_spec.rb +2 -2
  47. data/spec/lib/dispatch-rider/registrars/queue_service_spec.rb +1 -1
  48. data/spec/lib/dispatch-rider/registrars/sns_channel_spec.rb +5 -5
  49. data/spec/lib/dispatch-rider/runner_spec.rb +1 -1
  50. data/spec/lib/dispatch-rider/subscriber_spec.rb +45 -29
  51. data/spec/lib/dispatch-rider_spec.rb +3 -3
  52. data/spec/spec_helper.rb +3 -1
  53. metadata +13 -2
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe DispatchRider::QueueServices::Base do
4
4
  subject(:base_queue) do
5
- DispatchRider::QueueServices::Base.any_instance.stub(:assign_storage).and_return([])
5
+ allow_any_instance_of(DispatchRider::QueueServices::Base).to receive(:assign_storage).and_return([])
6
6
  DispatchRider::QueueServices::Base.new
7
7
  end
8
8
 
9
9
  describe "#initialize" do
10
10
  it "should initiate a queue" do
11
- base_queue.queue.should eq([])
11
+ expect(base_queue.queue).to eq([])
12
12
  end
13
13
  end
14
14
 
@@ -16,16 +16,18 @@ describe DispatchRider::QueueServices::Base do
16
16
  subject(:simple_queue) { DispatchRider::QueueServices::Simple.new }
17
17
 
18
18
  it "should push the serialized object to the queue" do
19
- simple_queue.push(DispatchRider::Message.new(:subject => "foo", :body => "bar"))
19
+ simple_queue.push(DispatchRider::Message.new(subject: "foo", body: "bar"))
20
20
  result = JSON.parse(simple_queue.queue.first)
21
- result['subject'].should eq('foo')
22
- result['body'].should eq('bar')
21
+ expect(result['subject']).to eq('foo')
22
+ expect(result['body']).to eq('bar')
23
23
  end
24
24
  end
25
25
 
26
26
  describe "#insert" do
27
27
  it "should raise an exception" do
28
- expect { base_queue.insert(DispatchRider::Message.new(:subject => "foo", :body => "bar")) }.to raise_exception(NotImplementedError)
28
+ expect {
29
+ base_queue.insert(DispatchRider::Message.new(subject: "foo", body: "bar"))
30
+ }.to raise_exception(NotImplementedError)
29
31
  end
30
32
  end
31
33
 
@@ -33,26 +35,28 @@ describe DispatchRider::QueueServices::Base do
33
35
  subject(:simple_queue) { DispatchRider::QueueServices::Simple.new }
34
36
 
35
37
  before :each do
36
- simple_queue.queue.push(DispatchRider::Message.new(:subject => "foo", :body => "bar").to_json)
38
+ simple_queue.queue.push(DispatchRider::Message.new(subject: "foo", body: "bar").to_json)
37
39
  end
38
40
 
39
41
  context "when the block passed to process the popped message returns true" do
40
42
  it "should return the first message in the queue" do
41
- simple_queue.pop {|msg| true}.should eq(DispatchRider::Message.new(:subject => 'foo', :body => 'bar'))
43
+ response = simple_queue.pop { |_msg| true }
44
+ expect(response).to eq(DispatchRider::Message.new(subject: 'foo', body: 'bar'))
42
45
  end
43
46
  end
44
47
 
45
48
  context "when the block passed to process the popped message returns false" do
46
49
  it "should return the first message in the queue" do
47
- simple_queue.pop {|msg| false}.should eq(DispatchRider::Message.new(:subject => 'foo', :body => 'bar'))
50
+ result = simple_queue.pop { |_msg| false }
51
+ expect(result).to eq(DispatchRider::Message.new(subject: 'foo', body: 'bar'))
48
52
  end
49
53
 
50
54
  it "should not remove the first message from the queue" do
51
55
  simple_queue.pop do |msg|
52
- msg.body = {:bar => "baz"}
56
+ msg.body = { bar: "baz" }
53
57
  false
54
58
  end
55
- simple_queue.should_not be_empty
59
+ expect(simple_queue).not_to be_empty
56
60
  end
57
61
  end
58
62
 
@@ -62,35 +66,40 @@ describe DispatchRider::QueueServices::Base do
62
66
  end
63
67
 
64
68
  it "should return nil" do
65
- simple_queue.pop do |msg|
66
- msg.body = {:bar => "baz"}
69
+ result = simple_queue.pop do |msg|
70
+ msg.body = { bar: "baz" }
67
71
  true
68
- end.should be_nil
72
+ end
73
+ expect(result).to be_nil
69
74
  end
70
75
  end
71
76
  end
72
77
 
73
78
  describe "#head" do
74
- before { base_queue.stub(:raw_head).and_return(new_item) }
79
+ before do
80
+ allow(base_queue).to receive(:raw_head) { new_item }
81
+ end
75
82
 
76
83
  context "when there is no new item" do
77
- let(:new_item){ nil }
84
+ let(:new_item) { nil }
78
85
 
79
86
  it "should raise an exception" do
80
- base_queue.head.should be_nil
87
+ expect(base_queue.head).to be_nil
81
88
  end
82
89
  end
83
90
 
84
91
  context "when a new item exists" do
85
- before { base_queue.stub(:construct_message_from){|item| item.message} }
92
+ before do
93
+ allow(base_queue).to receive(:construct_message_from) { |item| item.message }
94
+ end
86
95
 
87
- let(:new_item){ OpenStruct.new(:message => new_message) }
88
- let(:new_message){ :the_message }
96
+ let(:new_item) { OpenStruct.new(message: new_message) }
97
+ let(:new_message) { :the_message }
89
98
 
90
99
  it "should return the expected message" do
91
100
  received_head = base_queue.head
92
- received_head.item.should == new_item
93
- received_head.to_sym == new_message
101
+ expect(received_head.item).to eq new_item
102
+ expect(received_head.to_sym).to eq new_message
94
103
  end
95
104
  end
96
105
  end
@@ -103,19 +112,23 @@ describe DispatchRider::QueueServices::Base do
103
112
 
104
113
  describe "#construct_message_from" do
105
114
  it "should raise an exception" do
106
- expect { base_queue.construct_message_from({:subject => 'foo', :body => {:bar => 'baz'}}.to_json) }.to raise_exception(NotImplementedError)
115
+ expect {
116
+ base_queue.construct_message_from({ subject: 'foo', body: { bar: 'baz' } }.to_json)
117
+ }.to raise_exception(NotImplementedError)
107
118
  end
108
119
  end
109
120
 
110
121
  describe "#delete" do
111
122
  it "should raise an exception" do
112
- expect { base_queue.delete({:subject => 'foo', :body => {:bar => 'baz'}}.to_json) }.to raise_exception(NotImplementedError)
123
+ expect {
124
+ base_queue.delete({ subject: 'foo', body: { bar: 'baz' } }.to_json)
125
+ }.to raise_exception(NotImplementedError)
113
126
  end
114
127
  end
115
128
 
116
129
  describe "#empty?" do
117
130
  before :each do
118
- base_queue.stub(:size) { base_queue.queue.size }
131
+ allow(base_queue).to receive(:size) { base_queue.queue.size }
119
132
  end
120
133
 
121
134
  context "when the queue is empty" do
@@ -124,17 +137,17 @@ describe DispatchRider::QueueServices::Base do
124
137
  end
125
138
 
126
139
  it "should return true" do
127
- base_queue.should be_empty
140
+ expect(base_queue).to be_empty
128
141
  end
129
142
  end
130
143
 
131
144
  context "when the queue is not empty" do
132
145
  before :each do
133
- base_queue.queue << {:subject => 'foo', :body => 'bar'}.to_json
146
+ base_queue.queue << { subject: 'foo', body: 'bar' }.to_json
134
147
  end
135
148
 
136
149
  it "should return false" do
137
- base_queue.should_not be_empty
150
+ expect(base_queue).not_to be_empty
138
151
  end
139
152
  end
140
153
  end
@@ -7,11 +7,12 @@ describe DispatchRider::QueueServices::FileSystem do
7
7
  DispatchRider::QueueServices::FileSystem.new(:path => queue_path)
8
8
  end
9
9
 
10
- before { file_system_queue.send(:queue).send(:file_paths).each{|file| File.unlink(file)} }
10
+ before { file_system_queue.send(:queue).send(:file_paths).each { |file| File.unlink(file) } }
11
11
 
12
12
  describe "#assign_storage" do
13
13
  it "should return an empty array" do
14
- file_system_queue.assign_storage({:path => queue_path}).should be_a DispatchRider::QueueServices::FileSystem::Queue
14
+ expected_type = DispatchRider::QueueServices::FileSystem::Queue
15
+ expect(file_system_queue.assign_storage(path: queue_path)).to be_a expected_type
15
16
  end
16
17
  end
17
18
 
@@ -19,8 +20,8 @@ describe DispatchRider::QueueServices::FileSystem do
19
20
  it "should insert a serialized object into the queue" do
20
21
  file_system_queue.insert({'subject' => 'foo', 'body' => 'bar'}.to_json)
21
22
  result = JSON.parse(file_system_queue.queue.pop.read)
22
- result['subject'].should eq('foo')
23
- result['body'].should eq('bar')
23
+ expect(result['subject']).to eq('foo')
24
+ expect(result['body']).to eq('bar')
24
25
  end
25
26
  end
26
27
 
@@ -31,8 +32,8 @@ describe DispatchRider::QueueServices::FileSystem do
31
32
 
32
33
  it "should return the first item from the queue" do
33
34
  result = JSON.parse(file_system_queue.raw_head.read)
34
- result['subject'].should eq('foo')
35
- result['body'].should eq('bar')
35
+ expect(result['subject']).to eq('foo')
36
+ expect(result['body']).to eq('bar')
36
37
  end
37
38
  end
38
39
 
@@ -46,21 +47,21 @@ describe DispatchRider::QueueServices::FileSystem do
46
47
 
47
48
  it "should return the item casted as a message" do
48
49
  result = file_system_queue.construct_message_from(new_file)
49
- result.subject.should eq('foo')
50
- result.body.should eq('bar')
50
+ expect(result.subject).to eq('foo')
51
+ expect(result.body).to eq('bar')
51
52
  end
52
53
  end
53
-
54
+
54
55
  describe "#put_back" do
55
56
  before :each do
56
57
  file_system_queue.insert({'subject' => 'foo', 'body' => 'bar'}.to_json)
57
58
  end
58
-
59
+
59
60
  it "should remove and re-add the item" do
60
61
  file = file_system_queue.raw_head
61
- file_system_queue.should be_empty
62
+ expect(file_system_queue).to be_empty
62
63
  file_system_queue.put_back(file)
63
- file_system_queue.size.should eq(1)
64
+ expect(file_system_queue.size).to eq(1)
64
65
  end
65
66
  end
66
67
 
@@ -72,7 +73,7 @@ describe DispatchRider::QueueServices::FileSystem do
72
73
  it "should remove the item from the queue" do
73
74
  file = File.new(Dir["#{queue_path}/*.ready"].first, "w")
74
75
  file_system_queue.delete(file)
75
- file_system_queue.should be_empty
76
+ expect(file_system_queue).to be_empty
76
77
  end
77
78
  end
78
79
 
@@ -82,7 +83,7 @@ describe DispatchRider::QueueServices::FileSystem do
82
83
  end
83
84
 
84
85
  it "should return the size of the queue" do
85
- file_system_queue.size.should eq(1)
86
+ expect(file_system_queue.size).to eq(1)
86
87
  end
87
88
  end
88
89
  end
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe DispatchRider::QueueServices::ReceivedMessage do
4
4
 
5
- subject{ described_class.new("test_message", double(:item)) }
5
+ subject { described_class.new("test_message", double(:item)) }
6
6
 
7
7
  describe "#extend_timeout" do
8
8
  example do
9
- expect{
9
+ expect {
10
10
  subject.extend_timeout(10)
11
11
  }.to raise_error NotImplementedError
12
12
  end
@@ -14,7 +14,7 @@ describe DispatchRider::QueueServices::ReceivedMessage do
14
14
 
15
15
  describe "#return_to_queue" do
16
16
  example do
17
- expect{
17
+ expect {
18
18
  subject.return_to_queue
19
19
  }.to raise_error NotImplementedError
20
20
  end
@@ -7,7 +7,7 @@ describe DispatchRider::QueueServices::Simple do
7
7
 
8
8
  describe "#assign_storage" do
9
9
  it "should return an empty array" do
10
- simple_queue.assign_storage({}).should eq([])
10
+ expect(simple_queue.assign_storage({})).to eq([])
11
11
  end
12
12
  end
13
13
 
@@ -15,8 +15,8 @@ describe DispatchRider::QueueServices::Simple do
15
15
  it "should insert a serialized object into the queue" do
16
16
  simple_queue.insert({'subject' => 'foo', 'body' => 'bar'}.to_json)
17
17
  result = JSON.parse(simple_queue.queue.pop)
18
- result['subject'].should eq('foo')
19
- result['body'].should eq('bar')
18
+ expect(result['subject']).to eq('foo')
19
+ expect(result['body']).to eq('bar')
20
20
  end
21
21
  end
22
22
 
@@ -27,16 +27,16 @@ describe DispatchRider::QueueServices::Simple do
27
27
 
28
28
  it "should return the first item from the queue" do
29
29
  result = JSON.parse(simple_queue.raw_head)
30
- result['subject'].should eq('foo')
31
- result['body'].should eq('bar')
30
+ expect(result['subject']).to eq('foo')
31
+ expect(result['body']).to eq('bar')
32
32
  end
33
33
  end
34
34
 
35
35
  describe "#construct_message_from" do
36
36
  it "should return the item casted as a message" do
37
37
  result = simple_queue.construct_message_from({'subject' => 'foo', 'body' => 'bar'}.to_json)
38
- result.subject.should eq('foo')
39
- result.body.should eq('bar')
38
+ expect(result.subject).to eq('foo')
39
+ expect(result.body).to eq('bar')
40
40
  end
41
41
  end
42
42
 
@@ -47,7 +47,7 @@ describe DispatchRider::QueueServices::Simple do
47
47
 
48
48
  it "should remove the item from the queue" do
49
49
  simple_queue.delete({'subject' => 'foo', 'body' => 'bar'}.to_json)
50
- simple_queue.should be_empty
50
+ expect(simple_queue).to be_empty
51
51
  end
52
52
  end
53
53
 
@@ -57,7 +57,7 @@ describe DispatchRider::QueueServices::Simple do
57
57
  end
58
58
 
59
59
  it "should return the size of the queue" do
60
- simple_queue.size.should eq(1)
60
+ expect(simple_queue.size).to eq(1)
61
61
  end
62
62
  end
63
63
  end
@@ -25,7 +25,7 @@ describe DispatchRider::Registrars::Base do
25
25
 
26
26
  context "when there is a missing constant while registering" do
27
27
  it "raises an exception" do
28
- subject.should_receive(:value).with(:foo, {}) { 'bar'.camelize.constantize }
28
+ expect(subject).to receive(:value).with(:foo, {}) { 'bar'.camelize.constantize }
29
29
  expect { subject.register(:foo) }.to raise_exception(DispatchRider::NotFound)
30
30
  end
31
31
  end
@@ -33,7 +33,7 @@ describe DispatchRider::Registrars::Base do
33
33
 
34
34
  describe "#unregister" do
35
35
  before :each do
36
- subject.stub(:value).and_return('bar')
36
+ allow(subject).to receive(:value).and_return('bar')
37
37
  subject.register(:foo)
38
38
  end
39
39
 
@@ -43,19 +43,19 @@ describe DispatchRider::Registrars::Base do
43
43
  end
44
44
 
45
45
  it "returns the registrar" do
46
- subject.unregister(:foo).should eq(subject)
46
+ expect(subject.unregister(:foo)).to eq(subject)
47
47
  end
48
48
  end
49
49
 
50
50
  describe "#fetch" do
51
51
  context "when a key/value pair is registered" do
52
52
  before :each do
53
- subject.stub(:value).and_return('bar')
53
+ allow(subject).to receive(:value).and_return('bar')
54
54
  subject.register(:foo)
55
55
  end
56
56
 
57
57
  it "return the value for the key" do
58
- subject.fetch(:foo).should eq('bar')
58
+ expect(subject.fetch(:foo)).to eq('bar')
59
59
  end
60
60
  end
61
61
 
@@ -2,11 +2,11 @@ require 'spec_helper'
2
2
 
3
3
  describe DispatchRider::Registrars::FileSystemChannel do
4
4
  describe "#value" do
5
- let(:path){ "/foo/bar" }
6
- let(:channel_options){ {path: path} }
5
+ let(:path) { "/foo/bar" }
6
+ let(:channel_options) { { path: path } }
7
7
 
8
8
  it "returns the expanded path from the options" do
9
- subject.value(:foo, channel_options).should eq("/foo/bar")
9
+ expect(subject.value(:foo, channel_options)).to eq("/foo/bar")
10
10
  end
11
11
  end
12
12
  end
@@ -10,7 +10,7 @@ describe DispatchRider::Registrars::Handler do
10
10
 
11
11
  describe "#value" do
12
12
  it "returns the value for the key/value pair while registering a handler" do
13
- subject.value(:custom_test_handler).should eq(CustomTestHandler)
13
+ expect(subject.value(:custom_test_handler)).to eq(CustomTestHandler)
14
14
  end
15
15
  end
16
16
  end
@@ -7,7 +7,7 @@ describe DispatchRider::Registrars::NotificationService do
7
7
 
8
8
  describe "#value" do
9
9
  it "returns the value for the key/value pair while registering a notification service" do
10
- subject.value(:aws_sns).should be_a(DispatchRider::NotificationServices::AwsSns)
10
+ expect(subject.value(:aws_sns)).to be_a(DispatchRider::NotificationServices::AwsSns)
11
11
  end
12
12
  end
13
13
  end
@@ -4,8 +4,8 @@ describe DispatchRider::Registrars::PublishingDestination do
4
4
  describe "#value" do
5
5
  it "returns an object which has information about a notification service and a channel" do
6
6
  result = subject.value('foo', :service => :aws_sns, :channel => :bar)
7
- result.service.should eq(:aws_sns)
8
- result.channel.should eq(:bar)
7
+ expect(result.service).to eq(:aws_sns)
8
+ expect(result.channel).to eq(:bar)
9
9
  end
10
10
  end
11
11
  end
@@ -7,7 +7,7 @@ describe DispatchRider::Registrars::QueueService do
7
7
 
8
8
  describe "#value" do
9
9
  it "returns the value for the key/value pair while registering a queue service" do
10
- subject.value(:simple).should be_a(DispatchRider::QueueServices::Simple)
10
+ expect(subject.value(:simple)).to be_a(DispatchRider::QueueServices::Simple)
11
11
  end
12
12
  end
13
13
  end
@@ -2,13 +2,13 @@ require 'spec_helper'
2
2
 
3
3
  describe DispatchRider::Registrars::SnsChannel do
4
4
  describe "#value" do
5
- let(:account){ "123456789012" }
6
- let(:region){ "us-west-2" }
7
- let(:topic_name){ "GeneralTopic" }
8
- let(:channel_options){ {account: account, region: region, topic: topic_name} }
5
+ let(:account) { "123456789012" }
6
+ let(:region) { "us-west-2" }
7
+ let(:topic_name) { "GeneralTopic" }
8
+ let(:channel_options) { { account: account, region: region, topic: topic_name } }
9
9
 
10
10
  it "returns the value for the key/value pair while registering an amazon sns channel" do
11
- subject.value(:foo, channel_options).should eq("arn:aws:sns:us-west-2:123456789012:GeneralTopic")
11
+ expect(subject.value(:foo, channel_options)).to eq("arn:aws:sns:us-west-2:123456789012:GeneralTopic")
12
12
  end
13
13
  end
14
14
  end