time_window_drop_collector 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,6 +14,8 @@ class TimeWindowDropCollector::Storage
14
14
  end
15
15
 
16
16
  def count( keys )
17
+ return {} if keys.empty?
18
+
17
19
  window_keys = window_keys_multi( keys )
18
20
  keys_values = wrapper.get( window_keys )
19
21
 
@@ -1,3 +1,3 @@
1
1
  class TimeWindowDropCollector
2
- VERSION = "0.3.1"
2
+ VERSION = "0.3.2"
3
3
  end
@@ -2,20 +2,14 @@ require_relative "test_helper"
2
2
 
3
3
  class MemcacheWrapperTest < Test::Unit::TestCase
4
4
  def test_initialize
5
- Dalli::Client.expects( :new ).with( "arg1" ).returns( "client" )
5
+ Dalli::Client.expects( :new ).with( ["arg1"] ).returns( "client" )
6
6
  wrapper = TimeWindowDropCollector::Wrappers::Memcache.new( ["arg1"] )
7
7
  assert_equal( "client", wrapper.client )
8
8
  end
9
9
 
10
10
  def test_incr
11
11
  wrapper = TimeWindowDropCollector::Wrappers::Memcache.new( ["arg1"] )
12
- wrapper.client.expects( :incr ).with( "key", 5, "expire_time", 1 )
13
- wrapper.incr( "key", "expire_time", 5 )
14
- end
15
-
16
- def test_values_for
17
- wrapper = TimeWindowDropCollector::Wrappers::Memcache.new( ["arg1"] )
18
- wrapper.client.expects( :get_multi ).with( "keys" ).returns( {:a => 1, :b => 2} )
19
- assert_equal( [1, 2], wrapper.values_for( "keys" ))
12
+ wrapper.client.expects( :incr ).with( "key", 5, "expire_time", 1)
13
+ wrapper.incr( ["key"], "expire_time", 5 )
20
14
  end
21
15
  end
data/test/storage_test.rb CHANGED
@@ -7,13 +7,13 @@ class StorageTest < Test::Unit::TestCase
7
7
  end
8
8
 
9
9
  def test_timestamp_key_when_time_is_present
10
- timestamp = Time.new( 2001, 2, 3, 4, 5 )
11
- assert_equal( "drop_window_key_981169500000", @storage.timestamp_key( "key", timestamp ) )
10
+ timestamp = Time.new(2001, 2, 3, 4, 5, 0, "+01:00")
11
+ assert_equal("drop_window_key_981169500000", @storage.timestamp_key("key", timestamp))
12
12
  end
13
13
 
14
14
  def test_timestamp_key_when_time_is_not_present
15
- @storage.stubs( :timestamp ).returns( Time.new( 2012, 4, 3, 2, 1 ))
16
- assert_equal( "drop_window_key_1333411260000", @storage.timestamp_key( "key" ))
15
+ @storage.stubs(:timestamp).returns(Time.new(2012, 4, 3, 2, 1, 0, "+02:00"))
16
+ assert_equal("drop_window_key_1333411260000", @storage.timestamp_key("key"))
17
17
  end
18
18
 
19
19
  def test_window_keys_should_return_10_keys_for_the_last_10_minutes
@@ -30,8 +30,8 @@ class StorageTest < Test::Unit::TestCase
30
30
  "drop_window_key_1325560260000"
31
31
  ]
32
32
 
33
- Delorean.time_travel_to( '2012-01-03 04:20' ) do
34
- assert_equal( keys, @storage.window_keys( "key" ))
33
+ Delorean.time_travel_to('2012-01-03 04:20 +01:00') do
34
+ assert_equal(keys, @storage.window_keys("key"))
35
35
  end
36
36
  end
37
37
 
@@ -57,6 +57,10 @@ class StorageTest < Test::Unit::TestCase
57
57
  assert_equal( "grouping_keys_counts", @storage.count( "keys" ))
58
58
  end
59
59
 
60
+ def test_count_with_no_keys
61
+ assert_equal({}, @storage.count([]))
62
+ end
63
+
60
64
  def test_grouping_count
