pulse-meter-client-backport 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rbenv-version +1 -0
- data/.rspec +1 -0
- data/.rvmrc +1 -0
- data/.travis.yml +3 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/Procfile +3 -0
- data/README.md +98 -0
- data/Rakefile +53 -0
- data/bin/pulse +6 -0
- data/examples/readme_client_example.rb +52 -0
- data/lib/pulse-meter.rb +17 -0
- data/lib/pulse-meter/mixins/dumper.rb +76 -0
- data/lib/pulse-meter/mixins/utils.rb +93 -0
- data/lib/pulse-meter/sensor.rb +44 -0
- data/lib/pulse-meter/sensor/base.rb +75 -0
- data/lib/pulse-meter/sensor/counter.rb +36 -0
- data/lib/pulse-meter/sensor/hashed_counter.rb +31 -0
- data/lib/pulse-meter/sensor/indicator.rb +33 -0
- data/lib/pulse-meter/sensor/timeline.rb +180 -0
- data/lib/pulse-meter/sensor/timelined/average.rb +26 -0
- data/lib/pulse-meter/sensor/timelined/counter.rb +16 -0
- data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +22 -0
- data/lib/pulse-meter/sensor/timelined/max.rb +25 -0
- data/lib/pulse-meter/sensor/timelined/median.rb +14 -0
- data/lib/pulse-meter/sensor/timelined/min.rb +25 -0
- data/lib/pulse-meter/sensor/timelined/percentile.rb +31 -0
- data/lib/pulse-meter/version.rb +3 -0
- data/pulse-meter-client-backport.gemspec +33 -0
- data/spec/pulse_meter/mixins/dumper_spec.rb +141 -0
- data/spec/pulse_meter/mixins/utils_spec.rb +125 -0
- data/spec/pulse_meter/sensor/base_spec.rb +97 -0
- data/spec/pulse_meter/sensor/counter_spec.rb +54 -0
- data/spec/pulse_meter/sensor/hashed_counter_spec.rb +39 -0
- data/spec/pulse_meter/sensor/indicator_spec.rb +43 -0
- data/spec/pulse_meter/sensor/timeline_spec.rb +45 -0
- data/spec/pulse_meter/sensor/timelined/average_spec.rb +6 -0
- data/spec/pulse_meter/sensor/timelined/counter_spec.rb +6 -0
- data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +8 -0
- data/spec/pulse_meter/sensor/timelined/max_spec.rb +7 -0
- data/spec/pulse_meter/sensor/timelined/median_spec.rb +7 -0
- data/spec/pulse_meter/sensor/timelined/min_spec.rb +7 -0
- data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +17 -0
- data/spec/pulse_meter_spec.rb +16 -0
- data/spec/shared_examples/timeline_sensor.rb +274 -0
- data/spec/shared_examples/timelined_subclass.rb +23 -0
- data/spec/spec_helper.rb +21 -0
- data/spec/support/matchers.rb +45 -0
- metadata +276 -0
@@ -0,0 +1,23 @@
|
|
1
|
+
shared_examples_for "timelined subclass" do |events, result, extra_options|
|
2
|
+
let(:name){ :counter }
|
3
|
+
let(:ttl){ 100 }
|
4
|
+
let(:raw_data_ttl){ 10 }
|
5
|
+
let(:interval){ 5 }
|
6
|
+
let(:reduce_delay){ 3 }
|
7
|
+
let(:init_values){ {:ttl => ttl, :raw_data_ttl => raw_data_ttl, :interval => interval, :reduce_delay => reduce_delay}.merge(extra_options || {}) }
|
8
|
+
let(:sensor){ described_class.new(name, init_values) }
|
9
|
+
let(:epsilon) {1}
|
10
|
+
|
11
|
+
it "should calculate summarized value #{result.inspect} of #{events.inspect}" do
|
12
|
+
interval_id = 0
|
13
|
+
start_of_interval = Time.at(interval_id)
|
14
|
+
Timecop.freeze(start_of_interval) do
|
15
|
+
events.each {|e| sensor.event(e)}
|
16
|
+
end
|
17
|
+
Timecop.freeze(start_of_interval + interval) do
|
18
|
+
data = sensor.timeline(interval + epsilon).first
|
19
|
+
data.value.should be_generally_equal(result)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
$:.unshift File.expand_path('../../lib/', __FILE__)
|
4
|
+
|
5
|
+
ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
|
7
|
+
Bundler.require(:default, :test, :development)
|
8
|
+
|
9
|
+
require 'pulse-meter'
|
10
|
+
require 'rack/test'
|
11
|
+
|
12
|
+
Dir['spec/support/**/*.rb'].each{|f| require File.join(ROOT, f) }
|
13
|
+
Dir['spec/shared_examples/**/*.rb'].each{|f| require File.join(ROOT,f)}
|
14
|
+
|
15
|
+
RSpec.configure do |config|
|
16
|
+
config.before(:each) { PulseMeter.redis = MockRedis.new }
|
17
|
+
config.filter_run :focus => true
|
18
|
+
config.run_all_when_everything_filtered = true
|
19
|
+
config.include(Matchers)
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module Matchers
|
2
|
+
|
3
|
+
class GenerallyEqual
|
4
|
+
|
5
|
+
EPSILON = 0.0001
|
6
|
+
|
7
|
+
def initialize(expected)
|
8
|
+
@expected = expected
|
9
|
+
end
|
10
|
+
|
11
|
+
def json?(s)
|
12
|
+
begin
|
13
|
+
JSON.parse(s)
|
14
|
+
true
|
15
|
+
rescue
|
16
|
+
false
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches?(actual)
|
21
|
+
@actual = actual
|
22
|
+
|
23
|
+
if @actual.kind_of?(Float) || @expected.kind_of?(Float)
|
24
|
+
(@expected - EPSILON .. @expected + EPSILON).include? @actual
|
25
|
+
elsif json?(@actual) && json?(@expected)
|
26
|
+
JSON.parse(@actual) == JSON.parse(@expected)
|
27
|
+
else
|
28
|
+
@expected == @actual
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def failure_message_for_should
|
33
|
+
"expected #{@actual.inspect} to be generally equal to #{@expected.inspect}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def failure_message_for_should_not
|
37
|
+
"expected #{@actual.inspect} not to be generally equal to #{@expected.inspect}"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def be_generally_equal(expected)
|
42
|
+
GenerallyEqual.new(expected)
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,276 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pulse-meter-client-backport
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Ilya Averyanov
|
14
|
+
- Sergey Averyanov
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2012-05-30 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
hash: 3
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
prerelease: false
|
32
|
+
type: :runtime
|
33
|
+
name: json
|
34
|
+
requirement: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
hash: 3
|
42
|
+
segments:
|
43
|
+
- 0
|
44
|
+
version: "0"
|
45
|
+
prerelease: false
|
46
|
+
type: :runtime
|
47
|
+
name: redis
|
48
|
+
requirement: *id002
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
prerelease: false
|
60
|
+
type: :development
|
61
|
+
name: foreman
|
62
|
+
requirement: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
prerelease: false
|
74
|
+
type: :development
|
75
|
+
name: mock_redis
|
76
|
+
requirement: *id004
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
hash: 3
|
84
|
+
segments:
|
85
|
+
- 0
|
86
|
+
version: "0"
|
87
|
+
prerelease: false
|
88
|
+
type: :development
|
89
|
+
name: rack-test
|
90
|
+
requirement: *id005
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
version_requirements: &id006 !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
98
|
+
segments:
|
99
|
+
- 0
|
100
|
+
version: "0"
|
101
|
+
prerelease: false
|
102
|
+
type: :development
|
103
|
+
name: rake
|
104
|
+
requirement: *id006
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
version_requirements: &id007 !ruby/object:Gem::Requirement
|
107
|
+
none: false
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
hash: 3
|
112
|
+
segments:
|
113
|
+
- 0
|
114
|
+
version: "0"
|
115
|
+
prerelease: false
|
116
|
+
type: :development
|
117
|
+
name: redcarpet
|
118
|
+
requirement: *id007
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
version_requirements: &id008 !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
hash: 3
|
126
|
+
segments:
|
127
|
+
- 0
|
128
|
+
version: "0"
|
129
|
+
prerelease: false
|
130
|
+
type: :development
|
131
|
+
name: rspec
|
132
|
+
requirement: *id008
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
version_requirements: &id009 !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
prerelease: false
|
144
|
+
type: :development
|
145
|
+
name: timecop
|
146
|
+
requirement: *id009
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
version_requirements: &id010 !ruby/object:Gem::Requirement
|
149
|
+
none: false
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
hash: 3
|
154
|
+
segments:
|
155
|
+
- 0
|
156
|
+
version: "0"
|
157
|
+
prerelease: false
|
158
|
+
type: :development
|
159
|
+
name: yard
|
160
|
+
requirement: *id010
|
161
|
+
description: Ruby 1.8 compatible PulseMeter client
|
162
|
+
email:
|
163
|
+
- av@fun-box.ru
|
164
|
+
- averyanov@gmail.com
|
165
|
+
executables:
|
166
|
+
- pulse
|
167
|
+
extensions: []
|
168
|
+
|
169
|
+
extra_rdoc_files: []
|
170
|
+
|
171
|
+
files:
|
172
|
+
- .gitignore
|
173
|
+
- .rbenv-version
|
174
|
+
- .rspec
|
175
|
+
- .rvmrc
|
176
|
+
- .travis.yml
|
177
|
+
- Gemfile
|
178
|
+
- LICENSE
|
179
|
+
- Procfile
|
180
|
+
- README.md
|
181
|
+
- Rakefile
|
182
|
+
- bin/pulse
|
183
|
+
- examples/readme_client_example.rb
|
184
|
+
- lib/pulse-meter.rb
|
185
|
+
- lib/pulse-meter/mixins/dumper.rb
|
186
|
+
- lib/pulse-meter/mixins/utils.rb
|
187
|
+
- lib/pulse-meter/sensor.rb
|
188
|
+
- lib/pulse-meter/sensor/base.rb
|
189
|
+
- lib/pulse-meter/sensor/counter.rb
|
190
|
+
- lib/pulse-meter/sensor/hashed_counter.rb
|
191
|
+
- lib/pulse-meter/sensor/indicator.rb
|
192
|
+
- lib/pulse-meter/sensor/timeline.rb
|
193
|
+
- lib/pulse-meter/sensor/timelined/average.rb
|
194
|
+
- lib/pulse-meter/sensor/timelined/counter.rb
|
195
|
+
- lib/pulse-meter/sensor/timelined/hashed_counter.rb
|
196
|
+
- lib/pulse-meter/sensor/timelined/max.rb
|
197
|
+
- lib/pulse-meter/sensor/timelined/median.rb
|
198
|
+
- lib/pulse-meter/sensor/timelined/min.rb
|
199
|
+
- lib/pulse-meter/sensor/timelined/percentile.rb
|
200
|
+
- lib/pulse-meter/version.rb
|
201
|
+
- pulse-meter-client-backport.gemspec
|
202
|
+
- spec/pulse_meter/mixins/dumper_spec.rb
|
203
|
+
- spec/pulse_meter/mixins/utils_spec.rb
|
204
|
+
- spec/pulse_meter/sensor/base_spec.rb
|
205
|
+
- spec/pulse_meter/sensor/counter_spec.rb
|
206
|
+
- spec/pulse_meter/sensor/hashed_counter_spec.rb
|
207
|
+
- spec/pulse_meter/sensor/indicator_spec.rb
|
208
|
+
- spec/pulse_meter/sensor/timeline_spec.rb
|
209
|
+
- spec/pulse_meter/sensor/timelined/average_spec.rb
|
210
|
+
- spec/pulse_meter/sensor/timelined/counter_spec.rb
|
211
|
+
- spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb
|
212
|
+
- spec/pulse_meter/sensor/timelined/max_spec.rb
|
213
|
+
- spec/pulse_meter/sensor/timelined/median_spec.rb
|
214
|
+
- spec/pulse_meter/sensor/timelined/min_spec.rb
|
215
|
+
- spec/pulse_meter/sensor/timelined/percentile_spec.rb
|
216
|
+
- spec/pulse_meter_spec.rb
|
217
|
+
- spec/shared_examples/timeline_sensor.rb
|
218
|
+
- spec/shared_examples/timelined_subclass.rb
|
219
|
+
- spec/spec_helper.rb
|
220
|
+
- spec/support/matchers.rb
|
221
|
+
homepage: ""
|
222
|
+
licenses: []
|
223
|
+
|
224
|
+
post_install_message:
|
225
|
+
rdoc_options: []
|
226
|
+
|
227
|
+
require_paths:
|
228
|
+
- lib
|
229
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
230
|
+
none: false
|
231
|
+
requirements:
|
232
|
+
- - ~>
|
233
|
+
- !ruby/object:Gem::Version
|
234
|
+
hash: 55
|
235
|
+
segments:
|
236
|
+
- 1
|
237
|
+
- 8
|
238
|
+
- 0
|
239
|
+
version: 1.8.0
|
240
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
241
|
+
none: false
|
242
|
+
requirements:
|
243
|
+
- - ">="
|
244
|
+
- !ruby/object:Gem::Version
|
245
|
+
hash: 3
|
246
|
+
segments:
|
247
|
+
- 0
|
248
|
+
version: "0"
|
249
|
+
requirements: []
|
250
|
+
|
251
|
+
rubyforge_project:
|
252
|
+
rubygems_version: 1.8.24
|
253
|
+
signing_key:
|
254
|
+
specification_version: 3
|
255
|
+
summary: Ruby 1.8 compatible PulseMeter client
|
256
|
+
test_files:
|
257
|
+
- spec/pulse_meter/mixins/dumper_spec.rb
|
258
|
+
- spec/pulse_meter/mixins/utils_spec.rb
|
259
|
+
- spec/pulse_meter/sensor/base_spec.rb
|
260
|
+
- spec/pulse_meter/sensor/counter_spec.rb
|
261
|
+
- spec/pulse_meter/sensor/hashed_counter_spec.rb
|
262
|
+
- spec/pulse_meter/sensor/indicator_spec.rb
|
263
|
+
- spec/pulse_meter/sensor/timeline_spec.rb
|
264
|
+
- spec/pulse_meter/sensor/timelined/average_spec.rb
|
265
|
+
- spec/pulse_meter/sensor/timelined/counter_spec.rb
|
266
|
+
- spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb
|
267
|
+
- spec/pulse_meter/sensor/timelined/max_spec.rb
|
268
|
+
- spec/pulse_meter/sensor/timelined/median_spec.rb
|
269
|
+
- spec/pulse_meter/sensor/timelined/min_spec.rb
|
270
|
+
- spec/pulse_meter/sensor/timelined/percentile_spec.rb
|
271
|
+
- spec/pulse_meter_spec.rb
|
272
|
+
- spec/shared_examples/timeline_sensor.rb
|
273
|
+
- spec/shared_examples/timelined_subclass.rb
|
274
|
+
- spec/spec_helper.rb
|
275
|
+
- spec/support/matchers.rb
|
276
|
+
has_rdoc:
|