pulse_meter_core 0.5.3 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/.rbenv-version +1 -1
- data/.travis.yml +2 -0
- data/pulse_meter_core.gemspec +1 -1
- data/spec/pulse_meter/command_aggregator/async_spec.rb +14 -14
- data/spec/pulse_meter/command_aggregator/sync_spec.rb +5 -5
- data/spec/pulse_meter/command_aggregator/udp_spec.rb +8 -8
- data/spec/pulse_meter/mixins/dumper_spec.rb +27 -27
- data/spec/pulse_meter/mixins/utils_spec.rb +64 -64
- data/spec/pulse_meter/observer/extended_spec.rb +20 -20
- data/spec/pulse_meter/observer_spec.rb +26 -26
- data/spec/pulse_meter/sensor/base_spec.rb +25 -25
- data/spec/pulse_meter/sensor/configuration_spec.rb +21 -21
- data/spec/pulse_meter/sensor/counter_spec.rb +12 -12
- data/spec/pulse_meter/sensor/hashed_counter_spec.rb +9 -9
- data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +10 -10
- data/spec/pulse_meter/sensor/indicator_spec.rb +9 -9
- data/spec/pulse_meter/sensor/multi_spec.rb +13 -13
- data/spec/pulse_meter/sensor/timeline_spec.rb +12 -12
- data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +2 -2
- data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +1 -1
- data/spec/pulse_meter/sensor/uniq_counter_spec.rb +5 -5
- data/spec/pulse_meter/udp_server_spec.rb +9 -9
- data/spec/pulse_meter_spec.rb +21 -21
- data/spec/shared_examples/timeline_sensor.rb +88 -88
- data/spec/shared_examples/timelined_subclass.rb +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/matchers.rb +2 -2
- metadata +34 -34
@@ -6,48 +6,48 @@ describe PulseMeter::Sensor::Counter do
|
|
6
6
|
let(:redis){ PulseMeter.redis }
|
7
7
|
|
8
8
|
describe "#event" do
|
9
|
-
it "
|
9
|
+
it "increments sensor value by passed value" do
|
10
10
|
expect{ sensor.event(10) }.to change{ sensor.value }.from(0).to(10)
|
11
11
|
expect{ sensor.event(15) }.to change{ sensor.value }.from(10).to(25)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "truncates increment value" do
|
15
15
|
expect{ sensor.event(10.4) }.to change{ sensor.value }.from(0).to(10)
|
16
16
|
expect{ sensor.event(15.1) }.to change{ sensor.value }.from(10).to(25)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
describe "#value_key" do
|
21
|
-
it "
|
22
|
-
sensor.value_key.
|
21
|
+
it "is composed of sensor name and pulse_meter:value: prefix" do
|
22
|
+
expect(sensor.value_key).to eq("pulse_meter:value:#{name}")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
|
26
26
|
describe "#value" do
|
27
|
-
it "
|
28
|
-
sensor.value.
|
27
|
+
it "has initial value 0" do
|
28
|
+
expect(sensor.value).to eq(0)
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
31
|
+
it "stores stringified value by value_key" do
|
32
32
|
sensor.event(123)
|
33
|
-
sensor.value.
|
34
|
-
redis.get(sensor.value_key).
|
33
|
+
expect(sensor.value).to eq(123)
|
34
|
+
expect(redis.get(sensor.value_key)).to eq('123')
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe "#incr" do
|
39
|
-
it "
|
39
|
+
it "increments value by 1" do
|
40
40
|
expect{ sensor.incr }.to change{ sensor.value }.from(0).to(1)
|
41
41
|
expect{ sensor.incr }.to change{ sensor.value }.from(1).to(2)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
45
|
describe "#cleanup" do
|
46
|
-
it "
|
46
|
+
it "removes all sensor data" do
|
47
47
|
sensor.annotate("My Counter")
|
48
48
|
sensor.event(123)
|
49
49
|
sensor.cleanup
|
50
|
-
redis.keys('*').
|
50
|
+
expect(redis.keys('*')).to be_empty
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -6,35 +6,35 @@ describe PulseMeter::Sensor::HashedCounter do
|
|
6
6
|
let(:redis){ PulseMeter.redis }
|
7
7
|
|
8
8
|
describe "#event" do
|
9
|
-
it "
|
9
|
+
it "increments sensor value by passed value" do
|
10
10
|
expect{ sensor.event({"foo" => 10}) }.to change{ sensor.value["foo"] }.from(0).to(10)
|
11
11
|
expect{ sensor.event({"foo" => 15}) }.to change{ sensor.value["foo"] }.from(10).to(25)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "truncates increment value" do
|
15
15
|
expect{ sensor.event({"foo" => 10.4}) }.to change{ sensor.value["foo"] }.from(0).to(10)
|
16
16
|
expect{ sensor.event({"foo" => 15.1}) }.to change{ sensor.value["foo"] }.from(10).to(25)
|
17
17
|
end
|
18
18
|
|
19
|
-
it "
|
19
|
+
it "increments total value" do
|
20
20
|
expect{ sensor.event({"foo" => 1, "bar" => 2}) }.to change{sensor.value["total"]}.from(0).to(3)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "#value" do
|
25
|
-
it "
|
26
|
-
sensor.value["foo"].
|
25
|
+
it "has initial value 0" do
|
26
|
+
expect(sensor.value["foo"]).to eq(0)
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
29
|
+
it "stores redis hash by value_key" do
|
30
30
|
sensor.event({"foo" => 1})
|
31
|
-
sensor.value.
|
32
|
-
redis.hgetall(sensor.value_key).
|
31
|
+
expect(sensor.value).to eq({"foo" => 1, "total" => 1})
|
32
|
+
expect(redis.hgetall(sensor.value_key)).to eq({"foo" => "1", "total" => "1"})
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
describe "#incr" do
|
37
|
-
it "
|
37
|
+
it "increments key value by 1" do
|
38
38
|
expect{ sensor.incr("foo") }.to change{ sensor.value["foo"] }.from(0).to(1)
|
39
39
|
expect{ sensor.incr("foo") }.to change{ sensor.value["foo"] }.from(1).to(2)
|
40
40
|
end
|
@@ -6,33 +6,33 @@ describe PulseMeter::Sensor::HashedIndicator do
|
|
6
6
|
let(:redis){ PulseMeter.redis }
|
7
7
|
|
8
8
|
describe "#event" do
|
9
|
-
it "
|
9
|
+
it "sets sensor value to passed value" do
|
10
10
|
expect{ sensor.event("foo" => 10.4) }.to change{ sensor.value["foo"] }.from(0).to(10.4)
|
11
11
|
expect{ sensor.event("foo" => 15.1) }.to change{ sensor.value["foo"] }.from(10.4).to(15.1)
|
12
12
|
end
|
13
13
|
|
14
|
-
it "
|
14
|
+
it "takes multiple events" do
|
15
15
|
data = {"foo" => 1.1, "boo" => 2.2}
|
16
16
|
sensor.event(data)
|
17
|
-
sensor.value.
|
17
|
+
expect(sensor.value).to eq(data)
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#value_key" do
|
22
|
-
it "
|
23
|
-
sensor.value_key.
|
22
|
+
it "is composed of sensor name and pulse_meter:value: prefix" do
|
23
|
+
expect(sensor.value_key).to eq("pulse_meter:value:#{name}")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
27
27
|
describe "#value" do
|
28
|
-
it "
|
29
|
-
sensor.value["foo"].
|
28
|
+
it "has initial value 0" do
|
29
|
+
expect(sensor.value["foo"]).to eq(0)
|
30
30
|
end
|
31
31
|
|
32
|
-
it "
|
32
|
+
it "stores redis hash by value_key" do
|
33
33
|
sensor.event({"foo" => 1})
|
34
|
-
sensor.value.
|
35
|
-
redis.hgetall(sensor.value_key).
|
34
|
+
expect(sensor.value).to eq({"foo" => 1})
|
35
|
+
expect(redis.hgetall(sensor.value_key)).to eq({"foo" => "1.0"})
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
@@ -6,36 +6,36 @@ describe PulseMeter::Sensor::Indicator do
|
|
6
6
|
let(:redis){ PulseMeter.redis }
|
7
7
|
|
8
8
|
describe "#event" do
|
9
|
-
it "
|
9
|
+
it "sets sensor value to passed value" do
|
10
10
|
expect{ sensor.event(10.4) }.to change{ sensor.value }.from(0).to(10.4)
|
11
11
|
expect{ sensor.event(15.1) }.to change{ sensor.value }.from(10.4).to(15.1)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "#value_key" do
|
16
|
-
it "
|
17
|
-
sensor.value_key.
|
16
|
+
it "is composed of sensor name and pulse_meter:value: prefix" do
|
17
|
+
expect(sensor.value_key).to eq("pulse_meter:value:#{name}")
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
21
|
describe "#value" do
|
22
|
-
it "
|
23
|
-
sensor.value.
|
22
|
+
it "has initial value 0" do
|
23
|
+
expect(sensor.value).to eq(0)
|
24
24
|
end
|
25
25
|
|
26
|
-
it "
|
26
|
+
it "stores stringified value by value_key" do
|
27
27
|
sensor.event(123)
|
28
|
-
sensor.value.
|
28
|
+
expect(sensor.value).to eq(123)
|
29
29
|
redis.get(sensor.value_key) == '123'
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
describe "#cleanup" do
|
34
|
-
it "
|
34
|
+
it "removes all sensor data" do
|
35
35
|
sensor.annotate("My Indicator")
|
36
36
|
sensor.event(123)
|
37
37
|
sensor.cleanup
|
38
|
-
redis.keys('*').
|
38
|
+
expect(redis.keys('*')).to be_empty
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
@@ -34,19 +34,19 @@ describe PulseMeter::Sensor::Multi do
|
|
34
34
|
|
35
35
|
describe "#factors" do
|
36
36
|
it "returns factors passed to constructor" do
|
37
|
-
sensor.factors.
|
37
|
+
expect(sensor.factors).to eq(factors)
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
41
|
describe "#configuration_options" do
|
42
42
|
it "returns configuration option passed to constructor" do
|
43
|
-
sensor.configuration_options.
|
43
|
+
expect(sensor.configuration_options).to eq(configuration)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#sensors" do
|
48
48
|
it "returns PulseMeter::Sensor::Configuration instance" do
|
49
|
-
sensor.sensors.
|
49
|
+
expect(sensor.sensors).to be_instance_of(PulseMeter::Sensor::Configuration)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
@@ -67,19 +67,19 @@ describe PulseMeter::Sensor::Multi do
|
|
67
67
|
it "assigns names based on factors' names and values" do
|
68
68
|
sensor.event(factor_values, 1)
|
69
69
|
names = sensor.sensors.to_a.map(&:name)
|
70
|
-
names.sort.
|
70
|
+
expect(names.sort).to eq([
|
71
71
|
"#{name}",
|
72
72
|
"#{name}_f1_v1",
|
73
73
|
"#{name}_f2_v2",
|
74
74
|
"#{name}_f1_v1_f2_v2"
|
75
|
-
].sort
|
75
|
+
].sort)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "creates sensors of given type with configuration options passed" do
|
79
79
|
sensor.event(factor_values, 1)
|
80
80
|
sensor.sensors.each do |s|
|
81
|
-
s.
|
82
|
-
s.annotation.
|
81
|
+
expect(s).to be_instance_of(PulseMeter::Sensor::Counter)
|
82
|
+
expect(s.annotation).to eq(annotation)
|
83
83
|
end
|
84
84
|
end
|
85
85
|
end
|
@@ -96,7 +96,7 @@ describe PulseMeter::Sensor::Multi do
|
|
96
96
|
["#{name}_f1_f1v2_f2_f2v1", 2]
|
97
97
|
].each do |sensor_name, sum|
|
98
98
|
sensor.sensor(sensor_name) { |s|
|
99
|
-
s.value.
|
99
|
+
expect(s.value).to eq(sum)
|
100
100
|
}
|
101
101
|
end
|
102
102
|
end
|
@@ -107,12 +107,12 @@ describe PulseMeter::Sensor::Multi do
|
|
107
107
|
sensor.event({f1: :f1v1, f2: :f2v1}, 1)
|
108
108
|
restored_sensor = PulseMeter::Sensor::Base.restore(name)
|
109
109
|
|
110
|
-
restored_sensor.to_a.map(&:name).sort.
|
110
|
+
expect(restored_sensor.to_a.map(&:name).sort).to eq([
|
111
111
|
"#{name}",
|
112
112
|
"#{name}_f1_f1v1",
|
113
113
|
"#{name}_f2_f2v1",
|
114
114
|
"#{name}_f1_f1v1_f2_f2v1",
|
115
|
-
].sort
|
115
|
+
].sort)
|
116
116
|
end
|
117
117
|
end
|
118
118
|
|
@@ -120,8 +120,8 @@ describe PulseMeter::Sensor::Multi do
|
|
120
120
|
context "when sensor has already been created" do
|
121
121
|
it "yields block with sensor for given combination of factors and their values" do
|
122
122
|
sensor.event({f1: :f1v1, f2: :f2v1}, 1)
|
123
|
-
sensor.sensor_for_factors([:f1, :f2], [:f1v1, :f2v1]){|s| s.name.
|
124
|
-
sensor.sensor_for_factors([:f1], [:f1v1]){|s| s.name.
|
123
|
+
sensor.sensor_for_factors([:f1, :f2], [:f1v1, :f2v1]){|s| expect(s.name).to eq("#{name}_f1_f1v1_f2_f2v1")}
|
124
|
+
sensor.sensor_for_factors([:f1], [:f1v1]){|s| expect(s.name).to eq("#{name}_f1_f1v1")}
|
125
125
|
end
|
126
126
|
end
|
127
127
|
|
@@ -129,7 +129,7 @@ describe PulseMeter::Sensor::Multi do
|
|
129
129
|
it "does not yields block" do
|
130
130
|
yielded = false
|
131
131
|
sensor.sensor_for_factors([:foo], [:bar]){ yielded = true }
|
132
|
-
yielded.
|
132
|
+
expect(yielded).not_to be
|
133
133
|
end
|
134
134
|
end
|
135
135
|
end
|
@@ -21,36 +21,36 @@ describe PulseMeter::Sensor::Timeline do
|
|
21
21
|
shared_examples_for "error raiser" do |value_names, bad_values|
|
22
22
|
value_names.each do |value|
|
23
23
|
bad_values.each do |bad_value|
|
24
|
-
it "
|
24
|
+
it "raises exception if a bad value #{bad_value.inspect} passed for #{value.inspect}" do
|
25
25
|
expect{ described_class.new(name, good_init_values.merge(value => bad_value)) }.to raise_exception(ArgumentError)
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
it "
|
32
|
-
sensor.name.
|
31
|
+
it "initializes #ttl #raw_data_ttl #interval and #name attributes" do
|
32
|
+
expect(sensor.name).to eq(name.to_s)
|
33
33
|
|
34
|
-
sensor.ttl.
|
35
|
-
sensor.raw_data_ttl.
|
36
|
-
sensor.interval.
|
34
|
+
expect(sensor.ttl).to eq(ttl)
|
35
|
+
expect(sensor.raw_data_ttl).to eq(raw_data_ttl)
|
36
|
+
expect(sensor.interval).to eq(interval)
|
37
37
|
end
|
38
38
|
|
39
39
|
it_should_behave_like "error raiser", INIT_VALUE_NAMES[:without_defaults], [:bad, -1, nil]
|
40
40
|
it_should_behave_like "error raiser", INIT_VALUE_NAMES[:with_defaults], [:bad, -1]
|
41
41
|
|
42
42
|
INIT_VALUE_NAMES[:with_defaults].each do |value|
|
43
|
-
it "
|
43
|
+
it "does not raise exception if #{value.inspect} is not defined" do
|
44
44
|
values = good_init_values
|
45
45
|
values.delete(value)
|
46
46
|
expect {described_class.new(name, good_init_values)}.not_to raise_error
|
47
47
|
end
|
48
48
|
|
49
|
-
it "
|
49
|
+
it "assigns default value to #{value.inspect} if it is not defined" do
|
50
50
|
values = good_init_values
|
51
51
|
values.delete(value)
|
52
52
|
obj = described_class.new(name, good_init_values)
|
53
|
-
obj.send(value).
|
53
|
+
expect(obj.send(value)).to be_kind_of(Fixnum)
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
@@ -73,15 +73,15 @@ describe PulseMeter::Sensor::Timeline do
|
|
73
73
|
let!(:bad_instance) { BadSubclass.new("bad", good_init_values) }
|
74
74
|
|
75
75
|
it "preserves nil values" do
|
76
|
-
good_instance.deflate_safe(nil).
|
76
|
+
expect(good_instance.deflate_safe(nil)).to be_nil
|
77
77
|
end
|
78
78
|
|
79
79
|
it "converts value as defined in subclass" do
|
80
|
-
good_instance.deflate_safe("10").
|
80
|
+
expect(good_instance.deflate_safe("10")).to eq(10)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "returns nil if conversion fails" do
|
84
|
-
bad_instance.deflate_safe(:foo).
|
84
|
+
expect(bad_instance.deflate_safe(:foo)).to be_nil
|
85
85
|
end
|
86
86
|
end
|
87
87
|
|
@@ -8,11 +8,11 @@ describe PulseMeter::Sensor::Timelined::MultiPercentile do
|
|
8
8
|
let(:init_values) {{:ttl => 1, :raw_data_ttl => 1, :interval => 1, :reduce_delay => 1}}
|
9
9
|
let(:name) {"percentile"}
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "raises exception when extra parameter is not array of percentiles" do
|
12
12
|
expect {described_class.new(name, init_values.merge({:p => :bad}))}.to raise_exception(ArgumentError)
|
13
13
|
end
|
14
14
|
|
15
|
-
it "
|
15
|
+
it "raises exception when one of percentiles is not between 0 and 1" do
|
16
16
|
expect {described_class.new(name, init_values.merge({:p => [0.5, -1]}))}.to raise_exception(ArgumentError)
|
17
17
|
expect {described_class.new(name, init_values.merge({:p => [0.5, 1.1]}))}.to raise_exception(ArgumentError)
|
18
18
|
expect {described_class.new(name, init_values.merge({:p => [0.5, 0.1]}))}.not_to raise_exception
|
@@ -8,7 +8,7 @@ describe PulseMeter::Sensor::Timelined::Percentile do
|
|
8
8
|
let(:init_values) {{:ttl => 1, :raw_data_ttl => 1, :interval => 1, :reduce_delay => 1}}
|
9
9
|
let(:name) {"percentile"}
|
10
10
|
|
11
|
-
it "
|
11
|
+
it "raises exception when percentile is not between 0 and 1" do
|
12
12
|
expect {described_class.new(name, init_values.merge({:p => -1}))}.to raise_exception(ArgumentError)
|
13
13
|
expect {described_class.new(name, init_values.merge({:p => 1.1}))}.to raise_exception(ArgumentError)
|
14
14
|
expect {described_class.new(name, init_values.merge({:p => 0.1}))}.not_to raise_exception
|
@@ -6,7 +6,7 @@ describe PulseMeter::Sensor::UniqCounter do
|
|
6
6
|
let(:redis){ PulseMeter.redis }
|
7
7
|
|
8
8
|
describe "#event" do
|
9
|
-
it "
|
9
|
+
it "counts unique values" do
|
10
10
|
expect{ sensor.event(:first) }.to change{sensor.value}.to(1)
|
11
11
|
expect{ sensor.event(:first) }.not_to change{sensor.value}
|
12
12
|
expect{ sensor.event(:second) }.to change{sensor.value}.from(1).to(2)
|
@@ -14,14 +14,14 @@ describe PulseMeter::Sensor::UniqCounter do
|
|
14
14
|
end
|
15
15
|
|
16
16
|
describe "#value" do
|
17
|
-
it "
|
18
|
-
sensor.value.
|
17
|
+
it "has initial value 0" do
|
18
|
+
expect(sensor.value).to eq(0)
|
19
19
|
end
|
20
20
|
|
21
|
-
it "
|
21
|
+
it "returns count of unique values" do
|
22
22
|
data = (1..100).map {rand(200)}
|
23
23
|
data.each {|e| sensor.event(e)}
|
24
|
-
sensor.value.
|
24
|
+
expect(sensor.value).to eq(data.uniq.count)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -6,9 +6,9 @@ describe PulseMeter::UDPServer do
|
|
6
6
|
let(:udp_sock){double(:socket)}
|
7
7
|
let(:redis){PulseMeter.redis}
|
8
8
|
before do
|
9
|
-
UDPSocket.
|
10
|
-
udp_sock.
|
11
|
-
udp_sock.
|
9
|
+
expect(UDPSocket).to receive(:new).and_return(udp_sock)
|
10
|
+
expect(udp_sock).to receive(:bind).with(host, port).and_return(nil)
|
11
|
+
expect(udp_sock).to receive("do_not_reverse_lookup=").with(true).and_return(nil)
|
12
12
|
@server = described_class.new(host, port)
|
13
13
|
end
|
14
14
|
|
@@ -19,15 +19,15 @@ describe PulseMeter::UDPServer do
|
|
19
19
|
["set", "yyyy", "zzzz"]
|
20
20
|
].to_json
|
21
21
|
}
|
22
|
-
it "
|
23
|
-
udp_sock.
|
22
|
+
it "processes proper incoming commands" do
|
23
|
+
expect(udp_sock).to receive(:recvfrom).with(described_class::MAX_PACKET).and_return(data)
|
24
24
|
@server.start(1)
|
25
|
-
redis.get("xxxx").
|
26
|
-
redis.get("yyyy").
|
25
|
+
expect(redis.get("xxxx")).to eq("zzzz")
|
26
|
+
expect(redis.get("yyyy")).to eq("zzzz")
|
27
27
|
end
|
28
28
|
|
29
|
-
it "
|
30
|
-
udp_sock.
|
29
|
+
it "suppresses JSON errors" do
|
30
|
+
expect(udp_sock).to receive(:recvfrom).with(described_class::MAX_PACKET).and_return("xxx")
|
31
31
|
expect{ @server.start(1) }.not_to raise_exception
|
32
32
|
end
|
33
33
|
end
|
data/spec/pulse_meter_spec.rb
CHANGED
@@ -2,71 +2,71 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe PulseMeter do
|
4
4
|
describe "::redis=" do
|
5
|
-
it "
|
5
|
+
it "stores redis" do
|
6
6
|
PulseMeter.redis = 'redis'
|
7
|
-
PulseMeter.redis.
|
7
|
+
expect(PulseMeter.redis).to eq('redis')
|
8
8
|
end
|
9
9
|
end
|
10
10
|
describe "::redis" do
|
11
|
-
it "
|
11
|
+
it "retrieves redis" do
|
12
12
|
PulseMeter.redis = 'redis'
|
13
|
-
PulseMeter.redis.
|
13
|
+
expect(PulseMeter.redis).to eq('redis')
|
14
14
|
end
|
15
15
|
end
|
16
16
|
describe "::command_aggregator=" do
|
17
17
|
context "when :async passed" do
|
18
|
-
it "
|
18
|
+
it "sets async command_aggregator to be used" do
|
19
19
|
PulseMeter.command_aggregator = :async
|
20
|
-
PulseMeter.command_aggregator.
|
20
|
+
expect(PulseMeter.command_aggregator).to be_kind_of(PulseMeter::CommandAggregator::Async)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
context "when :sync passed" do
|
24
|
-
it "
|
24
|
+
it "sets sync command_aggregator to be used" do
|
25
25
|
PulseMeter.command_aggregator = :sync
|
26
|
-
PulseMeter.command_aggregator.
|
26
|
+
expect(PulseMeter.command_aggregator).to be_kind_of(PulseMeter::CommandAggregator::Sync)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
context "otherwise" do
|
30
|
-
it "
|
30
|
+
it "sets command_aggregator to the passed value" do
|
31
31
|
PulseMeter.command_aggregator = :xxx
|
32
|
-
PulseMeter.command_aggregator.
|
32
|
+
expect(PulseMeter.command_aggregator).to eq(:xxx)
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "::command_aggregator" do
|
38
|
-
it "
|
38
|
+
it "returns current command_aggregator" do
|
39
39
|
PulseMeter.command_aggregator = :async
|
40
|
-
PulseMeter.command_aggregator.
|
40
|
+
expect(PulseMeter.command_aggregator).to be_kind_of(PulseMeter::CommandAggregator::Async)
|
41
41
|
PulseMeter.command_aggregator = :sync
|
42
|
-
PulseMeter.command_aggregator.
|
42
|
+
expect(PulseMeter.command_aggregator).to be_kind_of(PulseMeter::CommandAggregator::Sync)
|
43
43
|
end
|
44
44
|
|
45
|
-
it "
|
45
|
+
it "always returns the same command_aggregator for each type" do
|
46
46
|
PulseMeter.command_aggregator = :async
|
47
47
|
ca1 = PulseMeter.command_aggregator
|
48
48
|
PulseMeter.command_aggregator = :sync
|
49
49
|
PulseMeter.command_aggregator = :async
|
50
50
|
ca2 = PulseMeter.command_aggregator
|
51
|
-
ca1.
|
51
|
+
expect(ca1).to eq(ca2)
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
55
|
describe "::logger" do
|
56
|
-
it "
|
56
|
+
it "returns PulseMeter logger" do
|
57
57
|
PulseMeter.logger = 123
|
58
|
-
PulseMeter.logger.
|
58
|
+
expect(PulseMeter.logger).to eq(123)
|
59
59
|
end
|
60
60
|
|
61
|
-
it "
|
61
|
+
it "returns default logger" do
|
62
62
|
PulseMeter.logger = nil
|
63
|
-
PulseMeter.logger.
|
63
|
+
expect(PulseMeter.logger).to be_kind_of(Logger)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
67
|
describe "::error" do
|
68
|
-
it "
|
69
|
-
PulseMeter.logger.
|
68
|
+
it "delegates error message to logger" do
|
69
|
+
expect(PulseMeter.logger).to receive(:error)
|
70
70
|
PulseMeter.error("foo")
|
71
71
|
end
|
72
72
|
end
|