alephant 0.0.9.6-java → 0.0.9.7-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.
- checksums.yaml +4 -4
- data/alephant.gemspec +1 -0
- data/lib/alephant.rb +5 -8
- data/lib/alephant/models/sequencer.rb +11 -8
- data/lib/alephant/version.rb +1 -1
- data/spec/alephant_spec.rb +44 -22
- data/spec/sequencer_spec.rb +38 -35
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ff0e13461b2cea58a931cebb4868520bbbc34df
|
4
|
+
data.tar.gz: 2b4b52fc0b91968f0276458a8862fe68d35c2407
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 437b33a9f5452daa6770c1463a2ea6928875c4cbfc533484e069554e9ad67bf29f3b21f753cf245242aa3bfb662dd4e2c567b16e94da34a26f3c88a143bc7848
|
7
|
+
data.tar.gz: 31930b9e797a79abda64fc91c376662c49aad4199e2fdcb82af4fb6b4576a2446d9b8eba2d993d8208f0cfddf2177d10b50e9f6ffd769f6c7924ccd7bdd5f15f
|
data/alephant.gemspec
CHANGED
data/lib/alephant.rb
CHANGED
@@ -24,9 +24,8 @@ module Alephant
|
|
24
24
|
:table_name,
|
25
25
|
:sqs_queue_id,
|
26
26
|
:view_path,
|
27
|
-
:
|
28
|
-
:
|
29
|
-
:component_id
|
27
|
+
:component_id,
|
28
|
+
:sequence_id
|
30
29
|
]
|
31
30
|
|
32
31
|
def initialize(opts = {}, logger = nil)
|
@@ -58,13 +57,11 @@ module Alephant
|
|
58
57
|
end
|
59
58
|
|
60
59
|
def receive(msg)
|
61
|
-
data = @parser.parse msg.body
|
62
|
-
|
63
60
|
@logger.info("Alephant.receive: with id #{msg.id} and body digest: #{msg.md5}")
|
64
61
|
|
65
|
-
if @sequencer.sequential?(
|
66
|
-
write
|
67
|
-
@sequencer.set_last_seen(
|
62
|
+
if @sequencer.sequential?(msg, @sequence_id)
|
63
|
+
write @parser.parse msg.body
|
64
|
+
@sequencer.set_last_seen(msg, @sequence_id)
|
68
65
|
else
|
69
66
|
@logger.warn("Alephant.receive: out of sequence message received #{msg.id} (discarded)")
|
70
67
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'aws-sdk'
|
2
|
+
require 'jsonpath'
|
2
3
|
|
3
4
|
module Alephant
|
4
5
|
class Sequencer
|
@@ -47,16 +48,12 @@ module Alephant
|
|
47
48
|
@logger.info("Sequencer.initialize: end with id #{@id}")
|
48
49
|
end
|
49
50
|
|
50
|
-
def sequential?(data)
|
51
|
-
|
52
|
-
yield(get_last_seen, data)
|
53
|
-
else
|
54
|
-
get_last_seen < data["sequence_id"].to_i
|
55
|
-
end
|
51
|
+
def sequential?(data, jsonpath = nil)
|
52
|
+
get_last_seen < get_sequence_id_from(data, jsonpath)
|
56
53
|
end
|
57
54
|
|
58
|
-
def set_last_seen(data)
|
59
|
-
last_seen_id =
|
55
|
+
def set_last_seen(data, jsonpath)
|
56
|
+
last_seen_id = get_sequence_id_from(data, jsonpath)
|
60
57
|
|
61
58
|
batch = AWS::DynamoDB::BatchWrite.new
|
62
59
|
batch.put(@table_name, [:key => @id,:value => last_seen_id])
|
@@ -64,6 +61,12 @@ module Alephant
|
|
64
61
|
@logger.info("Sequencer.set_last_seen: id #{id} and last_seen_id #{last_seen_id}")
|
65
62
|
end
|
66
63
|
|
64
|
+
def get_sequence_id_from(data, jsonpath)
|
65
|
+
jsonpath.nil? ?
|
66
|
+
data.body['sequence_id'].to_i :
|
67
|
+
JsonPath.on(data.body, jsonpath).first
|
68
|
+
end
|
69
|
+
|
67
70
|
def get_last_seen
|
68
71
|
begin
|
69
72
|
@table.batch_get(
|
data/lib/alephant/version.rb
CHANGED
data/spec/alephant_spec.rb
CHANGED
@@ -18,14 +18,13 @@ describe Alephant::Alephant do
|
|
18
18
|
|
19
19
|
it "sets specified options" do
|
20
20
|
instance = subject.new({
|
21
|
-
:s3_bucket_id
|
22
|
-
:s3_object_path
|
23
|
-
:s3_object_id
|
24
|
-
:table_name
|
25
|
-
:sqs_queue_id
|
26
|
-
:
|
27
|
-
:
|
28
|
-
:component_id => :component_id
|
21
|
+
:s3_bucket_id => :s3_bucket_id,
|
22
|
+
:s3_object_path => :s3_object_path,
|
23
|
+
:s3_object_id => :s3_object_id,
|
24
|
+
:table_name => :table_name,
|
25
|
+
:sqs_queue_id => :sqs_queue_id,
|
26
|
+
:component_id => :component_id,
|
27
|
+
:sequence_id => :sequence_id
|
29
28
|
})
|
30
29
|
|
31
30
|
expect(instance.s3_bucket_id).to eq(:s3_bucket_id);
|
@@ -33,9 +32,8 @@ describe Alephant::Alephant do
|
|
33
32
|
expect(instance.s3_object_id).to eq(:s3_object_id);
|
34
33
|
expect(instance.table_name).to eq(:table_name);
|
35
34
|
expect(instance.sqs_queue_id).to eq(:sqs_queue_id);
|
36
|
-
expect(instance.sequential_proc).to eq(:sequential_proc);
|
37
|
-
expect(instance.set_last_seen_proc).to eq(:set_last_seen_proc);
|
38
35
|
expect(instance.component_id).to eq(:component_id);
|
36
|
+
expect(instance.sequence_id).to eq(:sequence_id);
|
39
37
|
end
|
40
38
|
|
41
39
|
it "sets unspecified options to nil" do
|
@@ -46,14 +44,14 @@ describe Alephant::Alephant do
|
|
46
44
|
expect(instance.s3_object_id).to eq(nil);
|
47
45
|
expect(instance.table_name).to eq(nil);
|
48
46
|
expect(instance.sqs_queue_id).to eq(nil);
|
49
|
-
expect(instance.sequential_proc).to eq(nil);
|
50
|
-
expect(instance.set_last_seen_proc).to eq(nil);
|
51
47
|
expect(instance.component_id).to eq(nil);
|
48
|
+
expect(instance.sequence_id).to eq(nil);
|
52
49
|
end
|
53
50
|
|
54
51
|
context "initializes @sequencer" do
|
55
52
|
it "with Sequencer.new({ :table_name => :table_name }, @sqs_queue_id)" do
|
56
|
-
Alephant::Sequencer
|
53
|
+
Alephant::Sequencer
|
54
|
+
.should_receive(:new)
|
57
55
|
.with({ :table_name => :table_name }, :sqs_queue_id)
|
58
56
|
|
59
57
|
instance = subject.new({
|
@@ -65,7 +63,9 @@ describe Alephant::Alephant do
|
|
65
63
|
|
66
64
|
context "initializes @queue" do
|
67
65
|
it "with Queue.new(@sqs_queue_id)" do
|
68
|
-
Alephant::Queue
|
66
|
+
Alephant::Queue
|
67
|
+
.should_receive(:new)
|
68
|
+
.with(:sqs_queue_id)
|
69
69
|
|
70
70
|
instance = subject.new({
|
71
71
|
:sqs_queue_id => :sqs_queue_id
|
@@ -75,7 +75,9 @@ describe Alephant::Alephant do
|
|
75
75
|
|
76
76
|
context "initializes @cache" do
|
77
77
|
it "with Cache.new(@s3_bucket_id, @s3_object_path)" do
|
78
|
-
Alephant::Cache
|
78
|
+
Alephant::Cache
|
79
|
+
.should_receive(:new)
|
80
|
+
.with(:s3_bucket_id, :s3_object_path)
|
79
81
|
|
80
82
|
instance = subject.new({
|
81
83
|
:s3_bucket_id => :s3_bucket_id,
|
@@ -126,7 +128,9 @@ describe Alephant::Alephant do
|
|
126
128
|
|
127
129
|
instance.should_receive(:receive).with(:msg)
|
128
130
|
|
129
|
-
expect_any_instance_of(Alephant::Queue)
|
131
|
+
expect_any_instance_of(Alephant::Queue)
|
132
|
+
.to receive(:poll)
|
133
|
+
.and_yield(:msg)
|
130
134
|
|
131
135
|
t = instance.run!
|
132
136
|
t.join
|
@@ -148,10 +152,12 @@ describe Alephant::Alephant do
|
|
148
152
|
|
149
153
|
it "takes json as an argument" do
|
150
154
|
instance = subject.new
|
155
|
+
|
151
156
|
msg = double()
|
152
157
|
msg.stub(:body).and_return('notjson')
|
153
158
|
|
154
|
-
expect {
|
159
|
+
expect { JsonPath.on(msg.body, '$.foo') }
|
160
|
+
.to raise_error(MultiJson::LoadError);
|
155
161
|
end
|
156
162
|
|
157
163
|
it "writes data to cache if sequential order is true" do
|
@@ -164,10 +170,19 @@ describe Alephant::Alephant do
|
|
164
170
|
|
165
171
|
instance = subject.new
|
166
172
|
|
167
|
-
Alephant::Sequencer
|
168
|
-
|
173
|
+
Alephant::Sequencer
|
174
|
+
.any_instance
|
175
|
+
.stub(:sequential?)
|
176
|
+
.and_return(true)
|
177
|
+
|
178
|
+
Alephant::Sequencer
|
179
|
+
.any_instance
|
180
|
+
.stub(:set_last_seen)
|
181
|
+
|
182
|
+
instance
|
183
|
+
.should_receive(:write)
|
184
|
+
.with(JSON.parse(data, :symbolize_names => true))
|
169
185
|
|
170
|
-
instance.should_receive(:write).with(JSON.parse(data, :symbolize_names => true))
|
171
186
|
instance.receive(msg)
|
172
187
|
end
|
173
188
|
end
|
@@ -177,8 +192,15 @@ describe Alephant::Alephant do
|
|
177
192
|
sequencer = double()
|
178
193
|
queue = double()
|
179
194
|
|
180
|
-
Alephant::Sequencer
|
181
|
-
|
195
|
+
Alephant::Sequencer
|
196
|
+
.any_instance
|
197
|
+
.stub(:initialize)
|
198
|
+
.and_return(sequencer)
|
199
|
+
|
200
|
+
Alephant::Queue
|
201
|
+
.any_instance
|
202
|
+
.stub(:initialize)
|
203
|
+
.and_return(queue)
|
182
204
|
end
|
183
205
|
|
184
206
|
it "puts rendered data into the S3 Cache" do
|
data/spec/sequencer_spec.rb
CHANGED
@@ -60,58 +60,61 @@ describe Alephant::Sequencer do
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
-
describe "sequential?(data)" do
|
63
|
+
describe "sequential?(data, jsonpath = nil)" do
|
64
|
+
let(:jsonpath) { '$.sequence_id' }
|
65
|
+
let(:instance) { subject.new }
|
66
|
+
let(:id_value) { 0 }
|
67
|
+
let(:data) { double() }
|
68
|
+
|
64
69
|
before(:each) do
|
65
70
|
Alephant::Sequencer
|
66
71
|
.any_instance.stub(:initialize)
|
67
72
|
.and_return(double())
|
68
|
-
end
|
69
|
-
|
70
|
-
context "block_given? == true" do
|
71
|
-
it "yields to block" do
|
72
|
-
Alephant::Sequencer
|
73
|
-
.any_instance
|
74
|
-
.stub(:get_last_seen)
|
75
|
-
.and_return(1)
|
76
|
-
|
77
|
-
instance = subject.new
|
78
73
|
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
Alephant::Sequencer
|
75
|
+
.any_instance
|
76
|
+
.stub(:get_last_seen)
|
77
|
+
.and_return(1)
|
82
78
|
|
83
|
-
|
84
|
-
end
|
79
|
+
data.stub(:body).and_return('sequence_id' => id_value)
|
85
80
|
end
|
86
81
|
|
87
|
-
context "
|
88
|
-
context "
|
89
|
-
|
90
|
-
Alephant::Sequencer
|
91
|
-
.any_instance
|
92
|
-
.stub(:get_last_seen)
|
93
|
-
.and_return(0)
|
82
|
+
context "jsonpath provided" do
|
83
|
+
context "in sequence" do
|
84
|
+
let(:id_value) { 2 }
|
94
85
|
|
95
|
-
|
86
|
+
it "looks up data using jsonpath (returns true)" do
|
87
|
+
in_sequence = instance.sequential?(data, jsonpath)
|
88
|
+
expect(in_sequence).to eq(true)
|
89
|
+
end
|
90
|
+
end
|
96
91
|
|
97
|
-
|
92
|
+
context "out of sequence" do
|
93
|
+
let(:id_value) { 0 }
|
98
94
|
|
99
|
-
|
95
|
+
it "looks up data using jsonpath (returns false)" do
|
96
|
+
in_sequence = instance.sequential?(data, jsonpath)
|
97
|
+
expect(in_sequence).to eq(false)
|
100
98
|
end
|
101
99
|
end
|
100
|
+
end
|
102
101
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
.any_instance
|
107
|
-
.stub(:get_last_seen)
|
108
|
-
.and_return(1)
|
102
|
+
context "jsonpath NOT provided" do
|
103
|
+
context "in sequence" do
|
104
|
+
let(:id_value) { 2 }
|
109
105
|
|
110
|
-
|
106
|
+
it "looks up data using a fallback key (returns true)" do
|
107
|
+
in_sequence = instance.sequential?(data)
|
108
|
+
expect(in_sequence).to eq(true)
|
109
|
+
end
|
110
|
+
end
|
111
111
|
|
112
|
-
|
112
|
+
context "out of sequence" do
|
113
|
+
let(:id_value) { 0 }
|
113
114
|
|
114
|
-
|
115
|
+
it "looks up data using a fallback key (returns false)" do
|
116
|
+
in_sequence = instance.sequential?(data)
|
117
|
+
expect(in_sequence).to eq(false)
|
115
118
|
end
|
116
119
|
end
|
117
120
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.9.
|
4
|
+
version: 0.0.9.7
|
5
5
|
platform: java
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
@@ -192,6 +192,20 @@ dependencies:
|
|
192
192
|
version: 0.99.5
|
193
193
|
prerelease: false
|
194
194
|
type: :runtime
|
195
|
+
- !ruby/object:Gem::Dependency
|
196
|
+
name: jsonpath
|
197
|
+
version_requirements: !ruby/object:Gem::Requirement
|
198
|
+
requirements:
|
199
|
+
- - '>='
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
version: '0'
|
202
|
+
requirement: !ruby/object:Gem::Requirement
|
203
|
+
requirements:
|
204
|
+
- - '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
prerelease: false
|
208
|
+
type: :runtime
|
195
209
|
description: Static publishing to S3 based on SQS messages
|
196
210
|
email: kenoir@gmail.com
|
197
211
|
executables:
|