pulse-meter 0.4.9 → 0.4.11
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -48
- data/lib/pulse-meter.rb +1 -68
- data/lib/pulse-meter/visualizer.rb +1 -40
- data/pulse-meter.gemspec +4 -26
- metadata +10 -558
- data/Procfile +0 -3
- data/bin/pulse +0 -6
- data/examples/basic.ru +0 -145
- data/examples/basic_sensor_data.rb +0 -96
- data/examples/udp_benchmark.rb +0 -29
- data/lib/cmd.rb +0 -171
- data/lib/pulse-meter/command_aggregator/async.rb +0 -83
- data/lib/pulse-meter/command_aggregator/sync.rb +0 -18
- data/lib/pulse-meter/command_aggregator/udp.rb +0 -48
- data/lib/pulse-meter/extensions/enumerable.rb +0 -24
- data/lib/pulse-meter/mixins/cmd.rb +0 -46
- data/lib/pulse-meter/mixins/dumper.rb +0 -87
- data/lib/pulse-meter/mixins/utils.rb +0 -155
- data/lib/pulse-meter/observer.rb +0 -120
- data/lib/pulse-meter/observer/extended.rb +0 -34
- data/lib/pulse-meter/sensor.rb +0 -61
- data/lib/pulse-meter/sensor/base.rb +0 -88
- data/lib/pulse-meter/sensor/configuration.rb +0 -106
- data/lib/pulse-meter/sensor/counter.rb +0 -39
- data/lib/pulse-meter/sensor/hashed_counter.rb +0 -36
- data/lib/pulse-meter/sensor/hashed_indicator.rb +0 -24
- data/lib/pulse-meter/sensor/indicator.rb +0 -35
- data/lib/pulse-meter/sensor/multi.rb +0 -97
- data/lib/pulse-meter/sensor/timeline.rb +0 -236
- data/lib/pulse-meter/sensor/timeline_reduce.rb +0 -68
- data/lib/pulse-meter/sensor/timelined/average.rb +0 -32
- data/lib/pulse-meter/sensor/timelined/counter.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +0 -31
- data/lib/pulse-meter/sensor/timelined/hashed_indicator.rb +0 -30
- data/lib/pulse-meter/sensor/timelined/indicator.rb +0 -23
- data/lib/pulse-meter/sensor/timelined/max.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/median.rb +0 -14
- data/lib/pulse-meter/sensor/timelined/min.rb +0 -19
- data/lib/pulse-meter/sensor/timelined/multi_percentile.rb +0 -34
- data/lib/pulse-meter/sensor/timelined/percentile.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/uniq_counter.rb +0 -22
- data/lib/pulse-meter/sensor/timelined/zset_based.rb +0 -38
- data/lib/pulse-meter/sensor/uniq_counter.rb +0 -24
- data/lib/pulse-meter/server.rb +0 -0
- data/lib/pulse-meter/server/command_line_options.rb +0 -0
- data/lib/pulse-meter/server/config_options.rb +0 -0
- data/lib/pulse-meter/server/sensors.rb +0 -0
- data/lib/pulse-meter/udp_server.rb +0 -45
- data/lib/pulse-meter/version.rb +0 -3
- data/lib/pulse-meter/visualize/app.rb +0 -78
- data/lib/pulse-meter/visualize/base.rb +0 -15
- data/lib/pulse-meter/visualize/coffee/application.coffee +0 -40
- data/lib/pulse-meter/visualize/coffee/collections/page_info_list.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/collections/sensor_info_list.coffee +0 -4
- data/lib/pulse-meter/visualize/coffee/collections/widget_list.coffee +0 -14
- data/lib/pulse-meter/visualize/coffee/extensions.coffee +0 -26
- data/lib/pulse-meter/visualize/coffee/models/dinamic_widget.coffee +0 -34
- data/lib/pulse-meter/visualize/coffee/models/page_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/sensor_info.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/models/widget.coffee +0 -54
- data/lib/pulse-meter/visualize/coffee/presenters/area.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/gauge.coffee +0 -11
- data/lib/pulse-meter/visualize/coffee/presenters/line.coffee +0 -2
- data/lib/pulse-meter/visualize/coffee/presenters/pie.coffee +0 -20
- data/lib/pulse-meter/visualize/coffee/presenters/series.coffee +0 -44
- data/lib/pulse-meter/visualize/coffee/presenters/table.coffee +0 -10
- data/lib/pulse-meter/visualize/coffee/presenters/timeline.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/presenters/widget.coffee +0 -65
- data/lib/pulse-meter/visualize/coffee/router.coffee +0 -21
- data/lib/pulse-meter/visualize/coffee/views/dynamic_chart.coffee +0 -91
- data/lib/pulse-meter/visualize/coffee/views/dynamic_widget.coffee +0 -58
- data/lib/pulse-meter/visualize/coffee/views/page_title.coffee +0 -17
- data/lib/pulse-meter/visualize/coffee/views/page_titles.coffee +0 -15
- data/lib/pulse-meter/visualize/coffee/views/sensor_info_list.coffee +0 -19
- data/lib/pulse-meter/visualize/coffee/views/widget.coffee +0 -99
- data/lib/pulse-meter/visualize/coffee/views/widget_chart.coffee +0 -13
- data/lib/pulse-meter/visualize/coffee/views/widget_list.coffee +0 -15
- data/lib/pulse-meter/visualize/dsl/base.rb +0 -131
- data/lib/pulse-meter/visualize/dsl/errors.rb +0 -40
- data/lib/pulse-meter/visualize/dsl/layout.rb +0 -27
- data/lib/pulse-meter/visualize/dsl/page.rb +0 -33
- data/lib/pulse-meter/visualize/dsl/sensor.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widget.rb +0 -37
- data/lib/pulse-meter/visualize/dsl/widgets/area.rb +0 -20
- data/lib/pulse-meter/visualize/dsl/widgets/gauge.rb +0 -12
- data/lib/pulse-meter/visualize/dsl/widgets/line.rb +0 -21
- data/lib/pulse-meter/visualize/dsl/widgets/pie.rb +0 -16
- data/lib/pulse-meter/visualize/dsl/widgets/table.rb +0 -19
- data/lib/pulse-meter/visualize/layout.rb +0 -79
- data/lib/pulse-meter/visualize/page.rb +0 -25
- data/lib/pulse-meter/visualize/public/css/application.css +0 -56
- data/lib/pulse-meter/visualize/public/css/bootstrap.css +0 -4883
- data/lib/pulse-meter/visualize/public/css/bootstrap.min.css +0 -729
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
- data/lib/pulse-meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +0 -1320
- data/lib/pulse-meter/visualize/public/favicon.ico +0 -208
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
- data/lib/pulse-meter/visualize/public/img/glyphicons-halflings.png +0 -0
- data/lib/pulse-meter/visualize/public/js/application.js +0 -973
- data/lib/pulse-meter/visualize/public/js/backbone-min.js +0 -38
- data/lib/pulse-meter/visualize/public/js/bootstrap.js +0 -1835
- data/lib/pulse-meter/visualize/public/js/jquery-1.7.2.min.js +0 -4
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +0 -791
- data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +0 -21
- data/lib/pulse-meter/visualize/public/js/jquery-ui-timepicker-addon.js +0 -1687
- data/lib/pulse-meter/visualize/public/js/json2.js +0 -487
- data/lib/pulse-meter/visualize/public/js/underscore-min.js +0 -32
- data/lib/pulse-meter/visualize/sensor.rb +0 -63
- data/lib/pulse-meter/visualize/series_extractor.rb +0 -107
- data/lib/pulse-meter/visualize/views/main.haml +0 -30
- data/lib/pulse-meter/visualize/views/sensors.haml +0 -76
- data/lib/pulse-meter/visualize/views/widgets/area.haml +0 -53
- data/lib/pulse-meter/visualize/views/widgets/extend_options.haml +0 -11
- data/lib/pulse-meter/visualize/views/widgets/gauge.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/line.haml +0 -54
- data/lib/pulse-meter/visualize/views/widgets/pie.haml +0 -13
- data/lib/pulse-meter/visualize/views/widgets/table.haml +0 -45
- data/lib/pulse-meter/visualize/widget.rb +0 -38
- data/lib/pulse-meter/visualize/widgets/gauge.rb +0 -47
- data/lib/pulse-meter/visualize/widgets/pie.rb +0 -36
- data/lib/pulse-meter/visualize/widgets/timeline.rb +0 -114
- data/spec/pulse_meter/command_aggregator/async_spec.rb +0 -53
- data/spec/pulse_meter/command_aggregator/sync_spec.rb +0 -25
- data/spec/pulse_meter/command_aggregator/udp_spec.rb +0 -45
- data/spec/pulse_meter/extensions/enumerable_spec.rb +0 -58
- data/spec/pulse_meter/mixins/cmd_spec.rb +0 -117
- data/spec/pulse_meter/mixins/dumper_spec.rb +0 -162
- data/spec/pulse_meter/mixins/utils_spec.rb +0 -212
- data/spec/pulse_meter/observer/extended_spec.rb +0 -92
- data/spec/pulse_meter/observer_spec.rb +0 -207
- data/spec/pulse_meter/sensor/base_spec.rb +0 -106
- data/spec/pulse_meter/sensor/configuration_spec.rb +0 -103
- data/spec/pulse_meter/sensor/counter_spec.rb +0 -54
- data/spec/pulse_meter/sensor/hashed_counter_spec.rb +0 -43
- data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +0 -39
- data/spec/pulse_meter/sensor/indicator_spec.rb +0 -43
- data/spec/pulse_meter/sensor/multi_spec.rb +0 -137
- data/spec/pulse_meter/sensor/timeline_spec.rb +0 -88
- data/spec/pulse_meter/sensor/timelined/average_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/counter_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/hashed_indicator_spec.rb +0 -8
- data/spec/pulse_meter/sensor/timelined/indicator_spec.rb +0 -6
- data/spec/pulse_meter/sensor/timelined/max_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/median_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/min_spec.rb +0 -7
- data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +0 -21
- data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +0 -17
- data/spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb +0 -9
- data/spec/pulse_meter/sensor/uniq_counter_spec.rb +0 -28
- data/spec/pulse_meter/udp_server_spec.rb +0 -36
- data/spec/pulse_meter/visualize/app_spec.rb +0 -27
- data/spec/pulse_meter/visualize/dsl/layout_spec.rb +0 -64
- data/spec/pulse_meter/visualize/dsl/page_spec.rb +0 -62
- data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +0 -30
- data/spec/pulse_meter/visualize/dsl/widget_spec.rb +0 -6
- data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +0 -22
- data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +0 -44
- data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +0 -35
- data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +0 -36
- data/spec/pulse_meter/visualize/layout_spec.rb +0 -54
- data/spec/pulse_meter/visualize/page_spec.rb +0 -153
- data/spec/pulse_meter/visualize/sensor_spec.rb +0 -120
- data/spec/pulse_meter/visualize/series_extractor_spec.rb +0 -80
- data/spec/pulse_meter/visualize/widgets/area_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +0 -63
- data/spec/pulse_meter/visualize/widgets/line_spec.rb +0 -6
- data/spec/pulse_meter/visualize/widgets/pie_spec.rb +0 -73
- data/spec/pulse_meter/visualize/widgets/table_spec.rb +0 -6
- data/spec/pulse_meter/visualizer_spec.rb +0 -42
- data/spec/pulse_meter_spec.rb +0 -73
- data/spec/shared_examples/dsl_widget.rb +0 -106
- data/spec/shared_examples/timeline_sensor.rb +0 -439
- data/spec/shared_examples/timelined_subclass.rb +0 -23
- data/spec/shared_examples/widget.rb +0 -97
- data/spec/spec_helper.rb +0 -40
- data/spec/support/matchers.rb +0 -34
- data/spec/support/observered.rb +0 -40
@@ -1,63 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe PulseMeter::Visualize::Widgets::Gauge do
|
4
|
-
let(:interval){ 100 }
|
5
|
-
let!(:a_sensor){PulseMeter::Sensor::Indicator.new(:a_sensor, annotation: 'A')}
|
6
|
-
let!(:b_sensor){PulseMeter::Sensor::Indicator.new(:b_sensor, annotation: 'B')}
|
7
|
-
let!(:c_sensor){PulseMeter::Sensor::HashedIndicator.new(:c_sensor, annotation: 'C')}
|
8
|
-
|
9
|
-
|
10
|
-
let(:widget_name){ "some_widget" }
|
11
|
-
|
12
|
-
let(:redraw_interval){5}
|
13
|
-
let(:width){6}
|
14
|
-
|
15
|
-
let(:interval_start){ Time.at((Time.now.to_i / interval) * interval) }
|
16
|
-
|
17
|
-
let(:widget) do
|
18
|
-
w = PulseMeter::Visualize::DSL::Widgets::Gauge.new(widget_name)
|
19
|
-
w.redraw_interval redraw_interval
|
20
|
-
w.width width
|
21
|
-
w.sensor :a_sensor
|
22
|
-
w.sensor :b_sensor
|
23
|
-
w.sensor :c_sensor
|
24
|
-
w.gchart_options a: 1
|
25
|
-
w.to_data
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#data" do
|
29
|
-
it "should contain type, title, redraw_interval, width, gchart_options attriutes" do
|
30
|
-
wdata = widget.data
|
31
|
-
wdata[:type].should == 'gauge'
|
32
|
-
wdata[:title].should == widget_name
|
33
|
-
wdata[:redraw_interval].should == redraw_interval
|
34
|
-
wdata[:width].should == width
|
35
|
-
wdata[:gchart_options].should == {a: 1}
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "series attribute" do
|
39
|
-
before(:each) do
|
40
|
-
a_sensor.event(12)
|
41
|
-
b_sensor.event(33)
|
42
|
-
c_sensor.event(:a => 44)
|
43
|
-
c_sensor.event(:b => 55)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should contain valid gauge slices" do
|
47
|
-
|
48
|
-
widget.data[:series].sort.should == [
|
49
|
-
['A', 12],
|
50
|
-
['B', 33],
|
51
|
-
["C: a", 44],
|
52
|
-
["C: b", 55]
|
53
|
-
].sort
|
54
|
-
|
55
|
-
end
|
56
|
-
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe PulseMeter::Visualize::Widgets::Pie do
|
4
|
-
let(:interval){ 100 }
|
5
|
-
let!(:a_sensor){ PulseMeter::Sensor::Timelined::Counter.new(:a_sensor, :ttl => 1000, :interval => interval, annotation: 'A') }
|
6
|
-
let!(:b_sensor){ PulseMeter::Sensor::Timelined::Counter.new(:b_sensor, :ttl => 1000, :interval => interval, annotation: 'B') }
|
7
|
-
|
8
|
-
let(:widget_name){ "some_widget" }
|
9
|
-
|
10
|
-
let(:redraw_interval){5}
|
11
|
-
let(:values_label){'xxxx'}
|
12
|
-
let(:width){6}
|
13
|
-
let(:a_color){'#FF0000'}
|
14
|
-
let(:b_color){'#FFFF00'}
|
15
|
-
|
16
|
-
let(:interval_start){ Time.at((Time.now.to_i / interval) * interval) }
|
17
|
-
|
18
|
-
let(:widget) do
|
19
|
-
w = PulseMeter::Visualize::DSL::Widgets::Pie.new(widget_name)
|
20
|
-
w.redraw_interval redraw_interval
|
21
|
-
w.width width
|
22
|
-
w.sensor :a_sensor, color: a_color
|
23
|
-
w.sensor :b_sensor, color: b_color
|
24
|
-
w.gchart_options a: 1
|
25
|
-
w.to_data
|
26
|
-
end
|
27
|
-
|
28
|
-
describe "#data" do
|
29
|
-
it "should contain type, title, redraw_interval, width, gchart_options attriutes" do
|
30
|
-
wdata = widget.data
|
31
|
-
wdata[:type].should == 'pie'
|
32
|
-
wdata[:title].should == widget_name
|
33
|
-
wdata[:redraw_interval].should == redraw_interval
|
34
|
-
wdata[:width].should == width
|
35
|
-
wdata[:gchart_options].should == {a: 1}
|
36
|
-
end
|
37
|
-
|
38
|
-
describe "series attribute" do
|
39
|
-
before(:each) do
|
40
|
-
Timecop.freeze(interval_start + 1) do
|
41
|
-
a_sensor.event(12)
|
42
|
-
b_sensor.event(33)
|
43
|
-
end
|
44
|
-
Timecop.freeze(interval_start + interval + 1) do
|
45
|
-
a_sensor.event(111)
|
46
|
-
end
|
47
|
-
@current_time = interval_start + 2 * interval - 1
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should contain valid pie slices" do
|
51
|
-
|
52
|
-
Timecop.freeze(@current_time) do
|
53
|
-
widget.data[:series].should ==
|
54
|
-
{
|
55
|
-
data: [
|
56
|
-
[a_sensor.annotation, 12],
|
57
|
-
[b_sensor.annotation, 33]
|
58
|
-
],
|
59
|
-
options: [
|
60
|
-
{color: a_color},
|
61
|
-
{color: b_color}
|
62
|
-
]
|
63
|
-
}
|
64
|
-
end
|
65
|
-
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
|
73
|
-
|
@@ -1,42 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter::Visualizer do
|
4
|
-
describe "::draw" do
|
5
|
-
it "should generate correct layout with passed block" do
|
6
|
-
layout = described_class.draw do |l|
|
7
|
-
|
8
|
-
l.title "My Gauges"
|
9
|
-
|
10
|
-
l.page "Dashboard" do |p|
|
11
|
-
p.line :convertion do |c|
|
12
|
-
c.sensor :adv_clicks, color: :green
|
13
|
-
c.sensor :adv_shows, color: :red
|
14
|
-
end
|
15
|
-
|
16
|
-
p.pie :agents, title: 'User Agents' do |c|
|
17
|
-
c.sensor :agent_ie
|
18
|
-
c.sensor :agent_chrome
|
19
|
-
c.sensor :agent_ff
|
20
|
-
c.sensor :agent_other
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
24
|
-
|
25
|
-
l.page "Request stats" do |p|
|
26
|
-
p.line :rph_total, sensor: :rph_total
|
27
|
-
p.line :rph_main_page, sensor: :rph_main_page
|
28
|
-
p.line :request_time_p95_hour
|
29
|
-
|
30
|
-
p.pie :success_vs_fail_total_hourly do |w|
|
31
|
-
w.sensor :success_total_hourly
|
32
|
-
w.sensor :fail_total_hourly
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
layout.should be_kind_of(PulseMeter::Visualize::Layout)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
data/spec/pulse_meter_spec.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe PulseMeter do
|
4
|
-
describe "::redis=" do
|
5
|
-
it "should store redis" do
|
6
|
-
PulseMeter.redis = 'redis'
|
7
|
-
PulseMeter.redis.should == 'redis'
|
8
|
-
end
|
9
|
-
end
|
10
|
-
describe "::redis" do
|
11
|
-
it "should retrieve redis" do
|
12
|
-
PulseMeter.redis = 'redis'
|
13
|
-
PulseMeter.redis.should == 'redis'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
describe "::command_aggregator=" do
|
17
|
-
context "when :async passed" do
|
18
|
-
it "should set async command_aggregator to be used" do
|
19
|
-
PulseMeter.command_aggregator = :async
|
20
|
-
PulseMeter.command_aggregator.should be_kind_of(PulseMeter::CommandAggregator::Async)
|
21
|
-
end
|
22
|
-
end
|
23
|
-
context "when :sync passed" do
|
24
|
-
it "should set sync command_aggregator to be used" do
|
25
|
-
PulseMeter.command_aggregator = :sync
|
26
|
-
PulseMeter.command_aggregator.should be_kind_of(PulseMeter::CommandAggregator::Sync)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
context "otherwise" do
|
30
|
-
it "should set command_aggregator to the passed value" do
|
31
|
-
PulseMeter.command_aggregator = :xxx
|
32
|
-
PulseMeter.command_aggregator.should == :xxx
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
describe "::command_aggregator" do
|
38
|
-
it "should return current command_aggregator" do
|
39
|
-
PulseMeter.command_aggregator = :async
|
40
|
-
PulseMeter.command_aggregator.should be_kind_of(PulseMeter::CommandAggregator::Async)
|
41
|
-
PulseMeter.command_aggregator = :sync
|
42
|
-
PulseMeter.command_aggregator.should be_kind_of(PulseMeter::CommandAggregator::Sync)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should always return the same command_aggregator for each type" do
|
46
|
-
PulseMeter.command_aggregator = :async
|
47
|
-
ca1 = PulseMeter.command_aggregator
|
48
|
-
PulseMeter.command_aggregator = :sync
|
49
|
-
PulseMeter.command_aggregator = :async
|
50
|
-
ca2 = PulseMeter.command_aggregator
|
51
|
-
ca1.should == ca2
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe "::logger" do
|
56
|
-
it "should return PulseMeter logger" do
|
57
|
-
PulseMeter.logger = 123
|
58
|
-
PulseMeter.logger.should == 123
|
59
|
-
end
|
60
|
-
|
61
|
-
it "should return default logger" do
|
62
|
-
PulseMeter.logger = nil
|
63
|
-
PulseMeter.logger.should be_kind_of(Logger)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
describe "::error" do
|
68
|
-
it "should delegate error message to logger" do
|
69
|
-
PulseMeter.logger.should_receive(:error)
|
70
|
-
PulseMeter.error("foo")
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
@@ -1,106 +0,0 @@
|
|
1
|
-
shared_examples_for "dsl widget" do
|
2
|
-
|
3
|
-
let(:interval){ 100 }
|
4
|
-
let(:name) { "some_sensor" }
|
5
|
-
let!(:sensor){ PulseMeter::Sensor::Timelined::Max.new(name, :ttl => 1000, :interval => interval) }
|
6
|
-
|
7
|
-
let(:widget_name){ "some_widget" }
|
8
|
-
let(:w){ described_class.new(widget_name) }
|
9
|
-
|
10
|
-
describe '.new' do
|
11
|
-
it "should set default value for width papram" do
|
12
|
-
wid = w.to_data
|
13
|
-
wid.width.should == PulseMeter::Visualize::DSL::Widget::MAX_WIDTH
|
14
|
-
end
|
15
|
-
|
16
|
-
it "should set title param from .new argument" do
|
17
|
-
wid = w.to_data
|
18
|
-
wid.title.should == widget_name
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
describe "#process_args" do
|
23
|
-
it "should set sensor by :sensor param" do
|
24
|
-
w.process_args :sensor => :sss
|
25
|
-
sensors = w.to_data.sensors
|
26
|
-
sensors.size.should == 1
|
27
|
-
sensors.first.name.to_s.should == 'sss'
|
28
|
-
end
|
29
|
-
|
30
|
-
it "should set title by :title param" do
|
31
|
-
w.process_args :title => 'Title XXX'
|
32
|
-
w.to_data.title.should == 'Title XXX'
|
33
|
-
end
|
34
|
-
|
35
|
-
it "should set width by :width param" do
|
36
|
-
w.process_args :width => 5
|
37
|
-
w.to_data.width.should == 5
|
38
|
-
end
|
39
|
-
|
40
|
-
end
|
41
|
-
|
42
|
-
describe "#sensor" do
|
43
|
-
it "should add sensor" do
|
44
|
-
w.sensor :s1
|
45
|
-
w.sensor :s2
|
46
|
-
sensors = w.to_data.sensors
|
47
|
-
sensors.size.should == 2
|
48
|
-
sensors.first.name.to_s.should == 's1'
|
49
|
-
sensors.last.name.to_s.should == 's2'
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
describe "#title" do
|
54
|
-
it "should set title" do
|
55
|
-
w.title 'Title XXX'
|
56
|
-
w.to_data.title.should == 'Title XXX'
|
57
|
-
w.title 'Title YYY'
|
58
|
-
w.to_data.title.should == 'Title YYY'
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
describe "#width" do
|
63
|
-
it "should set width" do
|
64
|
-
w.width 6
|
65
|
-
w.to_data.width.should == 6
|
66
|
-
end
|
67
|
-
|
68
|
-
it "should raise exception if width is invalid" do
|
69
|
-
expect { w.width -1 }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetWidth)
|
70
|
-
expect { w.width 11 }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetWidth)
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe "#redraw_interval" do
|
75
|
-
it "should set redraw_interval" do
|
76
|
-
w.redraw_interval 5
|
77
|
-
w.to_data.redraw_interval.should == 5
|
78
|
-
end
|
79
|
-
it "should raise exception if redraw_interval is negative" do
|
80
|
-
expect{ w.redraw_interval(-1) }.to raise_exception(PulseMeter::Visualize::DSL::BadWidgetRedrawInterval)
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
|
85
|
-
describe "#to_data" do
|
86
|
-
it "should convert dsl data to widget" do
|
87
|
-
w.to_data.should be_kind_of(PulseMeter::Visualize::Widget)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
describe "#gchart_options" do
|
92
|
-
it "should add options to gchart_options hash" do
|
93
|
-
w.gchart_options a: 1
|
94
|
-
w.gchart_options b: 2
|
95
|
-
w.to_data.gchart_options.should == {a: 1, b: 2}
|
96
|
-
end
|
97
|
-
end
|
98
|
-
|
99
|
-
describe "any anknown method" do
|
100
|
-
it "should add options to gchart_options hash" do
|
101
|
-
w.foobar 123
|
102
|
-
w.to_data.gchart_options.should == {foobar: 123}
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
@@ -1,439 +0,0 @@
|
|
1
|
-
shared_examples_for "timeline sensor" do |extra_init_values, default_event|
|
2
|
-
class Dummy
|
3
|
-
include PulseMeter::Mixins::Dumper
|
4
|
-
def name; :dummy end
|
5
|
-
def redis; PulseMeter.redis; end
|
6
|
-
end
|
7
|
-
|
8
|
-
let(:name){ :some_value_with_history }
|
9
|
-
let(:ttl){ 10000 }
|
10
|
-
let(:raw_data_ttl){ 3000 }
|
11
|
-
let(:interval){ 5 }
|
12
|
-
let(:reduce_delay){ 3 }
|
13
|
-
let(:good_init_values){ {:ttl => ttl, :raw_data_ttl => raw_data_ttl, :interval => interval, :reduce_delay => reduce_delay}.merge(extra_init_values || {}) }
|
14
|
-
let!(:sensor){ described_class.new(name, good_init_values) }
|
15
|
-
let(:dummy) {Dummy.new}
|
16
|
-
let(:base_class){ PulseMeter::Sensor::Base }
|
17
|
-
let(:redis){ PulseMeter.redis }
|
18
|
-
let(:sample_event) {default_event || 123}
|
19
|
-
|
20
|
-
before(:each) do
|
21
|
-
@interval_id = (Time.now.to_i / interval) * interval
|
22
|
-
@prev_interval_id = (Time.now.to_i / interval) * interval - interval
|
23
|
-
|
24
|
-
@raw_data_key = sensor.raw_data_key(@interval_id)
|
25
|
-
@prev_raw_data_key = sensor.raw_data_key(@prev_interval_id)
|
26
|
-
|
27
|
-
@next_raw_data_key = sensor.raw_data_key(@interval_id + interval)
|
28
|
-
|
29
|
-
@start_of_interval = Time.at(@interval_id)
|
30
|
-
@start_of_prev_interval = Time.at(@prev_interval_id)
|
31
|
-
end
|
32
|
-
|
33
|
-
describe "#dump" do
|
34
|
-
it "should be dumped succesfully" do
|
35
|
-
expect {sensor.dump!}.not_to raise_exception
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe ".restore" do
|
40
|
-
before do
|
41
|
-
# no need to call sensor.dump! explicitly for it
|
42
|
-
# will be called automatically after creation
|
43
|
-
@restored = base_class.restore(sensor.name)
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should restore #{described_class} instance" do
|
47
|
-
@restored.should be_instance_of(described_class)
|
48
|
-
end
|
49
|
-
|
50
|
-
it "should restore object with the same data" do
|
51
|
-
def inner_data(obj)
|
52
|
-
obj.instance_variables.sort.map {|v| obj.instance_variable_get(v)}
|
53
|
-
end
|
54
|
-
|
55
|
-
inner_data(sensor).should == inner_data(@restored)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
describe "#event" do
|
60
|
-
it "should write events to redis" do
|
61
|
-
expect{
|
62
|
-
sensor.event(sample_event)
|
63
|
-
}.to change{ redis.keys('*').count }.by(1)
|
64
|
-
end
|
65
|
-
|
66
|
-
it "should write data so that it totally expires after :raw_data_ttl" do
|
67
|
-
key_count = redis.keys('*').count
|
68
|
-
sensor.event(sample_event)
|
69
|
-
Timecop.freeze(Time.now + raw_data_ttl + 1) do
|
70
|
-
redis.keys('*').count.should == key_count
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
it "should write data to bucket indicated by truncated timestamp" do
|
75
|
-
expect{
|
76
|
-
Timecop.freeze(@start_of_interval) do
|
77
|
-
sensor.event(sample_event)
|
78
|
-
end
|
79
|
-
}.to change{ redis.ttl(@raw_data_key) }
|
80
|
-
end
|
81
|
-
|
82
|
-
it "returns true if event processed correctly" do
|
83
|
-
sensor.event(sample_event).should be_true
|
84
|
-
end
|
85
|
-
|
86
|
-
it "catches StandardErrors and returns false" do
|
87
|
-
sensor.stub(:aggregate_event) {raise StandardError}
|
88
|
-
sensor.event(sample_event).should be_false
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
describe "#event_at" do
|
93
|
-
let(:now) {Time.now}
|
94
|
-
it "should write events to redis" do
|
95
|
-
expect{
|
96
|
-
sensor.event_at(now, sample_event)
|
97
|
-
}.to change{ redis.keys('*').count }.by(1)
|
98
|
-
end
|
99
|
-
|
100
|
-
it "should write data so that it totally expires after :raw_data_ttl" do
|
101
|
-
key_count = redis.keys('*').count
|
102
|
-
sensor.event_at(now, sample_event)
|
103
|
-
Timecop.freeze(now + raw_data_ttl + 1) do
|
104
|
-
redis.keys('*').count.should == key_count
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
it "should write data to bucket indicated by passed time" do
|
109
|
-
expect{
|
110
|
-
Timecop.freeze(@start_of_interval) do
|
111
|
-
sensor.event_at(@start_of_prev_interval, sample_event)
|
112
|
-
end
|
113
|
-
}.to change{ redis.ttl(@prev_raw_data_key) }
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
describe "#summarize" do
|
118
|
-
it "should convert data stored by raw_data_key to a value defined only by stored data" do
|
119
|
-
Timecop.freeze(@start_of_interval) do
|
120
|
-
sensor.event(sample_event)
|
121
|
-
end
|
122
|
-
Timecop.freeze(@start_of_interval + interval) do
|
123
|
-
sensor.event(sample_event)
|
124
|
-
end
|
125
|
-
sensor.summarize(@raw_data_key).should == sensor.summarize(@next_raw_data_key)
|
126
|
-
sensor.summarize(@raw_data_key).should_not be_nil
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
describe "#reduce" do
|
131
|
-
it "should store summarized value into data_key" do
|
132
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
133
|
-
val = sensor.summarize(@raw_data_key)
|
134
|
-
val.should_not be_nil
|
135
|
-
sensor.reduce(@interval_id)
|
136
|
-
redis.get(sensor.data_key(@interval_id)).should == val.to_s
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should remove original raw_data_key" do
|
140
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
141
|
-
expect{
|
142
|
-
sensor.reduce(@interval_id)
|
143
|
-
}.to change{ redis.keys(sensor.raw_data_key(@interval_id)).count }.from(1).to(0)
|
144
|
-
end
|
145
|
-
|
146
|
-
it "should expire stored summarized data" do
|
147
|
-
Timecop.freeze(@start_of_interval) do
|
148
|
-
sensor.event(sample_event)
|
149
|
-
sensor.reduce(@interval_id)
|
150
|
-
redis.keys(sensor.data_key(@interval_id)).count.should == 1
|
151
|
-
end
|
152
|
-
Timecop.freeze(@start_of_interval + ttl + 1) do
|
153
|
-
redis.keys(sensor.data_key(@interval_id)).count.should == 0
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
it "should not store data if there is no corresponding raw data" do
|
158
|
-
Timecop.freeze(@start_of_interval) do
|
159
|
-
sensor.reduce(@interval_id)
|
160
|
-
redis.keys(sensor.data_key(@interval_id)).count.should == 0
|
161
|
-
end
|
162
|
-
end
|
163
|
-
|
164
|
-
it "should not store summarized data if it already exists" do
|
165
|
-
data_key = sensor.data_key(@interval_id)
|
166
|
-
redis.set(data_key, :dummy)
|
167
|
-
Timecop.freeze(@start_of_interval) do
|
168
|
-
sensor.event(sample_event)
|
169
|
-
sensor.reduce(@interval_id)
|
170
|
-
redis.get(data_key).should == "dummy"
|
171
|
-
end
|
172
|
-
end
|
173
|
-
end
|
174
|
-
|
175
|
-
describe "#reduce_all_raw" do
|
176
|
-
it "should reduce all data older than reduce_delay" do
|
177
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
178
|
-
val0 = sensor.summarize(@raw_data_key)
|
179
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
180
|
-
val1 = sensor.summarize(@next_raw_data_key)
|
181
|
-
expect{
|
182
|
-
Timecop.freeze(@start_of_interval + interval + interval + reduce_delay + 1) do
|
183
|
-
sensor.reduce_all_raw
|
184
|
-
end
|
185
|
-
}.to change{ redis.keys(sensor.raw_data_key('*')).count }.from(2).to(0)
|
186
|
-
|
187
|
-
redis.get(sensor.data_key(@interval_id)).should == val0.to_s
|
188
|
-
redis.get(sensor.data_key(@interval_id + interval)).should == val1.to_s
|
189
|
-
end
|
190
|
-
|
191
|
-
it "creates up to MAX_INTERVALS compresed data pieces from previously uncompressed data" do
|
192
|
-
max_count = described_class::MAX_INTERVALS
|
193
|
-
start = @start_of_interval - reduce_delay - max_count * interval
|
194
|
-
(max_count + 100).times do |i|
|
195
|
-
Timecop.freeze(start + i * interval) {sensor.event(sample_event)}
|
196
|
-
end
|
197
|
-
|
198
|
-
Timecop.freeze(@start_of_interval) do
|
199
|
-
expect {
|
200
|
-
sensor.reduce_all_raw
|
201
|
-
}.to change {redis.keys(sensor.data_key('*')).count}.from(0).to(max_count)
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
it "should not reduce fresh data" do
|
206
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
207
|
-
|
208
|
-
expect{
|
209
|
-
Timecop.freeze(@start_of_interval + interval + reduce_delay - 1) { sensor.reduce_all_raw }
|
210
|
-
}.not_to change{ redis.keys(sensor.raw_data_key('*')).count }
|
211
|
-
|
212
|
-
expect{
|
213
|
-
Timecop.freeze(@start_of_interval + interval + reduce_delay - 1) { sensor.reduce_all_raw }
|
214
|
-
}.not_to change{ redis.keys(sensor.data_key('*')).count }
|
215
|
-
end
|
216
|
-
end
|
217
|
-
|
218
|
-
describe ".reduce_all_raw" do
|
219
|
-
it "should silently skip objects without reduce logic" do
|
220
|
-
dummy.dump!
|
221
|
-
expect {described_class.reduce_all_raw}.not_to raise_exception
|
222
|
-
end
|
223
|
-
|
224
|
-
it "should send reduce_all_raw to all dumped objects" do
|
225
|
-
described_class.any_instance.should_receive(:reduce_all_raw)
|
226
|
-
described_class.reduce_all_raw
|
227
|
-
end
|
228
|
-
end
|
229
|
-
|
230
|
-
describe "#timeline_within" do
|
231
|
-
it "should raise exception unless both arguments are Time objects" do
|
232
|
-
[:q, nil, -1].each do |bad_value|
|
233
|
-
expect{ sensor.timeline_within(Time.now, bad_value) }.to raise_exception(ArgumentError)
|
234
|
-
expect{ sensor.timeline_within(bad_value, Time.now) }.to raise_exception(ArgumentError)
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
it "should return an array of SensorData objects corresponding to stored data for passed interval" do
|
239
|
-
sensor.event(sample_event)
|
240
|
-
now = Time.now
|
241
|
-
timeline = sensor.timeline_within(now - 1, now)
|
242
|
-
timeline.should be_kind_of(Array)
|
243
|
-
timeline.each{|i| i.should be_kind_of(SensorData) }
|
244
|
-
end
|
245
|
-
|
246
|
-
it "should return array of results containing as many results as there are sensor interval beginnings in the passed interval" do
|
247
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
248
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
249
|
-
|
250
|
-
future = @start_of_interval + 3600
|
251
|
-
Timecop.freeze(future) do
|
252
|
-
sensor.timeline_within(
|
253
|
-
Time.at(@start_of_interval + interval - 1),
|
254
|
-
Time.at(@start_of_interval + interval + 1)
|
255
|
-
).size.should == 1
|
256
|
-
|
257
|
-
sensor.timeline_within(
|
258
|
-
Time.at(@start_of_interval - 1),
|
259
|
-
Time.at(@start_of_interval + interval + 1)
|
260
|
-
).size.should == 2
|
261
|
-
end
|
262
|
-
|
263
|
-
Timecop.freeze(@start_of_interval + interval + 2) do
|
264
|
-
sensor.timeline_within(
|
265
|
-
Time.at(@start_of_interval + interval + 1),
|
266
|
-
Time.at(@start_of_interval + interval + 2)
|
267
|
-
).size.should == 0
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
context "to avoid getting to much data" do
|
272
|
-
let(:max) {PulseMeter::Sensor::Timeline::MAX_TIMESPAN_POINTS}
|
273
|
-
|
274
|
-
it "should skip some points not to exceed MAX_TIMESPAN_POINTS" do
|
275
|
-
count = max * 2
|
276
|
-
sensor.timeline_within(
|
277
|
-
Time.at(@start_of_interval - 1),
|
278
|
-
Time.at(@start_of_interval + count * interval)
|
279
|
-
).size.should < max
|
280
|
-
end
|
281
|
-
|
282
|
-
it "should not skip any points when timeline orginal size is less then MAX_TIMESPAN_POINTS" do
|
283
|
-
count = max - 1
|
284
|
-
sensor.timeline_within(
|
285
|
-
Time.at(@start_of_interval - 1),
|
286
|
-
Time.at(@start_of_interval + count * interval)
|
287
|
-
).size.should == count
|
288
|
-
end
|
289
|
-
|
290
|
-
it "should give full data in case skip_optimization parameter set to true" do
|
291
|
-
count = max * 2
|
292
|
-
sensor.timeline_within(
|
293
|
-
Time.at(@start_of_interval - 1),
|
294
|
-
Time.at(@start_of_interval + count * interval),
|
295
|
-
true
|
296
|
-
).size.should == count
|
297
|
-
end
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
describe "#timeline" do
|
302
|
-
it "should raise exception if passed interval is not a positive integer" do
|
303
|
-
[:q, nil, -1].each do |bad_interval|
|
304
|
-
expect{ sensor.timeline(bad_interval) }.to raise_exception(ArgumentError)
|
305
|
-
end
|
306
|
-
end
|
307
|
-
|
308
|
-
it "should request timeline within interval from given number of seconds ago till now" do
|
309
|
-
Timecop.freeze do
|
310
|
-
now = Time.now
|
311
|
-
ago = interval * 100
|
312
|
-
sensor.timeline(ago).should == sensor.timeline_within(now - ago, now)
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
it "should return array of results containing as many results as there are sensor interval beginnings in the passed interval" do
|
317
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
318
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
319
|
-
|
320
|
-
Timecop.freeze(@start_of_interval + interval + 1) do
|
321
|
-
sensor.timeline(2).size.should == 1
|
322
|
-
end
|
323
|
-
Timecop.freeze(@start_of_interval + interval + 2) do
|
324
|
-
sensor.timeline(1).size.should == 0
|
325
|
-
end
|
326
|
-
Timecop.freeze(@start_of_interval + interval + 1) do
|
327
|
-
sensor.timeline(2 + interval).size.should == 2
|
328
|
-
end
|
329
|
-
end
|
330
|
-
end
|
331
|
-
|
332
|
-
describe "#drop_within" do
|
333
|
-
it "should raise exception unless both arguments are Time objects" do
|
334
|
-
[:q, nil, -1].each do |bad_value|
|
335
|
-
expect{ sensor.drop_within(Time.now, bad_value) }.to raise_exception(ArgumentError)
|
336
|
-
expect{ sensor.drop_within(bad_value, Time.now) }.to raise_exception(ArgumentError)
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
340
|
-
it "should drop as many raw results as there are sensor interval beginnings in the passed interval" do
|
341
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
342
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
343
|
-
|
344
|
-
future = @start_of_interval + interval * 3
|
345
|
-
Timecop.freeze(future) do
|
346
|
-
sensor.drop_within(
|
347
|
-
Time.at(@start_of_interval + interval - 1),
|
348
|
-
Time.at(@start_of_interval + interval + 1)
|
349
|
-
).should == 1
|
350
|
-
|
351
|
-
data = sensor.timeline_within(
|
352
|
-
Time.at(@start_of_interval + interval - 1),
|
353
|
-
Time.at(@start_of_interval + interval + 1)
|
354
|
-
)
|
355
|
-
data.size.should == 1
|
356
|
-
data.first.value.should be_nil # since data is dropped
|
357
|
-
|
358
|
-
end
|
359
|
-
|
360
|
-
Timecop.freeze(@start_of_interval + interval + 2) do
|
361
|
-
sensor.drop_within(
|
362
|
-
Time.at(@start_of_interval + interval + 1),
|
363
|
-
Time.at(@start_of_interval + interval + 2)
|
364
|
-
).should == 0
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
it "should drop as many reduced results as there are sensor interval beginnings in the passed interval" do
|
369
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
370
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
371
|
-
|
372
|
-
future = @start_of_interval
|
373
|
-
Timecop.freeze(future) do
|
374
|
-
sensor.reduce_all_raw
|
375
|
-
sensor.drop_within(
|
376
|
-
Time.at(@start_of_interval + interval - 1),
|
377
|
-
Time.at(@start_of_interval + interval + 1)
|
378
|
-
).should == 1
|
379
|
-
|
380
|
-
data = sensor.timeline_within(
|
381
|
-
Time.at(@start_of_interval + interval - 1),
|
382
|
-
Time.at(@start_of_interval + interval + 1)
|
383
|
-
)
|
384
|
-
data.size.should == 1
|
385
|
-
data.first.value.should be_nil # since data is dropped
|
386
|
-
|
387
|
-
end
|
388
|
-
|
389
|
-
Timecop.freeze(@start_of_interval + interval + 2) do
|
390
|
-
sensor.drop_within(
|
391
|
-
Time.at(@start_of_interval + interval + 1),
|
392
|
-
Time.at(@start_of_interval + interval + 2)
|
393
|
-
).should == 0
|
394
|
-
end
|
395
|
-
end
|
396
|
-
end
|
397
|
-
|
398
|
-
describe "SensorData value for an interval" do
|
399
|
-
def check_sensor_data(sensor, value)
|
400
|
-
data = sensor.timeline(2).first
|
401
|
-
data.value.should be_generally_equal(sensor.deflate_safe(value))
|
402
|
-
data.start_time.to_i.should == @interval_id
|
403
|
-
end
|
404
|
-
|
405
|
-
it "should contain summarized value stored by data_key for reduced intervals" do
|
406
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
407
|
-
sensor.reduce(@interval_id)
|
408
|
-
Timecop.freeze(@start_of_interval + 1){
|
409
|
-
check_sensor_data(sensor, redis.get(sensor.data_key(@interval_id)))
|
410
|
-
}
|
411
|
-
end
|
412
|
-
|
413
|
-
it "should contain summarized value based on raw data for intervals not yet reduced" do
|
414
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
415
|
-
Timecop.freeze(@start_of_interval + 1){
|
416
|
-
check_sensor_data(sensor, sensor.summarize(@raw_data_key))
|
417
|
-
}
|
418
|
-
end
|
419
|
-
|
420
|
-
it "should contain nil for intervals without any data" do
|
421
|
-
Timecop.freeze(@start_of_interval + 1) {
|
422
|
-
check_sensor_data(sensor, nil)
|
423
|
-
}
|
424
|
-
end
|
425
|
-
end
|
426
|
-
|
427
|
-
describe "#cleanup" do
|
428
|
-
it "should remove all sensor data (raw data, reduced data, annotations) from redis" do
|
429
|
-
Timecop.freeze(@start_of_interval){ sensor.event(sample_event) }
|
430
|
-
sensor.reduce(@interval_id)
|
431
|
-
Timecop.freeze(@start_of_interval + interval){ sensor.event(sample_event) }
|
432
|
-
sensor.annotate("Fooo sensor")
|
433
|
-
|
434
|
-
sensor.cleanup
|
435
|
-
redis.keys('*').should be_empty
|
436
|
-
end
|
437
|
-
end
|
438
|
-
|
439
|
-
end
|