redistat 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +8 -0
- data/README.md +219 -97
- data/lib/redistat.rb +13 -13
- data/lib/redistat/buffer.rb +27 -24
- data/lib/redistat/collection.rb +5 -5
- data/lib/redistat/connection.rb +23 -18
- data/lib/redistat/core_ext.rb +1 -1
- data/lib/redistat/core_ext/bignum.rb +2 -2
- data/lib/redistat/core_ext/date.rb +2 -2
- data/lib/redistat/core_ext/fixnum.rb +2 -2
- data/lib/redistat/core_ext/hash.rb +4 -4
- data/lib/redistat/date.rb +11 -11
- data/lib/redistat/event.rb +18 -18
- data/lib/redistat/finder.rb +39 -39
- data/lib/redistat/finder/date_set.rb +4 -4
- data/lib/redistat/key.rb +16 -16
- data/lib/redistat/label.rb +14 -14
- data/lib/redistat/mixins/database.rb +1 -1
- data/lib/redistat/mixins/date_helper.rb +1 -1
- data/lib/redistat/mixins/options.rb +8 -8
- data/lib/redistat/mixins/synchronize.rb +12 -11
- data/lib/redistat/model.rb +25 -17
- data/lib/redistat/result.rb +4 -4
- data/lib/redistat/scope.rb +5 -5
- data/lib/redistat/summary.rb +33 -26
- data/lib/redistat/version.rb +1 -1
- data/redistat.gemspec +4 -3
- data/spec/buffer_spec.rb +27 -25
- data/spec/collection_spec.rb +4 -4
- data/spec/connection_spec.rb +12 -12
- data/spec/core_ext/hash_spec.rb +5 -5
- data/spec/database_spec.rb +3 -3
- data/spec/date_spec.rb +15 -15
- data/spec/event_spec.rb +8 -8
- data/spec/finder/date_set_spec.rb +134 -134
- data/spec/finder_spec.rb +36 -36
- data/spec/key_spec.rb +19 -19
- data/spec/label_spec.rb +10 -10
- data/spec/model_helper.rb +10 -9
- data/spec/model_spec.rb +38 -41
- data/spec/options_spec.rb +9 -9
- data/spec/result_spec.rb +4 -4
- data/spec/scope_spec.rb +6 -6
- data/spec/spec_helper.rb +6 -0
- data/spec/summary_spec.rb +31 -24
- data/spec/synchronize_spec.rb +118 -57
- data/spec/thread_safety_spec.rb +6 -6
- metadata +88 -126
- data/.rvmrc +0 -1
data/spec/collection_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Redistat::Collection do
|
4
|
-
|
4
|
+
|
5
5
|
it "should initialize properly" do
|
6
6
|
options = {:from => "from", :till => "till", :depth => "depth"}
|
7
7
|
result = Redistat::Collection.new(options)
|
@@ -9,12 +9,12 @@ describe Redistat::Collection do
|
|
9
9
|
result.till.should == options[:till]
|
10
10
|
result.depth.should == options[:depth]
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should have a total property" do
|
14
14
|
col = Redistat::Collection.new()
|
15
15
|
col.total.should == {}
|
16
16
|
col.total = {:foo => "bar"}
|
17
17
|
col.total.should == {:foo => "bar"}
|
18
18
|
end
|
19
|
-
|
20
|
-
end
|
19
|
+
|
20
|
+
end
|
data/spec/connection_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require "spec_helper"
|
|
2
2
|
include Redistat
|
3
3
|
|
4
4
|
describe Redistat::Connection do
|
5
|
-
|
5
|
+
|
6
6
|
before(:each) do
|
7
7
|
@redis = Redistat.redis
|
8
8
|
end
|
9
|
-
|
9
|
+
|
10
10
|
it "should have a valid Redis client instance" do
|
11
11
|
Redistat.redis.should_not be_nil
|
12
12
|
end
|
@@ -16,13 +16,13 @@ describe Redistat::Connection do
|
|
16
16
|
@redis.client.port.should == 8379
|
17
17
|
@redis.client.db.should == 15
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should be able to set and get data" do
|
21
21
|
@redis.set("hello", "world")
|
22
22
|
@redis.get("hello").should == "world"
|
23
23
|
@redis.del("hello").should be_true
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
it "should be able to store hashes to Redis" do
|
27
27
|
@redis.hset("hash", "field", "1")
|
28
28
|
@redis.hget("hash", "field").should == "1"
|
@@ -32,36 +32,36 @@ describe Redistat::Connection do
|
|
32
32
|
@redis.hget("hash", "field").should == "1"
|
33
33
|
@redis.del("hash")
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should be accessible from Redistat module" do
|
37
37
|
Redistat.redis.should == Connection.get
|
38
38
|
Redistat.redis.should == Redistat.connection
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "should handle multiple connections with refs" do
|
42
42
|
Redistat.redis.client.db.should == 15
|
43
43
|
Redistat.connect(:port => 8379, :db => 14, :ref => "Custom")
|
44
44
|
Redistat.redis.client.db.should == 15
|
45
45
|
Redistat.redis("Custom").client.db.should == 14
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should be able to overwrite default and custom refs" do
|
49
49
|
Redistat.redis.client.db.should == 15
|
50
50
|
Redistat.connect(:port => 8379, :db => 14)
|
51
51
|
Redistat.redis.client.db.should == 14
|
52
|
-
|
52
|
+
|
53
53
|
Redistat.redis("Custom").client.db.should == 14
|
54
54
|
Redistat.connect(:port => 8379, :db => 15, :ref => "Custom")
|
55
55
|
Redistat.redis("Custom").client.db.should == 15
|
56
|
-
|
56
|
+
|
57
57
|
# Reset the default connection to the testing server or all hell
|
58
58
|
# might brake loose from the rest of the specs
|
59
59
|
Redistat.connect(:port => 8379, :db => 15)
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
# TODO: Test thread-safety
|
63
63
|
it "should be thread-safe" do
|
64
64
|
pending("need to figure out a way to test thread-safety")
|
65
65
|
end
|
66
|
-
|
67
|
-
end
|
66
|
+
|
67
|
+
end
|
data/spec/core_ext/hash_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Hash do
|
4
|
-
|
4
|
+
|
5
5
|
it "should #set_or_incr values" do
|
6
6
|
hash = {:count => 1}
|
7
7
|
hash.set_or_incr(:sum, 3).should be_true
|
@@ -14,17 +14,17 @@ describe Hash do
|
|
14
14
|
hash[:view] = 'test'
|
15
15
|
hash.set_or_incr(:view, 3).should be_false
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should #merge_and_incr hashes" do
|
19
19
|
hash = { :count => 1, :city => 'hell', :sum => 3, :name => 'john' }
|
20
|
-
|
20
|
+
|
21
21
|
new_hash = { :count => 3, :city => 'slum', :views => 2 }
|
22
22
|
hash.clone.merge_and_incr(new_hash).should == { :count => 4, :city => 'slum', :views => 2,
|
23
23
|
:sum => 3, :name => 'john' }
|
24
|
-
|
24
|
+
|
25
25
|
new_hash = { :count => 'six', :city => 'slum', :views => 2, :time => 'late' }
|
26
26
|
hash.clone.merge_and_incr(new_hash).should == { :count => 'six', :city => 'slum', :views => 2,
|
27
27
|
:sum => 3, :name => 'john', :time => 'late' }
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
end
|
data/spec/database_spec.rb
CHANGED
data/spec/date_spec.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Redistat::Date do
|
4
|
-
|
4
|
+
|
5
5
|
it "should initialize from Time object" do
|
6
6
|
now = Time.now
|
7
7
|
[Redistat::Date.new(now), now.to_rs].each do |rdate|
|
8
8
|
Redistat::Date::DEPTHS.each { |k| rdate.send(k).should == now.send(k) }
|
9
9
|
end
|
10
10
|
end
|
11
|
-
|
11
|
+
|
12
12
|
it "should initialize from Date object" do
|
13
13
|
today = Date.today
|
14
14
|
[Redistat::Date.new(today), today.to_rs].each do |rdate|
|
@@ -16,7 +16,7 @@ describe Redistat::Date do
|
|
16
16
|
[:hour, :min, :sec, :usec].each { |k| rdate.send(k).should == 0 }
|
17
17
|
end
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
it "should initialize from Fixnum object (UNIX Timestamp)" do
|
21
21
|
now = Time.now.to_i
|
22
22
|
time = Time.at(now)
|
@@ -24,13 +24,13 @@ describe Redistat::Date do
|
|
24
24
|
[:year, :month, :day, :hour, :min, :sec].each { |k| rdate.send(k).should == time.send(k) }
|
25
25
|
end
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
it "should initialize from String object" do
|
29
29
|
now = Time.now
|
30
30
|
rdate = Redistat::Date.new(now.to_s)
|
31
31
|
[:year, :month, :day, :hour, :min, :sec].each { |k| rdate.send(k).should == now.send(k) }
|
32
32
|
end
|
33
|
-
|
33
|
+
|
34
34
|
it "should initialize from Redistat date String" do
|
35
35
|
now = Time.now
|
36
36
|
rdate = Redistat::Date.new(now.to_s)
|
@@ -38,25 +38,25 @@ describe Redistat::Date do
|
|
38
38
|
rdate.to_s(k).should == Redistat::Date.new(rdate.to_s(k)).to_s(k)
|
39
39
|
}
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "should convert to Time object" do
|
43
43
|
now = Time.now
|
44
44
|
rdate = Redistat::Date.new(now)
|
45
45
|
rdate.to_time.to_s.should == now.to_s
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "should convert to Date object" do
|
49
49
|
today = Date.today
|
50
50
|
rdate = Redistat::Date.new(today)
|
51
51
|
rdate.to_date.to_s.should == today.to_s
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should convert to Fixnum object (UNIX Timestamp)" do
|
55
55
|
now = Time.now
|
56
56
|
rdate = Redistat::Date.new(now)
|
57
57
|
rdate.to_i.should == now.to_i
|
58
58
|
end
|
59
|
-
|
59
|
+
|
60
60
|
it "should convert to string with correct depths" do
|
61
61
|
today = Date.today
|
62
62
|
now = Time.now
|
@@ -71,25 +71,25 @@ describe Redistat::Date do
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should add helper methods to Date, Time and Fixnum classes" do
|
76
76
|
Date.today.to_time.should == Time.parse(Date.today.to_s)
|
77
77
|
Time.now.to_i.to_time.should == Time.at(Time.now.to_i)
|
78
78
|
Date.today.to_rs.to_date.should == Date.today
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
it "should have a depth property" do
|
82
82
|
now = Time.now
|
83
|
-
|
83
|
+
|
84
84
|
date = Redistat::Date.new(now)
|
85
85
|
date.depth.should be_nil
|
86
86
|
date.to_s.should == now.to_rs(:sec).to_s
|
87
87
|
date.to_s.should == now.to_rs.to_s(:sec)
|
88
|
-
|
88
|
+
|
89
89
|
date = Redistat::Date.new(now, :hour)
|
90
90
|
date.depth.should == :hour
|
91
91
|
date.to_s.should == now.to_rs(:hour).to_s
|
92
92
|
date.to_s.should == now.to_rs.to_s(:hour)
|
93
93
|
end
|
94
|
-
|
95
|
-
end
|
94
|
+
|
95
|
+
end
|
data/spec/event_spec.rb
CHANGED
@@ -2,7 +2,7 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Redistat::Event do
|
4
4
|
include Redistat::Database
|
5
|
-
|
5
|
+
|
6
6
|
before(:each) do
|
7
7
|
db.flushdb
|
8
8
|
@scope = "PageViews"
|
@@ -14,7 +14,7 @@ describe Redistat::Event do
|
|
14
14
|
@date = Time.now
|
15
15
|
@event = Redistat::Event.new(@scope, @label, @date, @stats, @options, @meta)
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
it "should initialize properly" do
|
19
19
|
@event.id.should be_nil
|
20
20
|
@event.scope.to_s.should == @scope
|
@@ -41,7 +41,7 @@ describe Redistat::Event do
|
|
41
41
|
@event.label.to_s.should == @label
|
42
42
|
@event.label_hash.should == @label_hash
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
it "should increment next_id" do
|
46
46
|
event = Redistat::Event.new("VisitorCount", @label, @date, @stats, @options, @meta)
|
47
47
|
@event.next_id.should == 1
|
@@ -49,7 +49,7 @@ describe Redistat::Event do
|
|
49
49
|
@event.next_id.should == 2
|
50
50
|
event.next_id.should == 2
|
51
51
|
end
|
52
|
-
|
52
|
+
|
53
53
|
it "should store event properly" do
|
54
54
|
@event = Redistat::Event.new(@scope, @label, @date, @stats, @options.merge({:store_event => true}), @meta)
|
55
55
|
@event.new?.should be_true
|
@@ -59,7 +59,7 @@ describe Redistat::Event do
|
|
59
59
|
keys.should include("#{@event.scope}#{Redistat::KEY_EVENT}#{@event.id}")
|
60
60
|
keys.should include("#{@event.scope}#{Redistat::KEY_EVENT_IDS}")
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
it "should find event by id" do
|
64
64
|
@event = Redistat::Event.new(@scope, @label, @date, @stats, @options.merge({:store_event => true}), @meta).save
|
65
65
|
fetched = Redistat::Event.find(@scope, @event.id)
|
@@ -69,7 +69,7 @@ describe Redistat::Event do
|
|
69
69
|
@event.stats.should == fetched.stats
|
70
70
|
@event.meta.should == fetched.meta
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "should store summarized statistics" do
|
74
74
|
2.times do |i|
|
75
75
|
@event = Redistat::Event.new(@scope, @label, @date, @stats, @options, @meta).save
|
@@ -81,5 +81,5 @@ describe Redistat::Event do
|
|
81
81
|
end
|
82
82
|
end
|
83
83
|
end
|
84
|
-
|
85
|
-
end
|
84
|
+
|
85
|
+
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Redistat::Finder::DateSet do
|
4
|
-
|
4
|
+
|
5
5
|
before(:all) do
|
6
6
|
@finder = Redistat::Finder::DateSet.new
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should initialize properly" do
|
10
10
|
t_start = Time.utc(2010, 8, 28, 22, 54, 57)
|
11
11
|
t_end = Time.utc(2013, 12, 4, 22, 52, 3)
|
@@ -20,508 +20,508 @@ describe Redistat::Finder::DateSet do
|
|
20
20
|
{ :add => ["2011", "2012"], :rem => [] }
|
21
21
|
]
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
it "should find date sets by interval" do
|
25
25
|
t_start = Time.utc(2010, 8, 28, 18, 54, 57)
|
26
|
-
|
26
|
+
|
27
27
|
t_end = t_start + 4.hours
|
28
28
|
result = Redistat::Finder::DateSet.new.find_date_sets(t_start, t_end, :hour, true)
|
29
29
|
result[0][:add].should == ["2010082818", "2010082819", "2010082820", "2010082821", "2010082822"]
|
30
30
|
result[0][:rem].should == []
|
31
31
|
result.should == Redistat::Finder::DateSet.new(t_start, t_end, nil, :hour)
|
32
|
-
|
32
|
+
|
33
33
|
t_end = t_start + 4.days
|
34
34
|
result = Redistat::Finder::DateSet.new.find_date_sets(t_start, t_end, :day, true)
|
35
35
|
result[0][:add].should == ["20100828", "20100829", "20100830", "20100831", "20100901"]
|
36
36
|
result[0][:rem].should == []
|
37
37
|
result.should == Redistat::Finder::DateSet.new(t_start, t_end, nil, :day)
|
38
38
|
end
|
39
|
-
|
39
|
+
|
40
40
|
it "should find start keys properly" do
|
41
|
-
|
41
|
+
|
42
42
|
#
|
43
43
|
# Simple fetching
|
44
44
|
# Dates: 22:54, 26th August, 2010 --> 22:52, 14th December, 2010
|
45
45
|
#
|
46
|
-
|
46
|
+
|
47
47
|
t_start = Time.utc(2010, 8, 26, 22, 54, 57)
|
48
48
|
t_end = Time.utc(2013, 12, 14, 22, 52, 3)
|
49
|
-
|
49
|
+
|
50
50
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end)
|
51
51
|
result[:add].should == ["20100826225458", "20100826225459"]
|
52
52
|
result[:rem].should == []
|
53
|
-
|
53
|
+
|
54
54
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
55
55
|
result[:add].should == ["201008262255", "201008262256", "201008262257", "201008262258", "201008262259"]
|
56
56
|
result[:rem].should == []
|
57
|
-
|
57
|
+
|
58
58
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
59
59
|
result[:add].should == ["2010082623"]
|
60
60
|
result[:rem].should == []
|
61
|
-
|
61
|
+
|
62
62
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
63
63
|
result[:add].should == ["20100827", "20100828", "20100829", "20100830", "20100831"]
|
64
64
|
result[:rem].should == []
|
65
|
-
|
65
|
+
|
66
66
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end)
|
67
67
|
result[:add].should == ["201009", "201010", "201011", "201012"]
|
68
68
|
result[:rem].should == []
|
69
|
-
|
69
|
+
|
70
70
|
result = @finder.send(:find_start_keys_for, :year, t_start, t_end)
|
71
71
|
result[:add].should == ["2011", "2012"]
|
72
72
|
result[:rem].should == []
|
73
|
-
|
73
|
+
|
74
74
|
#
|
75
75
|
# Reverse / Inteligent fetching
|
76
76
|
# Dates: 5:06, 4th April, 2010 --> 22:52, 14th February, 2011
|
77
77
|
#
|
78
|
-
|
78
|
+
|
79
79
|
t_start = Time.utc(2010, 4, 4, 5, 6, 4)
|
80
80
|
t_end = Time.utc(2011, 2, 14, 22, 52, 3)
|
81
|
-
|
81
|
+
|
82
82
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end)
|
83
83
|
result[:add].should == ["201004040506"]
|
84
84
|
result[:rem].should == ["20100404050600", "20100404050601", "20100404050602", "20100404050603", "20100404050604"]
|
85
|
-
|
85
|
+
|
86
86
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
87
87
|
result[:add].should == ["2010040405"]
|
88
88
|
result[:rem].should == ["201004040500", "201004040501", "201004040502", "201004040503", "201004040504", "201004040505", "201004040506"]
|
89
|
-
|
89
|
+
|
90
90
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
91
91
|
result[:add].should == ["20100404"]
|
92
92
|
result[:rem].should == ["2010040400", "2010040401", "2010040402", "2010040403", "2010040404", "2010040405"]
|
93
|
-
|
93
|
+
|
94
94
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
95
95
|
result[:add].should == ["201004"]
|
96
96
|
result[:rem].should == ["20100401", "20100402", "20100403", "20100404"]
|
97
|
-
|
97
|
+
|
98
98
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end)
|
99
99
|
result[:add].should == ["2010"]
|
100
100
|
result[:rem].should == ["201001", "201002", "201003", "201004"]
|
101
|
-
|
101
|
+
|
102
102
|
result = @finder.send(:find_start_keys_for, :year, t_start, t_end)
|
103
103
|
result[:add].should == []
|
104
104
|
result[:rem].should == []
|
105
|
-
|
105
|
+
|
106
106
|
end
|
107
|
-
|
107
|
+
|
108
108
|
it "should find end keys properly" do
|
109
|
-
|
109
|
+
|
110
110
|
#
|
111
111
|
# Simple fetching
|
112
112
|
# Dates: 22:04, 26th December, 2007 --> 5:06, 7th May, 2010
|
113
113
|
#
|
114
|
-
|
114
|
+
|
115
115
|
t_start = Time.utc(2007, 12, 26, 22, 4, 4)
|
116
116
|
t_end = Time.utc(2010, 5, 7, 5, 6, 3)
|
117
|
-
|
117
|
+
|
118
118
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end)
|
119
119
|
result[:add].should == ["20100507050600", "20100507050601", "20100507050602"]
|
120
120
|
result[:rem].should == []
|
121
|
-
|
121
|
+
|
122
122
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
123
123
|
result[:add].should == ["201005070500", "201005070501", "201005070502", "201005070503", "201005070504", "201005070505"]
|
124
124
|
result[:rem].should == []
|
125
|
-
|
125
|
+
|
126
126
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
127
127
|
result[:add].should == ["2010050700", "2010050701", "2010050702", "2010050703", "2010050704"]
|
128
128
|
result[:rem].should == []
|
129
|
-
|
129
|
+
|
130
130
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
131
131
|
result[:add].should == ["20100501", "20100502", "20100503", "20100504", "20100505", "20100506"]
|
132
132
|
result[:rem].should == []
|
133
|
-
|
133
|
+
|
134
134
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end)
|
135
135
|
result[:add].should == ["201001", "201002", "201003", "201004"]
|
136
136
|
result[:rem].should == []
|
137
|
-
|
137
|
+
|
138
138
|
result = @finder.send(:find_end_keys_for, :year, t_start, t_end)
|
139
139
|
result[:add].should == []
|
140
140
|
result[:rem].should == []
|
141
|
-
|
141
|
+
|
142
142
|
#
|
143
143
|
# Reverse / Inteligent fetching
|
144
144
|
# Dates: 22:04, 26th December, 2009 --> 22:56, 27th October, 2010
|
145
145
|
#
|
146
|
-
|
146
|
+
|
147
147
|
t_start = Time.utc(2009, 12, 26, 22, 4, 4)
|
148
148
|
t_end = Time.utc(2010, 10, 27, 22, 56, 57)
|
149
|
-
|
149
|
+
|
150
150
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end)
|
151
151
|
result[:add].should == ["201010272256"]
|
152
152
|
result[:rem].should == ["20101027225657", "20101027225658", "20101027225659"]
|
153
|
-
|
153
|
+
|
154
154
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
155
155
|
result[:add].should == ["2010102722"]
|
156
156
|
result[:rem].should == ["201010272256", "201010272257", "201010272258", "201010272259"]
|
157
|
-
|
157
|
+
|
158
158
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
159
159
|
result[:add].should == ["20101027"]
|
160
160
|
result[:rem].should == ["2010102722", "2010102723"]
|
161
|
-
|
161
|
+
|
162
162
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
163
163
|
result[:add].should == ["201010"]
|
164
164
|
result[:rem].should == ["20101027", "20101028", "20101029", "20101030", "20101031"]
|
165
|
-
|
165
|
+
|
166
166
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end)
|
167
167
|
result[:add].should == ["2010"]
|
168
168
|
result[:rem].should == ["201010", "201011", "201012"]
|
169
|
-
|
169
|
+
|
170
170
|
result = @finder.send(:find_end_keys_for, :year, t_start, t_end)
|
171
171
|
result[:add].should == []
|
172
172
|
result[:rem].should == []
|
173
|
-
|
173
|
+
|
174
174
|
end
|
175
|
-
|
175
|
+
|
176
176
|
it "should fetch start/end keys with limits" do
|
177
|
-
|
177
|
+
|
178
178
|
#
|
179
179
|
# Simple fetching with Limits
|
180
180
|
#
|
181
|
-
|
181
|
+
|
182
182
|
# seconds
|
183
183
|
t_start = Time.utc(2010, 8, 26, 20, 54, 45)
|
184
184
|
t_end = t_start + 4.seconds
|
185
|
-
|
185
|
+
|
186
186
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end)
|
187
187
|
result[:add].should == ["20100826205446", "20100826205447", "20100826205448"]
|
188
188
|
result[:rem].should == []
|
189
|
-
|
189
|
+
|
190
190
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end)
|
191
191
|
result[:add].should == []
|
192
192
|
result[:rem].should == []
|
193
|
-
|
193
|
+
|
194
194
|
t_start = Time.utc(2010, 8, 26, 20, 54, 4)
|
195
195
|
t_end = t_start + 4.seconds
|
196
|
-
|
196
|
+
|
197
197
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end)
|
198
198
|
result[:add].should == ["20100826205405", "20100826205406", "20100826205407"]
|
199
199
|
result[:rem].should == []
|
200
|
-
|
200
|
+
|
201
201
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end)
|
202
202
|
result[:add].should == []
|
203
203
|
result[:rem].should == []
|
204
|
-
|
204
|
+
|
205
205
|
# minutes
|
206
206
|
t_start = Time.utc(2010, 8, 26, 20, 54)
|
207
207
|
t_end = t_start + 4.minutes
|
208
|
-
|
208
|
+
|
209
209
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
210
210
|
result[:add].should == ["201008262055", "201008262056", "201008262057"]
|
211
211
|
result[:rem].should == []
|
212
|
-
|
212
|
+
|
213
213
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
214
214
|
result[:add].should == []
|
215
215
|
result[:rem].should == []
|
216
|
-
|
216
|
+
|
217
217
|
t_start = Time.utc(2010, 8, 26, 20, 4)
|
218
218
|
t_end = t_start + 4.minutes
|
219
|
-
|
219
|
+
|
220
220
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
221
221
|
result[:add].should == ["201008262005", "201008262006", "201008262007"]
|
222
222
|
result[:rem].should == []
|
223
|
-
|
223
|
+
|
224
224
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
225
225
|
result[:add].should == []
|
226
226
|
result[:rem].should == []
|
227
|
-
|
227
|
+
|
228
228
|
# hours
|
229
229
|
t_start = Time.utc(2010, 8, 26, 20, 54)
|
230
230
|
t_end = t_start + 2.hours
|
231
|
-
|
231
|
+
|
232
232
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
233
233
|
result[:add].should == ["201008262055", "201008262056", "201008262057", "201008262058", "201008262059"]
|
234
234
|
result[:rem].should == []
|
235
|
-
|
235
|
+
|
236
236
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
237
237
|
result[:add].should == ["2010082621"]
|
238
238
|
result[:rem].should == []
|
239
|
-
|
239
|
+
|
240
240
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
241
241
|
result[:add].should == []
|
242
242
|
result[:rem].should == []
|
243
|
-
|
243
|
+
|
244
244
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
245
245
|
result[:add].should == ["2010082622"]
|
246
246
|
result[:rem].should == ["201008262254", "201008262255", "201008262256", "201008262257", "201008262258", "201008262259"]
|
247
|
-
|
247
|
+
|
248
248
|
t_start = Time.utc(2010, 8, 26, 4, 54)
|
249
249
|
t_end = t_start + 5.hours
|
250
|
-
|
250
|
+
|
251
251
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
252
252
|
result[:add].should == ["201008260455", "201008260456", "201008260457", "201008260458", "201008260459"]
|
253
253
|
result[:rem].should == []
|
254
|
-
|
254
|
+
|
255
255
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
256
256
|
result[:add].should == ["2010082605", "2010082606", "2010082607", "2010082608"]
|
257
257
|
result[:rem].should == []
|
258
|
-
|
258
|
+
|
259
259
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
260
260
|
result[:add].should == []
|
261
261
|
result[:rem].should == []
|
262
|
-
|
262
|
+
|
263
263
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
264
264
|
result[:add].should == ["2010082609"]
|
265
265
|
result[:rem].should == ["201008260954", "201008260955", "201008260956", "201008260957", "201008260958", "201008260959"]
|
266
|
-
|
266
|
+
|
267
267
|
# days
|
268
268
|
t_start = Time.utc(2010, 8, 26, 20, 54)
|
269
269
|
t_end = t_start + 2.day
|
270
|
-
|
270
|
+
|
271
271
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
272
272
|
result[:add].should == ["201008262055", "201008262056", "201008262057", "201008262058", "201008262059"]
|
273
273
|
result[:rem].should == []
|
274
|
-
|
274
|
+
|
275
275
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
276
276
|
result[:add].should == ["2010082621", "2010082622", "2010082623"]
|
277
277
|
result[:rem].should == []
|
278
|
-
|
278
|
+
|
279
279
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
280
280
|
result[:add].should == ["20100827"]
|
281
281
|
result[:rem].should == []
|
282
|
-
|
282
|
+
|
283
283
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
284
284
|
result[:add].should == []
|
285
285
|
result[:rem].should == []
|
286
|
-
|
286
|
+
|
287
287
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
288
288
|
result[:add].should == ["20100828"]
|
289
289
|
result[:rem].should == ["2010082820", "2010082821", "2010082822", "2010082823"]
|
290
|
-
|
290
|
+
|
291
291
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
292
292
|
result[:add].should == ["2010082820"]
|
293
293
|
result[:rem].should == ["201008282054", "201008282055", "201008282056", "201008282057", "201008282058", "201008282059"]
|
294
|
-
|
294
|
+
|
295
295
|
t_start = Time.utc(2010, 8, 6, 20, 54)
|
296
296
|
t_end = t_start + 2.day
|
297
|
-
|
297
|
+
|
298
298
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
299
299
|
result[:add].should == ["201008062055", "201008062056", "201008062057", "201008062058", "201008062059"]
|
300
300
|
result[:rem].should == []
|
301
|
-
|
301
|
+
|
302
302
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
303
303
|
result[:add].should == ["2010080621", "2010080622", "2010080623"]
|
304
304
|
result[:rem].should == []
|
305
|
-
|
305
|
+
|
306
306
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
307
307
|
result[:add].should == ["20100807"]
|
308
308
|
result[:rem].should == []
|
309
|
-
|
309
|
+
|
310
310
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
311
311
|
result[:add].should == []
|
312
312
|
result[:rem].should == []
|
313
|
-
|
313
|
+
|
314
314
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
315
315
|
result[:add].should == ["20100808"]
|
316
316
|
result[:rem].should == ["2010080820", "2010080821", "2010080822", "2010080823"]
|
317
|
-
|
317
|
+
|
318
318
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
319
319
|
result[:add].should == ["2010080820"]
|
320
320
|
result[:rem].should == ["201008082054", "201008082055", "201008082056", "201008082057", "201008082058", "201008082059"]
|
321
|
-
|
321
|
+
|
322
322
|
# months
|
323
323
|
t_start = Time.utc(2010, 8, 26, 20, 54)
|
324
324
|
t_end = t_start + 3.months
|
325
|
-
|
325
|
+
|
326
326
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
327
327
|
result[:add].should == ["201008262055", "201008262056", "201008262057", "201008262058", "201008262059"]
|
328
328
|
result[:rem].should == []
|
329
|
-
|
329
|
+
|
330
330
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
331
331
|
result[:add].should == ["2010082621", "2010082622", "2010082623"]
|
332
332
|
result[:rem].should == []
|
333
|
-
|
333
|
+
|
334
334
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
335
335
|
result[:add].should == ["20100827", "20100828", "20100829", "20100830", "20100831"]
|
336
336
|
result[:rem].should == []
|
337
|
-
|
337
|
+
|
338
338
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end)
|
339
339
|
result[:add].should == ["201009", "201010"]
|
340
340
|
result[:rem].should == []
|
341
|
-
|
341
|
+
|
342
342
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end)
|
343
343
|
result[:add].should == []
|
344
344
|
result[:rem].should == []
|
345
|
-
|
345
|
+
|
346
346
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
347
347
|
result[:add].should == ["201011"]
|
348
348
|
result[:rem].should == ["20101126", "20101127", "20101128", "20101129", "20101130"]
|
349
|
-
|
349
|
+
|
350
350
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
351
351
|
result[:add].should == ["20101126"]
|
352
352
|
result[:rem].should == ["2010112620", "2010112621", "2010112622", "2010112623"]
|
353
|
-
|
353
|
+
|
354
354
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
355
355
|
result[:add].should == ["2010112620"]
|
356
356
|
result[:rem].should == ["201011262054", "201011262055", "201011262056", "201011262057", "201011262058", "201011262059"]
|
357
|
-
|
357
|
+
|
358
358
|
t_start = Time.utc(2010, 4, 26, 20, 54)
|
359
359
|
t_end = t_start + 3.months
|
360
|
-
|
360
|
+
|
361
361
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end)
|
362
362
|
result[:add].should == ["201004262055", "201004262056", "201004262057", "201004262058", "201004262059"]
|
363
363
|
result[:rem].should == []
|
364
|
-
|
364
|
+
|
365
365
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end)
|
366
366
|
result[:add].should == ["2010042621", "2010042622", "2010042623"]
|
367
367
|
result[:rem].should == []
|
368
|
-
|
368
|
+
|
369
369
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end)
|
370
370
|
result[:add].should == ["20100427", "20100428", "20100429", "20100430"]
|
371
371
|
result[:rem].should == []
|
372
|
-
|
372
|
+
|
373
373
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end)
|
374
374
|
result[:add].should == ["201005", "201006"]
|
375
375
|
result[:rem].should == []
|
376
|
-
|
376
|
+
|
377
377
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end)
|
378
378
|
result[:add].should == []
|
379
379
|
result[:rem].should == []
|
380
|
-
|
380
|
+
|
381
381
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end)
|
382
382
|
result[:add].should == ["201007"]
|
383
383
|
result[:rem].should == ["20100726", "20100727", "20100728", "20100729", "20100730", "20100731"]
|
384
|
-
|
384
|
+
|
385
385
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end)
|
386
386
|
result[:add].should == ["20100726"]
|
387
387
|
result[:rem].should == ["2010072620", "2010072621", "2010072622", "2010072623"]
|
388
|
-
|
388
|
+
|
389
389
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end)
|
390
390
|
result[:add].should == ["2010072620"]
|
391
391
|
result[:rem].should == ["201007262054", "201007262055", "201007262056", "201007262057", "201007262058", "201007262059"]
|
392
|
-
|
392
|
+
|
393
393
|
end
|
394
|
-
|
394
|
+
|
395
395
|
it "should find inclusive keys on lowest depth" do
|
396
|
-
|
396
|
+
|
397
397
|
#
|
398
398
|
# Simple start fetching
|
399
399
|
# Dates: 22:54, 26th August, 2010 --> 22:52, 14th December, 2010
|
400
400
|
#
|
401
|
-
|
401
|
+
|
402
402
|
t_start = Time.utc(2010, 8, 26, 22, 54, 57)
|
403
403
|
t_end = Time.utc(2013, 12, 14, 22, 52, 3)
|
404
|
-
|
404
|
+
|
405
405
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end, true)
|
406
406
|
result[:add].should == ["20100826225457", "20100826225458", "20100826225459"]
|
407
407
|
result[:rem].should == []
|
408
|
-
|
408
|
+
|
409
409
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end, true)
|
410
410
|
result[:add].should == ["201008262254", "201008262255", "201008262256", "201008262257", "201008262258", "201008262259"]
|
411
411
|
result[:rem].should == []
|
412
|
-
|
412
|
+
|
413
413
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end, true)
|
414
414
|
result[:add].should == ["2010082622", "2010082623"]
|
415
415
|
result[:rem].should == []
|
416
|
-
|
416
|
+
|
417
417
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end, true)
|
418
418
|
result[:add].should == ["20100826", "20100827", "20100828", "20100829", "20100830", "20100831"]
|
419
419
|
result[:rem].should == []
|
420
|
-
|
420
|
+
|
421
421
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end, true)
|
422
422
|
result[:add].should == ["201008", "201009", "201010", "201011", "201012"]
|
423
423
|
result[:rem].should == []
|
424
|
-
|
424
|
+
|
425
425
|
result = @finder.send(:find_start_keys_for, :year, t_start, t_end, true)
|
426
426
|
result[:add].should == ["2011", "2012", "2013"]
|
427
427
|
result[:rem].should == []
|
428
|
-
|
428
|
+
|
429
429
|
#
|
430
430
|
# Reverse / Inteligent start fetching
|
431
431
|
# Dates: 5:06, 4th April, 2010 --> 22:52, 14th February, 2011
|
432
432
|
#
|
433
|
-
|
433
|
+
|
434
434
|
t_start = Time.utc(2010, 4, 4, 5, 6, 4)
|
435
435
|
t_end = Time.utc(2013, 2, 14, 22, 52, 3)
|
436
|
-
|
436
|
+
|
437
437
|
result = @finder.send(:find_start_keys_for, :sec, t_start, t_end, true)
|
438
438
|
result[:add].should == ["201004040506"]
|
439
439
|
result[:rem].should == ["20100404050600", "20100404050601", "20100404050602", "20100404050603"]
|
440
|
-
|
440
|
+
|
441
441
|
result = @finder.send(:find_start_keys_for, :min, t_start, t_end, true)
|
442
442
|
result[:add].should == ["2010040405"]
|
443
443
|
result[:rem].should == ["201004040500", "201004040501", "201004040502", "201004040503", "201004040504", "201004040505"]
|
444
|
-
|
444
|
+
|
445
445
|
result = @finder.send(:find_start_keys_for, :hour, t_start, t_end, true)
|
446
446
|
result[:add].should == ["20100404"]
|
447
447
|
result[:rem].should == ["2010040400", "2010040401", "2010040402", "2010040403", "2010040404"]
|
448
|
-
|
448
|
+
|
449
449
|
result = @finder.send(:find_start_keys_for, :day, t_start, t_end, true)
|
450
450
|
result[:add].should == ["201004"]
|
451
451
|
result[:rem].should == ["20100401", "20100402", "20100403"]
|
452
|
-
|
452
|
+
|
453
453
|
result = @finder.send(:find_start_keys_for, :month, t_start, t_end, true)
|
454
454
|
result[:add].should == ["2010"]
|
455
455
|
result[:rem].should == ["201001", "201002", "201003"]
|
456
|
-
|
456
|
+
|
457
457
|
result = @finder.send(:find_start_keys_for, :year, t_start, t_end, true)
|
458
458
|
result[:add].should == ["2011", "2012", "2013"]
|
459
459
|
result[:rem].should == []
|
460
|
-
|
460
|
+
|
461
461
|
#
|
462
462
|
# Simple fetching
|
463
463
|
# Dates: 22:04, 26th December, 2007 --> 5:06, 7th May, 2010
|
464
464
|
#
|
465
|
-
|
465
|
+
|
466
466
|
t_start = Time.utc(2007, 12, 26, 22, 4, 4)
|
467
467
|
t_end = Time.utc(2010, 5, 7, 5, 6, 3)
|
468
|
-
|
468
|
+
|
469
469
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end, true)
|
470
470
|
result[:add].should == ["20100507050600", "20100507050601", "20100507050602", "20100507050603"]
|
471
471
|
result[:rem].should == []
|
472
|
-
|
472
|
+
|
473
473
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end, true)
|
474
474
|
result[:add].should == ["201005070500", "201005070501", "201005070502", "201005070503", "201005070504", "201005070505", "201005070506"]
|
475
475
|
result[:rem].should == []
|
476
|
-
|
476
|
+
|
477
477
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end, true)
|
478
478
|
result[:add].should == ["2010050700", "2010050701", "2010050702", "2010050703", "2010050704", "2010050705"]
|
479
479
|
result[:rem].should == []
|
480
|
-
|
480
|
+
|
481
481
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end, true)
|
482
482
|
result[:add].should == ["20100501", "20100502", "20100503", "20100504", "20100505", "20100506", "20100507"]
|
483
483
|
result[:rem].should == []
|
484
|
-
|
484
|
+
|
485
485
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end, true)
|
486
486
|
result[:add].should == ["201001", "201002", "201003", "201004", "201005"]
|
487
487
|
result[:rem].should == []
|
488
|
-
|
488
|
+
|
489
489
|
result = @finder.send(:find_end_keys_for, :year, t_start, t_end, true)
|
490
490
|
result[:add].should == ["2010"]
|
491
491
|
result[:rem].should == []
|
492
|
-
|
492
|
+
|
493
493
|
#
|
494
494
|
# Reverse / Inteligent fetching
|
495
495
|
# Dates: 22:04, 26th December, 2009 --> 22:56, 27th October, 2010
|
496
496
|
#
|
497
|
-
|
497
|
+
|
498
498
|
t_start = Time.utc(2009, 12, 26, 22, 4, 4)
|
499
499
|
t_end = Time.utc(2010, 10, 27, 22, 56, 57)
|
500
|
-
|
500
|
+
|
501
501
|
result = @finder.send(:find_end_keys_for, :sec, t_start, t_end, true)
|
502
502
|
result[:add].should == ["201010272256"]
|
503
503
|
result[:rem].should == ["20101027225658", "20101027225659"]
|
504
|
-
|
504
|
+
|
505
505
|
result = @finder.send(:find_end_keys_for, :min, t_start, t_end, true)
|
506
506
|
result[:add].should == ["2010102722"]
|
507
507
|
result[:rem].should == ["201010272257", "201010272258", "201010272259"]
|
508
|
-
|
508
|
+
|
509
509
|
result = @finder.send(:find_end_keys_for, :hour, t_start, t_end, true)
|
510
510
|
result[:add].should == ["20101027"]
|
511
511
|
result[:rem].should == ["2010102723"]
|
512
|
-
|
512
|
+
|
513
513
|
result = @finder.send(:find_end_keys_for, :day, t_start, t_end, true)
|
514
514
|
result[:add].should == ["201010"]
|
515
515
|
result[:rem].should == ["20101028", "20101029", "20101030", "20101031"]
|
516
|
-
|
516
|
+
|
517
517
|
result = @finder.send(:find_end_keys_for, :month, t_start, t_end, true)
|
518
518
|
result[:add].should == ["2010"]
|
519
519
|
result[:rem].should == ["201011", "201012"]
|
520
|
-
|
520
|
+
|
521
521
|
result = @finder.send(:find_end_keys_for, :year, t_start, t_end, true)
|
522
522
|
result[:add].should == ["2010"]
|
523
523
|
result[:rem].should == []
|
524
|
-
|
524
|
+
|
525
525
|
end
|
526
|
-
|
527
|
-
end
|
526
|
+
|
527
|
+
end
|