journaled 2.0.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +14 -8
- data/app/models/journaled/delivery.rb +15 -3
- data/lib/journaled/version.rb +1 -1
- data/spec/dummy/log/development.log +16 -32
- data/spec/dummy/log/test.log +5280 -30829
- data/spec/models/journaled/delivery_spec.rb +65 -32
- metadata +3 -4
@@ -4,6 +4,7 @@ RSpec.describe Journaled::Delivery do
|
|
4
4
|
let(:stream_name) { 'test_events' }
|
5
5
|
let(:partition_key) { 'fake_partition_key' }
|
6
6
|
let(:serialized_event) { '{"foo":"bar"}' }
|
7
|
+
let(:kinesis_client) { Aws::Kinesis::Client.new(stub_responses: true) }
|
7
8
|
|
8
9
|
around do |example|
|
9
10
|
with_env(JOURNALED_STREAM_NAME: stream_name) { example.run }
|
@@ -12,29 +13,60 @@ RSpec.describe Journaled::Delivery do
|
|
12
13
|
subject { described_class.new serialized_event: serialized_event, partition_key: partition_key, app_name: nil }
|
13
14
|
|
14
15
|
describe '#perform' do
|
15
|
-
let
|
16
|
-
|
17
|
-
end
|
18
|
-
let(:return_status_code) { 200 }
|
19
|
-
let(:return_status_body) { return_status_body_hash.to_json }
|
20
|
-
let(:return_status_body_hash) { { RecordId: '101' } }
|
21
|
-
|
22
|
-
let(:stubbed_body) do
|
23
|
-
{
|
24
|
-
'StreamName' => stream_name,
|
25
|
-
'Data' => Base64.encode64(serialized_event).strip,
|
26
|
-
'PartitionKey' => 'fake_partition_key'
|
27
|
-
}
|
28
|
-
end
|
16
|
+
let(:return_status_body) { { shard_id: '101', sequence_number: '101123' } }
|
17
|
+
let(:return_object) { instance_double Aws::Kinesis::Types::PutRecordOutput, return_status_body }
|
29
18
|
|
30
19
|
before do
|
20
|
+
allow(Aws::AssumeRoleCredentials).to receive(:new).and_call_original
|
21
|
+
allow(Aws::Kinesis::Client).to receive(:new).and_return kinesis_client
|
22
|
+
kinesis_client.stub_responses(:put_record, return_status_body)
|
23
|
+
|
31
24
|
allow(Journaled).to receive(:enabled?).and_return(true)
|
32
25
|
end
|
33
26
|
|
34
27
|
it 'makes requests to AWS to put the event on the Kinesis with the correct body' do
|
35
|
-
subject.perform
|
28
|
+
event = subject.perform
|
36
29
|
|
37
|
-
expect(
|
30
|
+
expect(event.shard_id).to eq '101'
|
31
|
+
expect(event.sequence_number).to eq '101123'
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'when JOURNALED_IAM_ROLE_NAME is defined' do
|
35
|
+
let(:aws_sts_client) { Aws::STS::Client.new(stub_responses: true) }
|
36
|
+
|
37
|
+
around do |example|
|
38
|
+
with_env(JOURNALED_IAM_ROLE_NAME: 'iam-role-arn-for-assuming-kinesis-access') { example.run }
|
39
|
+
end
|
40
|
+
|
41
|
+
before do
|
42
|
+
allow(Aws::STS::Client).to receive(:new).and_return aws_sts_client
|
43
|
+
aws_sts_client.stub_responses(:assume_role, assume_role_response)
|
44
|
+
end
|
45
|
+
|
46
|
+
let(:assume_role_response) do
|
47
|
+
{
|
48
|
+
assumed_role_user: {
|
49
|
+
arn: 'iam-role-arn-for-assuming-kinesis-access',
|
50
|
+
assumed_role_id: "ARO123EXAMPLE123:Bob"
|
51
|
+
},
|
52
|
+
credentials: {
|
53
|
+
access_key_id: "AKIAIOSFODNN7EXAMPLE",
|
54
|
+
secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY",
|
55
|
+
session_token: "EXAMPLEtc764bNrC9SAPBSM22wDOk4x4HIZ8j4FZTwdQWLWsKWHGBuFqwAeMicRXmxfpSPfIeoIYRqTflfKD8YUuwthAx7mSEI",
|
56
|
+
expiration: Time.zone.parse("2011-07-15T23:28:33.359Z")
|
57
|
+
}
|
58
|
+
}
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'initializes a Kinesis client with assume role credentials' do
|
62
|
+
subject.perform
|
63
|
+
|
64
|
+
expect(Aws::AssumeRoleCredentials).to have_received(:new).with(
|
65
|
+
client: aws_sts_client,
|
66
|
+
role_arn: "iam-role-arn-for-assuming-kinesis-access",
|
67
|
+
role_session_name: "JournaledAssumeRoleAccess"
|
68
|
+
)
|
69
|
+
end
|
38
70
|
end
|
39
71
|
|
40
72
|
context 'when the stream name env var is NOT set' do
|
@@ -46,57 +78,58 @@ RSpec.describe Journaled::Delivery do
|
|
46
78
|
end
|
47
79
|
|
48
80
|
context 'when Amazon responds with an InternalFailure' do
|
49
|
-
|
50
|
-
|
81
|
+
before do
|
82
|
+
kinesis_client.stub_responses(:put_record, 'InternalFailure')
|
83
|
+
end
|
51
84
|
|
52
85
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
53
86
|
expect(Rails.logger).to receive(:error).with("Kinesis Error - Server Error occurred - Aws::Kinesis::Errors::InternalFailure").once
|
54
87
|
expect { subject.perform }.to raise_error described_class::KinesisTemporaryFailure
|
55
|
-
expect(stubbed_request).to have_been_requested.once
|
56
88
|
end
|
57
89
|
end
|
58
90
|
|
59
91
|
context 'when Amazon responds with a ServiceUnavailable' do
|
60
|
-
|
61
|
-
|
92
|
+
before do
|
93
|
+
kinesis_client.stub_responses(:put_record, 'ServiceUnavailable')
|
94
|
+
end
|
62
95
|
|
63
96
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
64
97
|
allow(Rails.logger).to receive(:error)
|
65
98
|
expect { subject.perform }.to raise_error described_class::KinesisTemporaryFailure
|
66
|
-
expect(stubbed_request).to have_been_requested.once
|
67
99
|
expect(Rails.logger).to have_received(:error).with(/\AKinesis Error/).once
|
68
100
|
end
|
69
101
|
end
|
70
102
|
|
71
103
|
context 'when we receive a 504 Gateway timeout' do
|
72
|
-
|
73
|
-
|
104
|
+
before do
|
105
|
+
kinesis_client.stub_responses(:put_record, 'Aws::Kinesis::Errors::ServiceError')
|
106
|
+
end
|
74
107
|
|
75
108
|
it 'raises an error that subclasses Aws::Kinesis::Errors::ServiceError' do
|
76
109
|
expect { subject.perform }.to raise_error Aws::Kinesis::Errors::ServiceError
|
77
|
-
expect(stubbed_request).to have_been_requested.once
|
78
110
|
end
|
79
111
|
end
|
80
112
|
|
81
113
|
context 'when the IAM user does not have permission to put_record to the specified stream' do
|
82
|
-
|
83
|
-
|
114
|
+
before do
|
115
|
+
kinesis_client.stub_responses(:put_record, 'AccessDeniedException')
|
116
|
+
end
|
84
117
|
|
85
118
|
it 'raises an AccessDeniedException error' do
|
86
119
|
expect { subject.perform }.to raise_error Aws::Kinesis::Errors::AccessDeniedException
|
87
|
-
expect(stubbed_request).to have_been_requested.once
|
88
120
|
end
|
89
121
|
end
|
90
122
|
|
91
123
|
context 'when the request timesout' do
|
92
|
-
|
93
|
-
|
124
|
+
before do
|
125
|
+
kinesis_client.stub_responses(:put_record, Seahorse::Client::NetworkingError.new(Timeout::Error.new))
|
94
126
|
end
|
95
127
|
|
96
128
|
it 'catches the error and re-raises a subclass of NotTrulyExceptionalError and logs about the failure' do
|
97
|
-
expect(Rails.logger).to receive(:error).with(
|
129
|
+
expect(Rails.logger).to receive(:error).with(
|
130
|
+
"Kinesis Error - Networking Error occurred - Seahorse::Client::NetworkingError"
|
131
|
+
).once
|
98
132
|
expect { subject.perform }.to raise_error described_class::KinesisTemporaryFailure
|
99
|
-
expect(stubbed_request).to have_been_requested.once
|
100
133
|
end
|
101
134
|
end
|
102
135
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: journaled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jake Lipson
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2019-
|
14
|
+
date: 2019-06-07 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: aws-sdk-resources
|
@@ -295,8 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
295
295
|
- !ruby/object:Gem::Version
|
296
296
|
version: '0'
|
297
297
|
requirements: []
|
298
|
-
|
299
|
-
rubygems_version: 2.5.1
|
298
|
+
rubygems_version: 3.0.1
|
300
299
|
signing_key:
|
301
300
|
specification_version: 4
|
302
301
|
summary: Journaling for Betterment apps.
|