alephant-sequencer 0.0.6 → 0.0.7
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/lib/alephant/sequencer/sequencer.rb +5 -5
- data/lib/alephant/sequencer/version.rb +1 -1
- data/spec/sequencer_spec.rb +107 -5
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2cfb808e20d9d7e1ff9bf36eca6c61d3fb042152
|
4
|
+
data.tar.gz: 4936135a727783f3925d23ec2c018e04b6baf2f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83c66149df5dab3d97d6a619bbbc3b42adeb8887e1a3adc7cf39669f3a147c35fafacbf16062f91b737b9ef3123791fa7b9ee32148bd916917a329b8e3bbb7a5
|
7
|
+
data.tar.gz: d11b43af46a3329ac430b3e7669d054787b009370fa4957667fed40e06592e7e131e2599cd64eae7c273c91ed83de989b6f1cf475700209a0ff5823c640699c0
|
@@ -18,7 +18,7 @@ module Alephant
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def sequential?(msg)
|
21
|
-
(get_last_seen || 0) < sequence_id_from(msg)
|
21
|
+
(get_last_seen || 0) < Sequencer.sequence_id_from(msg, jsonpath)
|
22
22
|
end
|
23
23
|
|
24
24
|
def exists?
|
@@ -29,7 +29,7 @@ module Alephant
|
|
29
29
|
block.call(msg)
|
30
30
|
|
31
31
|
last_seen_id = get_last_seen
|
32
|
-
if (last_seen_id || 0) < sequence_id_from(msg)
|
32
|
+
if (last_seen_id || 0) < Sequencer.sequence_id_from(msg, jsonpath)
|
33
33
|
set_last_seen(msg, last_seen_id)
|
34
34
|
else
|
35
35
|
logger.info("Sequencer#sequence nonsequential message for #{ident}")
|
@@ -43,7 +43,7 @@ module Alephant
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def set_last_seen(msg, last_seen_check = nil)
|
46
|
-
seen_id = sequence_id_from(msg)
|
46
|
+
seen_id = Sequencer.sequence_id_from(msg, jsonpath)
|
47
47
|
|
48
48
|
@sequence_table.set_sequence_for(
|
49
49
|
ident, seen_id,
|
@@ -55,8 +55,8 @@ module Alephant
|
|
55
55
|
@sequence_table.sequence_for(ident)
|
56
56
|
end
|
57
57
|
|
58
|
-
def sequence_id_from(msg)
|
59
|
-
JsonPath.on(msg.body,
|
58
|
+
def self.sequence_id_from(msg, path)
|
59
|
+
JsonPath.on(msg.body, path).first.to_i
|
60
60
|
end
|
61
61
|
end
|
62
62
|
end
|
data/spec/sequencer_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Alephant::Sequencer do
|
4
4
|
let(:ident) { :ident }
|
5
|
-
let(:jsonpath) {
|
5
|
+
let(:jsonpath) { "$.sequence_id" }
|
6
6
|
|
7
7
|
describe ".create(table_name, ident, jsonpath)" do
|
8
8
|
it "should return a Sequencer" do
|
@@ -42,6 +42,108 @@ describe Alephant::Sequencer do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
|
46
|
+
describe "#sequence(msg, &block)" do
|
47
|
+
let(:message) do
|
48
|
+
m = double()
|
49
|
+
m.stub(:body)
|
50
|
+
|
51
|
+
m
|
52
|
+
end
|
53
|
+
|
54
|
+
let(:a_proc) do
|
55
|
+
a_block = double()
|
56
|
+
a_block.should_receive(:called).with(message)
|
57
|
+
|
58
|
+
Proc.new do |msg|
|
59
|
+
a_block.called(msg)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
let(:stubbed_last_seen) { 2 }
|
64
|
+
let(:stubbed_seen_high) { 3 }
|
65
|
+
let(:stubbed_seen_low) { 1 }
|
66
|
+
|
67
|
+
it "should call the passed block with msg" do
|
68
|
+
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
69
|
+
subject.sequence(message, &a_proc)
|
70
|
+
end
|
71
|
+
|
72
|
+
context "last_seen_id is nil" do
|
73
|
+
before(:each) do
|
74
|
+
Alephant::Sequencer::Sequencer.any_instance
|
75
|
+
.stub(:get_last_seen).and_return(nil)
|
76
|
+
|
77
|
+
Alephant::Sequencer::Sequencer
|
78
|
+
.stub(:sequence_id_from).and_return(stubbed_seen_high)
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should not call set_last_seen(msg, last_seen_id)" do
|
82
|
+
Alephant::Sequencer::Sequencer.any_instance
|
83
|
+
.should_receive(:set_last_seen)
|
84
|
+
.with(message, nil)
|
85
|
+
|
86
|
+
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
87
|
+
subject.sequence(message, &a_proc)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "last_seen_id == sequence_id_from(msg)" do
|
92
|
+
before(:each) do
|
93
|
+
Alephant::Sequencer::Sequencer.any_instance
|
94
|
+
.stub(:get_last_seen).and_return(stubbed_last_seen)
|
95
|
+
|
96
|
+
Alephant::Sequencer::Sequencer
|
97
|
+
.stub(:sequence_id_from).and_return(stubbed_last_seen)
|
98
|
+
end
|
99
|
+
|
100
|
+
it "should not call set_last_seen(msg, last_seen_id)" do
|
101
|
+
Alephant::Sequencer::Sequencer.any_instance
|
102
|
+
.should_not_receive(:set_last_seen)
|
103
|
+
|
104
|
+
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
105
|
+
subject.sequence(message, &a_proc)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "last_seen_id > sequence_id_from(msg)" do
|
110
|
+
before(:each) do
|
111
|
+
Alephant::Sequencer::Sequencer.any_instance
|
112
|
+
.stub(:get_last_seen).and_return(stubbed_last_seen)
|
113
|
+
|
114
|
+
Alephant::Sequencer::Sequencer.any_instance
|
115
|
+
.stub(:sequence_id_from).and_return(stubbed_seen_low)
|
116
|
+
end
|
117
|
+
|
118
|
+
it "should not call set_last_seen(msg, last_seen_id)" do
|
119
|
+
Alephant::Sequencer::Sequencer.any_instance
|
120
|
+
.should_not_receive(:set_last_seen)
|
121
|
+
|
122
|
+
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
123
|
+
subject.sequence(message, &a_proc)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "last_seen_id < sequence_id_from(msg)" do
|
128
|
+
before(:each) do
|
129
|
+
Alephant::Sequencer::Sequencer.any_instance
|
130
|
+
.stub(:get_last_seen).and_return(stubbed_last_seen)
|
131
|
+
|
132
|
+
Alephant::Sequencer::Sequencer
|
133
|
+
.stub(:sequence_id_from).and_return(stubbed_seen_high)
|
134
|
+
end
|
135
|
+
|
136
|
+
it "should call set_last_seen(msg, last_seen_id)" do
|
137
|
+
Alephant::Sequencer::Sequencer.any_instance
|
138
|
+
.should_receive(:set_last_seen)
|
139
|
+
.with(message, stubbed_last_seen)
|
140
|
+
|
141
|
+
subject = Alephant::Sequencer::Sequencer.new(sequence_table, ident, jsonpath)
|
142
|
+
subject.sequence(message, &a_proc)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
45
147
|
describe "#get_last_seen" do
|
46
148
|
it "returns sequence_table.sequence_for(ident)" do
|
47
149
|
table = double()
|
@@ -57,7 +159,7 @@ describe Alephant::Sequencer do
|
|
57
159
|
|
58
160
|
describe "#set_last_seen(data)" do
|
59
161
|
before(:each) do
|
60
|
-
Alephant::Sequencer::Sequencer.
|
162
|
+
Alephant::Sequencer::Sequencer.stub(:sequence_id_from).and_return(last_seen)
|
61
163
|
end
|
62
164
|
|
63
165
|
it "calls set_sequence_for(ident, last_seen)" do
|
@@ -71,11 +173,11 @@ describe Alephant::Sequencer do
|
|
71
173
|
end
|
72
174
|
end
|
73
175
|
|
74
|
-
describe "
|
75
|
-
subject { Alephant::Sequencer::Sequencer
|
176
|
+
describe ".sequence_id_from(data)" do
|
177
|
+
subject { Alephant::Sequencer::Sequencer }
|
76
178
|
it "should return the id described by the set jsonpath" do
|
77
179
|
msg = Struct.new(:body).new({ "set_sequence_id" => 1 })
|
78
|
-
expect(subject.sequence_id_from
|
180
|
+
expect(subject.sequence_id_from(msg,'$.set_sequence_id')).to eq(1)
|
79
181
|
end
|
80
182
|
end
|
81
183
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alephant-sequencer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Kenny
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|