61
65
  key_values = {
62
66
  "drop_window_key1_201201031416" => 1,
@@ -122,19 +126,19 @@ class StorageTest < Test::Unit::TestCase
122
126
  end
123
127
 
124
128
  def test_slice_start_timestamp
125
- storage = TimeWindowDropCollector::Storage.new( nil, 100, 10 )
126
- time = Time.new( 2001, 2, 3, 4, 5 )
127
-
128
- assert_equal( 981169500000, storage.slice_start_timestamp( time ) )
129
- assert_equal( 981169500000, storage.slice_start_timestamp( time + 1 ) )
130
- assert_equal( 981169500000, storage.slice_start_timestamp( time + 9 ) )
131
- assert_equal( 981169520000, storage.slice_start_timestamp( time + 25 ) )
132
- assert_equal( 981169600000, storage.slice_start_timestamp( time + 100 ) )
129
+ storage = TimeWindowDropCollector::Storage.new(nil, 100, 10)
130
+ time = Time.new(2001, 2, 3, 4, 5, 0, '+01:00')
131
+
132
+ assert_equal(981169500000, storage.slice_start_timestamp(time))
133
+ assert_equal(981169500000, storage.slice_start_timestamp(time + 1))
134
+ assert_equal(981169500000, storage.slice_start_timestamp(time + 9))
135
+ assert_equal(981169520000, storage.slice_start_timestamp(time + 25))
136
+ assert_equal(981169600000, storage.slice_start_timestamp(time + 100))
133
137
  end
134
138
 
135
139
  def test_slice_start_timestamp_with_slice_sizes_no_integer
136
140
  storage = TimeWindowDropCollector::Storage.new( nil, 100, 12 )
137
- time = Time.new( 2001, 2, 3, 4, 5 )
141
+ time = Time.new( 2001, 2, 3, 4, 5, 0,'+01:00')
138
142
 
139
143
  assert_equal( 981169493317, storage.slice_start_timestamp( time ) )
140
144
  assert_equal( 981169493317, storage.slice_start_timestamp( time + 1 ) )
@@ -144,14 +148,14 @@ class StorageTest < Test::Unit::TestCase
144
148
  end
145
149
 
146
150
  def test_slice_start_timestamp_with_slice_size_less_than_a_second
147
- storage = TimeWindowDropCollector::Storage.new( nil, 100, 101 )
148
- time = Time.new( 2001, 2, 3, 4, 5 )
149
-
150
- assert_equal( 981169499970, storage.slice_start_timestamp( time ) )
151
- assert_equal( 981169500960, storage.slice_start_timestamp( time + 1 ) )
152
- assert_equal( 981169508880, storage.slice_start_timestamp( time + 9 ) )
153
- assert_equal( 981169524720, storage.slice_start_timestamp( time + 25 ) )
154
- assert_equal( 981169599960, storage.slice_start_timestamp( time + 100 ) )
151
+ storage = TimeWindowDropCollector::Storage.new(nil, 100, 101)
152
+ time = Time.new( 2001, 2, 3, 4, 5, 0, '+01:00')
153
+
154
+ assert_equal(981169499970, storage.slice_start_timestamp(time))
155
+ assert_equal(981169500960, storage.slice_start_timestamp(time + 1))
156
+ assert_equal(981169508880, storage.slice_start_timestamp(time + 9))
157
+ assert_equal(981169524720, storage.slice_start_timestamp(time + 25))
158
+ assert_equal(981169599960, storage.slice_start_timestamp(time + 100))
155
159
  end
156
160
 
157
161
  def test_window_size_consistency
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: time_window_drop_collector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,74 +10,104 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-12-19 00:00:00.000000000Z
13
+ date: 2013-10-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: bundler
17
- requirement: &70353016535360 !ruby/object:Gem::Requirement
18
- none: false
17
+ prerelease: false
18
+ requirement: !ruby/object:Gem::Requirement
19
19
  requirements:
20
20
  - - ! '>='
21
21
  - !ruby/object:Gem::Version
22
22
  version: '0'
23
+ none: false
23
24
  type: :development
24
- prerelease: false
25
- version_requirements: *70353016535360
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ none: false
26
31
  - !ruby/object:Gem::Dependency
27
32
  name: rake
28
- requirement: &70353016534860 !ruby/object:Gem::Requirement
29
- none: false
33
+ prerelease: false
34
+ requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - =
36
+ - - '='
32
37
  - !ruby/object:Gem::Version
33
38
  version: 0.9.2.2
39
+ none: false
34
40
  type: :development
35
- prerelease: false
36
- version_requirements: *70353016534860
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - '='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.9.2.2
46
+ none: false
37
47
  - !ruby/object:Gem::Dependency
38
48
  name: mocha
39
- requirement: &70353016534360 !ruby/object:Gem::Requirement
40
- none: false
49
+ prerelease: false
50
+ requirement: !ruby/object:Gem::Requirement
41
51
  requirements:
42
- - - =
52
+ - - '='
43
53
  - !ruby/object:Gem::Version
44
54
  version: 0.10.0
55
+ none: false
45
56
  type: :development
46
- prerelease: false
47
- version_requirements: *70353016534360
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.0
62
+ none: false
48
63
  - !ruby/object:Gem::Dependency
49
64
  name: delorean
50
- requirement: &70353016533900 !ruby/object:Gem::Requirement
51
- none: false
65
+ prerelease: false
66
+ requirement: !ruby/object:Gem::Requirement
52
67
  requirements:
53
- - - =
68
+ - - '='
54
69
  - !ruby/object:Gem::Version
55
70
  version: 1.2.0
71
+ none: false
56
72
  type: :development
57
- prerelease: false
58
- version_requirements: *70353016533900
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.2.0
78
+ none: false
59
79
  - !ruby/object:Gem::Dependency
60
80
  name: memcache_mock
61
- requirement: &70353016533440 !ruby/object:Gem::Requirement
62
- none: false
81
+ prerelease: false
82
+ requirement: !ruby/object:Gem::Requirement
63
83
  requirements:
64
- - - =
84
+ - - '='
65
85
  - !ruby/object:Gem::Version
66
86
  version: 0.0.1
87
+ none: false
67
88
  type: :development
68
- prerelease: false
69
- version_requirements: *70353016533440
89
+ version_requirements: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - '='
92
+ - !ruby/object:Gem::Version
93
+ version: 0.0.1
94
+ none: false
70
95
  - !ruby/object:Gem::Dependency
71
96
  name: dalli
72
- requirement: &70353016533060 !ruby/object:Gem::Requirement
73
- none: false
97
+ prerelease: false
98
+ requirement: !ruby/object:Gem::Requirement
74
99
  requirements:
75
100
  - - ! '>='
76
101
  - !ruby/object:Gem::Version
77
102
  version: '0'
103
+ none: false
78
104
  type: :runtime
79
- prerelease: false
80
- version_requirements: *70353016533060
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ none: false
81
111
  description: Counter storage system for a concrete time window
82
112
  email:
83
113
  - fguillen.mail@gmail.com
@@ -122,20 +152,20 @@ rdoc_options: []
122
152
  require_paths:
123
153
  - lib
124
154
  required_ruby_version: !ruby/object:Gem::Requirement
125
- none: false
126
155
  requirements:
127
156
  - - ! '>='
128
157
  - !ruby/object:Gem::Version
129
158
  version: '0'
130
- required_rubygems_version: !ruby/object:Gem::Requirement
131
159
  none: false
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
161
  requirements:
133
162
  - - ! '>='
134
163
  - !ruby/object:Gem::Version
135
164
  version: '0'
165
+ none: false
136
166
  requirements: []
137
167
  rubyforge_project: time_window_drop_collector
138
- rubygems_version: 1.8.15
168
+ rubygems_version: 1.8.24
139
169
  signing_key:
140
170
  specification_version: 3
141
171
  summary: Counter storage system for a concrete time window
@@ -150,3 +180,4 @@ test_files:
150
180
  - test/test_helper.rb
151
181
  - test/time_window_drop_collector_test.rb
152
182
  - test/wrapper_test.rb
183
+ has_rdoc: