alephant-sequencer 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da4eb17201797a629eaeeac5596eeea58c0ae5ff
4
- data.tar.gz: 1ca50a3ef5e5cb822d45d8f63cb029765d24abd8
3
+ metadata.gz: 2cfb808e20d9d7e1ff9bf36eca6c61d3fb042152
4
+ data.tar.gz: 4936135a727783f3925d23ec2c018e04b6baf2f5
5
5
  SHA512:
6
- metadata.gz: c50a39c7b3faab1cf4fd590c40d55188fc1400124045a52dedad92955de88ce09fa4e4000877464675e348e75c2bc9c337e9bfea674f21a7071247ac36abdf6f
7
- data.tar.gz: 3b3978ea477682fe6735d1f3c1c17a9f87d957e48fae08c8409230b598705eaf9fba5a5c694aa13832b72f8cd23544c8a12a6b5814f88ba7de946764d867e859
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, jsonpath).first.to_i
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
@@ -1,5 +1,5 @@
1
1
  module Alephant
2
2
  module Sequencer
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe Alephant::Sequencer do
4
4
  let(:ident) { :ident }
5
- let(:jsonpath) { :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.any_instance.stub(:sequence_id_from).and_return(last_seen)
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 "#sequence_id_from(data)" do
75
- subject { Alephant::Sequencer::Sequencer.new(sequence_table, ident, '$.set_sequence_id') }
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 msg).to eq(1)
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.6
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-07 00:00:00.000000000 Z
11
+ date: 2014-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler