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.
Files changed (192) hide show
  1. data/Rakefile +1 -48
  2. data/lib/pulse-meter.rb +1 -68
  3. data/lib/pulse-meter/visualizer.rb +1 -40
  4. data/pulse-meter.gemspec +4 -26
  5. metadata +10 -558
  6. data/Procfile +0 -3
  7. data/bin/pulse +0 -6
  8. data/examples/basic.ru +0 -145
  9. data/examples/basic_sensor_data.rb +0 -96
  10. data/examples/udp_benchmark.rb +0 -29
  11. data/lib/cmd.rb +0 -171
  12. data/lib/pulse-meter/command_aggregator/async.rb +0 -83
  13. data/lib/pulse-meter/command_aggregator/sync.rb +0 -18
  14. data/lib/pulse-meter/command_aggregator/udp.rb +0 -48
  15. data/lib/pulse-meter/extensions/enumerable.rb +0 -24
  16. data/lib/pulse-meter/mixins/cmd.rb +0 -46
  17. data/lib/pulse-meter/mixins/dumper.rb +0 -87
  18. data/lib/pulse-meter/mixins/utils.rb +0 -155
  19. data/lib/pulse-meter/observer.rb +0 -120
  20. data/lib/pulse-meter/observer/extended.rb +0 -34
  21. data/lib/pulse-meter/sensor.rb +0 -61
  22. data/lib/pulse-meter/sensor/base.rb +0 -88
  23. data/lib/pulse-meter/sensor/configuration.rb +0 -106
  24. data/lib/pulse-meter/sensor/counter.rb +0 -39
  25. data/lib/pulse-meter/sensor/hashed_counter.rb +0 -36
  26. data/lib/pulse-meter/sensor/hashed_indicator.rb +0 -24
  27. data/lib/pulse-meter/sensor/indicator.rb +0 -35
  28. data/lib/pulse-meter/sensor/multi.rb +0 -97
  29. data/lib/pulse-meter/sensor/timeline.rb +0 -236
  30. data/lib/pulse-meter/sensor/timeline_reduce.rb +0 -68
  31. data/lib/pulse-meter/sensor/timelined/average.rb +0 -32
  32. data/lib/pulse-meter/sensor/timelined/counter.rb +0 -23
  33. data/lib/pulse-meter/sensor/timelined/hashed_counter.rb +0 -31
  34. data/lib/pulse-meter/sensor/timelined/hashed_indicator.rb +0 -30
  35. data/lib/pulse-meter/sensor/timelined/indicator.rb +0 -23
  36. data/lib/pulse-meter/sensor/timelined/max.rb +0 -19
  37. data/lib/pulse-meter/sensor/timelined/median.rb +0 -14
  38. data/lib/pulse-meter/sensor/timelined/min.rb +0 -19
  39. data/lib/pulse-meter/sensor/timelined/multi_percentile.rb +0 -34
  40. data/lib/pulse-meter/sensor/timelined/percentile.rb +0 -22
  41. data/lib/pulse-meter/sensor/timelined/uniq_counter.rb +0 -22
  42. data/lib/pulse-meter/sensor/timelined/zset_based.rb +0 -38
  43. data/lib/pulse-meter/sensor/uniq_counter.rb +0 -24
  44. data/lib/pulse-meter/server.rb +0 -0
  45. data/lib/pulse-meter/server/command_line_options.rb +0 -0
  46. data/lib/pulse-meter/server/config_options.rb +0 -0
  47. data/lib/pulse-meter/server/sensors.rb +0 -0
  48. data/lib/pulse-meter/udp_server.rb +0 -45
  49. data/lib/pulse-meter/version.rb +0 -3
  50. data/lib/pulse-meter/visualize/app.rb +0 -78
  51. data/lib/pulse-meter/visualize/base.rb +0 -15
  52. data/lib/pulse-meter/visualize/coffee/application.coffee +0 -40
  53. data/lib/pulse-meter/visualize/coffee/collections/page_info_list.coffee +0 -17
  54. data/lib/pulse-meter/visualize/coffee/collections/sensor_info_list.coffee +0 -4
  55. data/lib/pulse-meter/visualize/coffee/collections/widget_list.coffee +0 -14
  56. data/lib/pulse-meter/visualize/coffee/extensions.coffee +0 -26
  57. data/lib/pulse-meter/visualize/coffee/models/dinamic_widget.coffee +0 -34
  58. data/lib/pulse-meter/visualize/coffee/models/page_info.coffee +0 -2
  59. data/lib/pulse-meter/visualize/coffee/models/sensor_info.coffee +0 -2
  60. data/lib/pulse-meter/visualize/coffee/models/widget.coffee +0 -54
  61. data/lib/pulse-meter/visualize/coffee/presenters/area.coffee +0 -2
  62. data/lib/pulse-meter/visualize/coffee/presenters/gauge.coffee +0 -11
  63. data/lib/pulse-meter/visualize/coffee/presenters/line.coffee +0 -2
  64. data/lib/pulse-meter/visualize/coffee/presenters/pie.coffee +0 -20
  65. data/lib/pulse-meter/visualize/coffee/presenters/series.coffee +0 -44
  66. data/lib/pulse-meter/visualize/coffee/presenters/table.coffee +0 -10
  67. data/lib/pulse-meter/visualize/coffee/presenters/timeline.coffee +0 -13
  68. data/lib/pulse-meter/visualize/coffee/presenters/widget.coffee +0 -65
  69. data/lib/pulse-meter/visualize/coffee/router.coffee +0 -21
  70. data/lib/pulse-meter/visualize/coffee/views/dynamic_chart.coffee +0 -91
  71. data/lib/pulse-meter/visualize/coffee/views/dynamic_widget.coffee +0 -58
  72. data/lib/pulse-meter/visualize/coffee/views/page_title.coffee +0 -17
  73. data/lib/pulse-meter/visualize/coffee/views/page_titles.coffee +0 -15
  74. data/lib/pulse-meter/visualize/coffee/views/sensor_info_list.coffee +0 -19
  75. data/lib/pulse-meter/visualize/coffee/views/widget.coffee +0 -99
  76. data/lib/pulse-meter/visualize/coffee/views/widget_chart.coffee +0 -13
  77. data/lib/pulse-meter/visualize/coffee/views/widget_list.coffee +0 -15
  78. data/lib/pulse-meter/visualize/dsl/base.rb +0 -131
  79. data/lib/pulse-meter/visualize/dsl/errors.rb +0 -40
  80. data/lib/pulse-meter/visualize/dsl/layout.rb +0 -27
  81. data/lib/pulse-meter/visualize/dsl/page.rb +0 -33
  82. data/lib/pulse-meter/visualize/dsl/sensor.rb +0 -20
  83. data/lib/pulse-meter/visualize/dsl/widget.rb +0 -37
  84. data/lib/pulse-meter/visualize/dsl/widgets/area.rb +0 -20
  85. data/lib/pulse-meter/visualize/dsl/widgets/gauge.rb +0 -12
  86. data/lib/pulse-meter/visualize/dsl/widgets/line.rb +0 -21
  87. data/lib/pulse-meter/visualize/dsl/widgets/pie.rb +0 -16
  88. data/lib/pulse-meter/visualize/dsl/widgets/table.rb +0 -19
  89. data/lib/pulse-meter/visualize/layout.rb +0 -79
  90. data/lib/pulse-meter/visualize/page.rb +0 -25
  91. data/lib/pulse-meter/visualize/public/css/application.css +0 -56
  92. data/lib/pulse-meter/visualize/public/css/bootstrap.css +0 -4883
  93. data/lib/pulse-meter/visualize/public/css/bootstrap.min.css +0 -729
  94. data/lib/pulse-meter/visualize/public/css/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  95. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  96. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  97. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  98. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  99. data/lib/pulse-meter/visualize/public/css/images/ui-bg_glass_75_ffffff_1x400.png +0 -0
  100. data/lib/pulse-meter/visualize/public/css/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  101. data/lib/pulse-meter/visualize/public/css/images/ui-bg_inset-soft_95_fef1ec_1x100.png +0 -0
  102. data/lib/pulse-meter/visualize/public/css/images/ui-icons_222222_256x240.png +0 -0
  103. data/lib/pulse-meter/visualize/public/css/images/ui-icons_2e83ff_256x240.png +0 -0
  104. data/lib/pulse-meter/visualize/public/css/images/ui-icons_454545_256x240.png +0 -0
  105. data/lib/pulse-meter/visualize/public/css/images/ui-icons_888888_256x240.png +0 -0
  106. data/lib/pulse-meter/visualize/public/css/images/ui-icons_cd0a0a_256x240.png +0 -0
  107. data/lib/pulse-meter/visualize/public/css/images/ui-icons_f6cf3b_256x240.png +0 -0
  108. data/lib/pulse-meter/visualize/public/css/jquery-ui-1.8.16.bootstrap.css +0 -1320
  109. data/lib/pulse-meter/visualize/public/favicon.ico +0 -208
  110. data/lib/pulse-meter/visualize/public/img/glyphicons-halflings-white.png +0 -0
  111. data/lib/pulse-meter/visualize/public/img/glyphicons-halflings.png +0 -0
  112. data/lib/pulse-meter/visualize/public/js/application.js +0 -973
  113. data/lib/pulse-meter/visualize/public/js/backbone-min.js +0 -38
  114. data/lib/pulse-meter/visualize/public/js/bootstrap.js +0 -1835
  115. data/lib/pulse-meter/visualize/public/js/jquery-1.7.2.min.js +0 -4
  116. data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.16.bootstrap.min.js +0 -791
  117. data/lib/pulse-meter/visualize/public/js/jquery-ui-1.8.23.custom.min.js +0 -21
  118. data/lib/pulse-meter/visualize/public/js/jquery-ui-timepicker-addon.js +0 -1687
  119. data/lib/pulse-meter/visualize/public/js/json2.js +0 -487
  120. data/lib/pulse-meter/visualize/public/js/underscore-min.js +0 -32
  121. data/lib/pulse-meter/visualize/sensor.rb +0 -63
  122. data/lib/pulse-meter/visualize/series_extractor.rb +0 -107
  123. data/lib/pulse-meter/visualize/views/main.haml +0 -30
  124. data/lib/pulse-meter/visualize/views/sensors.haml +0 -76
  125. data/lib/pulse-meter/visualize/views/widgets/area.haml +0 -53
  126. data/lib/pulse-meter/visualize/views/widgets/extend_options.haml +0 -11
  127. data/lib/pulse-meter/visualize/views/widgets/gauge.haml +0 -13
  128. data/lib/pulse-meter/visualize/views/widgets/line.haml +0 -54
  129. data/lib/pulse-meter/visualize/views/widgets/pie.haml +0 -13
  130. data/lib/pulse-meter/visualize/views/widgets/table.haml +0 -45
  131. data/lib/pulse-meter/visualize/widget.rb +0 -38
  132. data/lib/pulse-meter/visualize/widgets/gauge.rb +0 -47
  133. data/lib/pulse-meter/visualize/widgets/pie.rb +0 -36
  134. data/lib/pulse-meter/visualize/widgets/timeline.rb +0 -114
  135. data/spec/pulse_meter/command_aggregator/async_spec.rb +0 -53
  136. data/spec/pulse_meter/command_aggregator/sync_spec.rb +0 -25
  137. data/spec/pulse_meter/command_aggregator/udp_spec.rb +0 -45
  138. data/spec/pulse_meter/extensions/enumerable_spec.rb +0 -58
  139. data/spec/pulse_meter/mixins/cmd_spec.rb +0 -117
  140. data/spec/pulse_meter/mixins/dumper_spec.rb +0 -162
  141. data/spec/pulse_meter/mixins/utils_spec.rb +0 -212
  142. data/spec/pulse_meter/observer/extended_spec.rb +0 -92
  143. data/spec/pulse_meter/observer_spec.rb +0 -207
  144. data/spec/pulse_meter/sensor/base_spec.rb +0 -106
  145. data/spec/pulse_meter/sensor/configuration_spec.rb +0 -103
  146. data/spec/pulse_meter/sensor/counter_spec.rb +0 -54
  147. data/spec/pulse_meter/sensor/hashed_counter_spec.rb +0 -43
  148. data/spec/pulse_meter/sensor/hashed_indicator_spec.rb +0 -39
  149. data/spec/pulse_meter/sensor/indicator_spec.rb +0 -43
  150. data/spec/pulse_meter/sensor/multi_spec.rb +0 -137
  151. data/spec/pulse_meter/sensor/timeline_spec.rb +0 -88
  152. data/spec/pulse_meter/sensor/timelined/average_spec.rb +0 -6
  153. data/spec/pulse_meter/sensor/timelined/counter_spec.rb +0 -6
  154. data/spec/pulse_meter/sensor/timelined/hashed_counter_spec.rb +0 -8
  155. data/spec/pulse_meter/sensor/timelined/hashed_indicator_spec.rb +0 -8
  156. data/spec/pulse_meter/sensor/timelined/indicator_spec.rb +0 -6
  157. data/spec/pulse_meter/sensor/timelined/max_spec.rb +0 -7
  158. data/spec/pulse_meter/sensor/timelined/median_spec.rb +0 -7
  159. data/spec/pulse_meter/sensor/timelined/min_spec.rb +0 -7
  160. data/spec/pulse_meter/sensor/timelined/multi_percentile_spec.rb +0 -21
  161. data/spec/pulse_meter/sensor/timelined/percentile_spec.rb +0 -17
  162. data/spec/pulse_meter/sensor/timelined/uniq_counter_spec.rb +0 -9
  163. data/spec/pulse_meter/sensor/uniq_counter_spec.rb +0 -28
  164. data/spec/pulse_meter/udp_server_spec.rb +0 -36
  165. data/spec/pulse_meter/visualize/app_spec.rb +0 -27
  166. data/spec/pulse_meter/visualize/dsl/layout_spec.rb +0 -64
  167. data/spec/pulse_meter/visualize/dsl/page_spec.rb +0 -62
  168. data/spec/pulse_meter/visualize/dsl/sensor_spec.rb +0 -30
  169. data/spec/pulse_meter/visualize/dsl/widget_spec.rb +0 -6
  170. data/spec/pulse_meter/visualize/dsl/widgets/area_spec.rb +0 -44
  171. data/spec/pulse_meter/visualize/dsl/widgets/gauge_spec.rb +0 -22
  172. data/spec/pulse_meter/visualize/dsl/widgets/line_spec.rb +0 -44
  173. data/spec/pulse_meter/visualize/dsl/widgets/pie_spec.rb +0 -35
  174. data/spec/pulse_meter/visualize/dsl/widgets/table_spec.rb +0 -36
  175. data/spec/pulse_meter/visualize/layout_spec.rb +0 -54
  176. data/spec/pulse_meter/visualize/page_spec.rb +0 -153
  177. data/spec/pulse_meter/visualize/sensor_spec.rb +0 -120
  178. data/spec/pulse_meter/visualize/series_extractor_spec.rb +0 -80
  179. data/spec/pulse_meter/visualize/widgets/area_spec.rb +0 -6
  180. data/spec/pulse_meter/visualize/widgets/gauge_spec.rb +0 -63
  181. data/spec/pulse_meter/visualize/widgets/line_spec.rb +0 -6
  182. data/spec/pulse_meter/visualize/widgets/pie_spec.rb +0 -73
  183. data/spec/pulse_meter/visualize/widgets/table_spec.rb +0 -6
  184. data/spec/pulse_meter/visualizer_spec.rb +0 -42
  185. data/spec/pulse_meter_spec.rb +0 -73
  186. data/spec/shared_examples/dsl_widget.rb +0 -106
  187. data/spec/shared_examples/timeline_sensor.rb +0 -439
  188. data/spec/shared_examples/timelined_subclass.rb +0 -23
  189. data/spec/shared_examples/widget.rb +0 -97
  190. data/spec/spec_helper.rb +0 -40
  191. data/spec/support/matchers.rb +0 -34
  192. data/spec/support/observered.rb +0 -40
@@ -1,13 +0,0 @@
1
- %script.widget-template{type: 'text/template', 'data-widget-type' => 'pie'}
2
- #plotarea
3
- #chart-controls
4
- .form-inline
5
- %button#refresh.btn.btn-mini
6
- %i.icon-refresh
7
- Refresh
8
- %span.space
9
- %label
10
- Refresh:
11
- %input.btn-mini#need-refresh{type: :checkbox, checked: :true}
12
- %hr
13
-
@@ -1,45 +0,0 @@
1
- %script.widget-template{type: 'text/template', 'data-widget-type' => 'table'}
2
- #plotarea
3
- #chart-controls
4
- .form-inline
5
- %button#refresh.btn.btn-mini
6
- %i.icon-refresh
7
- Refresh
8
- %a#configure-button.btn.btn-mini{href: "#configure", role: 'button', 'data-toggle' => 'modal'}
9
- %i.icon-wrench
10
- Configure...
11
- .modal.hide.fade#configure
12
- .modal-header
13
- %button.close{type: 'button', 'data-dismiss' => 'modal', 'aria-hidden' => 'true'} ×
14
- %h3 Configure
15
- .modal-body
16
- %p
17
- %label
18
- Refresh:
19
- %input.btn-mini#need-refresh{type: :checkbox, checked: :true}
20
- %hr
21
- %p
22
- %label
23
- Timespan:
24
- %select#extend-timespan-val.btn-mini.span3
25
- = partial "widgets/extend_options"
26
- %button#extend-timespan.btn.btn-mini
27
- %i.icon-arrow-left
28
- Extend
29
- %button#reset-timespan.btn.btn-mini
30
- %i.icon-arrow-right
31
- Reset
32
- %hr
33
- %p
34
- %label
35
- From:
36
- %span#start-time
37
- %input.datepicker
38
- %label
39
- Till:
40
- %span#end-time
41
- %input.datepicker
42
- %button#set-interval.btn.btn-mini
43
- %i.icon-time
44
- Set interval
45
-
@@ -1,38 +0,0 @@
1
- module PulseMeter
2
- module Visualize
3
- class Error < StandardError; end
4
-
5
- class Widget < Base
6
- def initialize(opts)
7
- super
8
- @opts[:sensors] ||= []
9
- end
10
-
11
- def data
12
- {
13
- type: type,
14
- title: title,
15
- redraw_interval: redraw_interval,
16
- width: width,
17
- gchart_options: gchart_options,
18
- values_title: values_label
19
- }
20
- end
21
-
22
- def type
23
- self.class.to_s.split('::').last.downcase
24
- end
25
-
26
- protected
27
-
28
- def gauge_series_data
29
- ensure_gauge_indicators!
30
- sensors.map do |s|
31
- [s.annotation, s.value]
32
- end
33
- end
34
-
35
- end
36
- end
37
- end
38
-
@@ -1,47 +0,0 @@
1
- module PulseMeter
2
- module Visualize
3
- module Widgets
4
- class Gauge < PulseMeter::Visualize::Widget
5
- class NotAnIndicatorSensorInGaugeWidget < PulseMeter::Visualize::Error; end
6
-
7
- def data(options = {})
8
- super().merge({
9
- series: values_data
10
- })
11
- end
12
-
13
- protected
14
-
15
- def ensure_gauge_indicators!
16
- sensors.each do |s|
17
- unless s.type <= PulseMeter::Sensor::Indicator || s.type <= PulseMeter::Sensor::HashedIndicator
18
- raise NotAnIndicatorSensorInGaugeWidget, "Sensor #{s.name} is not an indicator(PulseMeter::Sensor::Indicator or PulseMeter::Sensor::HashedIndicator)"
19
- end
20
- end
21
- end
22
-
23
- def values_data
24
- ensure_gauge_indicators!
25
- gauges = []
26
- sensors.map do |s|
27
- s_type = s.type
28
- case
29
- when s_type == PulseMeter::Sensor::Indicator
30
- gauges << [s.annotation, s.value]
31
- when s_type == PulseMeter::Sensor::HashedIndicator
32
- s.value.each_pair do |k, v|
33
- gauge_title = "#{s.annotation}: #{k}"
34
- gauges << [gauge_title, v]
35
- end
36
- end
37
- end
38
- gauges
39
- end
40
-
41
- end
42
- end
43
-
44
- end
45
- end
46
-
47
-
@@ -1,36 +0,0 @@
1
- module PulseMeter
2
- module Visualize
3
- module Widgets
4
- class Pie < PulseMeter::Visualize::Widget
5
-
6
- def data(options = {})
7
- super().merge({
8
- series: slice_data
9
- })
10
- end
11
-
12
- protected
13
-
14
- def slice_data
15
- values = []
16
- slice_options = []
17
- now = Time.now
18
- sensors.each do |s|
19
- s.last_point_data(now, show_last_point).each do |point_data|
20
- values << [point_data[:name], point_data[:y]]
21
- slice_options << {color: point_data[:color]}
22
- end
23
- end
24
- {
25
- data: values,
26
- options: slice_options
27
- }
28
- end
29
-
30
- end
31
- end
32
-
33
- end
34
- end
35
-
36
-
@@ -1,114 +0,0 @@
1
- module PulseMeter
2
- module Visualize
3
- module Widgets
4
- class Error < StandardError; end
5
- class Timeline < PulseMeter::Visualize::Widget
6
-
7
- class NotATimelinedSensorInWidget < PulseMeter::Visualize::Error; end
8
- class DifferentSensorIntervalsInWidget < PulseMeter::Visualize::Error; end
9
-
10
- DEFAULT_TIMESPAN = 3600
11
-
12
- def initialize(opts)
13
- super
14
- opts[:timespan] ||= DEFAULT_TIMESPAN
15
- end
16
-
17
- def data(options = {})
18
- from, till = get_interval_borders(options)
19
- super().merge({
20
- values_title: values_label,
21
- series: series_data(from, till),
22
- timespan: timespan,
23
- interval: interval
24
- })
25
- end
26
-
27
- protected
28
-
29
- def get_interval_borders(options)
30
- from = if options[:start_time] && (options[:start_time] > 0)
31
- Time.at options[:start_time]
32
- else
33
- tspan = options[:timespan] || timespan
34
- Time.now - tspan
35
- end
36
-
37
- till = if options[:end_time] && (options[:end_time] > 0)
38
- Time.at options[:end_time]
39
- else
40
- Time.now
41
- end
42
- [from, till]
43
- end
44
-
45
- def series_data(from, till)
46
- ensure_equal_intervals!
47
- sensor_datas = sensors.map{ |s|
48
- s.timeline_data(from, till, show_last_point)
49
- }
50
- rows = []
51
- titles = []
52
- series_options = []
53
- datas = []
54
- sensor_datas.each do |sensor_data|
55
- sensor_data.each do |tl|
56
- titles << tl[:name]
57
- series_options << {color: tl[:color]}
58
- datas << tl[:data]
59
- end
60
- end
61
- unless datas.empty?
62
- first = datas.shift
63
- first.each_with_index do |tl_data, row_num|
64
- rows << datas.each_with_object([tl_data[:x], tl_data[:y]]) do |data_col, row|
65
- row << data_col[row_num][:y]
66
- end
67
- end
68
- end
69
- {
70
- titles: titles,
71
- rows: rows,
72
- options: series_options
73
- }
74
- end
75
-
76
- def ensure_equal_intervals!
77
- intervals = []
78
- sensors.each do |s|
79
- unless s.type < PulseMeter::Sensor::Timeline
80
- raise NotATimelinedSensorInWidget, "sensor `#{s.name}' is not timelined"
81
- end
82
- intervals << s.interval
83
- end
84
-
85
- unless intervals.all?{|i| i == intervals.first}
86
- interval_notice = sensors.map{|s| "#{s.name}: #{s.interval}"}.join(', ')
87
- raise DifferentSensorIntervalsInWidget, "Sensors with different intervals in a single widget: #{interval_notice}"
88
- end
89
- end
90
-
91
- def interval
92
- if sensors.empty?
93
- nil
94
- else
95
- sensors.first.interval
96
- end
97
- end
98
-
99
- end
100
-
101
- class Area < Timeline; end
102
- class Line < Timeline; end
103
-
104
- class Table < Timeline
105
- def data(options = {})
106
- res = super(options)
107
- res[:series].delete(options)
108
- res
109
- end
110
- end
111
- end
112
- end
113
- end
114
-
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::CommandAggregator::Async do
4
- let(:ca){PulseMeter.command_aggregator}
5
- let(:redis){PulseMeter.redis}
6
-
7
- describe "#multi" do
8
- it "should accumulate redis command and execute in a bulk" do
9
- ca.multi do
10
- ca.set("xxxx", "zzzz")
11
- ca.set("yyyy", "zzzz")
12
- sleep 0.1
13
- redis.get("xxxx").should be_nil
14
- redis.get("yyyy").should be_nil
15
- end
16
- ca.wait_for_pending_events
17
- redis.get("xxxx").should == "zzzz"
18
- redis.get("yyyy").should == "zzzz"
19
- end
20
- end
21
-
22
- describe "any other redis instance method" do
23
- it "should be delegated to redis" do
24
- ca.set("xxxx", "zzzz")
25
- ca.wait_for_pending_events
26
- redis.get("xxxx").should == "zzzz"
27
- end
28
-
29
- it "should be aggregated if queue is not overflooded" do
30
- redis.set("x", 0)
31
- ca.max_queue_length.times{ ca.incr("x") }
32
- ca.wait_for_pending_events
33
- redis.get("x").to_i.should == ca.max_queue_length
34
- end
35
-
36
- it "should not be aggregated if queue is overflooded" do
37
- redis.set("x", 0)
38
- (ca.max_queue_length * 2).times{ ca.incr("x") }
39
- ca.wait_for_pending_events
40
- redis.get("x").to_i.should < 2 * ca.max_queue_length
41
- end
42
- end
43
-
44
- describe "#wait_for_pending_events" do
45
- it "should pause execution until aggregator thread sends all commands ro redis" do
46
- ca.set("xxxx", "zzzz")
47
- redis.get("xxxx").should be_nil
48
- ca.wait_for_pending_events
49
- redis.get("xxxx").should == "zzzz"
50
- end
51
- end
52
-
53
- end
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::CommandAggregator::Sync do
4
- let(:ca){described_class.instance}
5
- let(:redis){PulseMeter.redis}
6
-
7
- describe "#multi" do
8
- it "should accumulate redis command and execute in a bulk" do
9
- ca.multi do
10
- ca.set("xxxx", "zzzz").should == "QUEUED"
11
- ca.set("yyyy", "zzzz").should == "QUEUED"
12
- end
13
- redis.get("xxxx").should == "zzzz"
14
- redis.get("yyyy").should == "zzzz"
15
- end
16
- end
17
-
18
- describe "any other redis instance method" do
19
- it "should be delegated to redis" do
20
- ca.set("xxxx", "zzzz")
21
- redis.get("xxxx").should == "zzzz"
22
- end
23
- end
24
- end
25
-
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe PulseMeter::CommandAggregator::UDP do
4
- let(:host){'127.0.0.1'}
5
- let(:port){33333}
6
- let(:udp_sock){mock(:socket)}
7
- before do
8
- UDPSocket.stub!(:new).and_return(udp_sock)
9
- udp_sock.stub!(:fcntl).and_return(nil)
10
- @ca = described_class.new([[host, port]])
11
- end
12
-
13
- describe "#multi" do
14
- it "should accumulate redis commands and send them in a bulk" do
15
- data = [
16
- ["set", "xxxx", "zzzz"],
17
- ["set", "yyyy", "zzzz"]
18
- ].to_json
19
- udp_sock.should_receive(:send).with(data, 0, host, port).and_return(0)
20
- @ca.multi do
21
- @ca.set("xxxx", "zzzz")
22
- @ca.set("yyyy", "zzzz")
23
- end
24
- end
25
-
26
- it "should ignore standard exceptions" do
27
- udp_sock.should_receive(:send).and_raise(StandardError)
28
- @ca.multi do
29
- @ca.set("xxxx", "zzzz")
30
- end
31
- end
32
- end
33
-
34
- describe "any other redis instance method" do
35
- it "should send data imediately" do
36
- data = [
37
- ["set", "xxxx", "zzzz"]
38
- ].to_json
39
- udp_sock.should_receive(:send).with(data, 0, host, port).and_return(0)
40
- @ca.set("xxxx", "zzzz")
41
- end
42
- end
43
-
44
- end
45
-
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
- require 'pulse-meter/extensions/enumerable'
3
-
4
- describe Enumerable do
5
- let!(:time) {Time.new}
6
- describe "#convert_time" do
7
- it "converts Time objects to unixtime" do
8
- [time].convert_time.should == [time.to_i]
9
- end
10
-
11
- it "does not change other members" do
12
- [1, 2, 3].convert_time.should == [1, 2 ,3]
13
- end
14
- end
15
-
16
- describe "#to_table" do
17
- context "when format is csv" do
18
- it "returns csv as string" do
19
- [].to_table(:csv).should be_instance_of(String)
20
- end
21
-
22
- it "returns csv containing each subarray as a row" do
23
- [[:a, :b], [:c, :d]].to_table(:csv).should == "a;b\nc;d\n"
24
- end
25
-
26
- it "converts Time objects to unixtime" do
27
- [[time]].to_table(:csv).should == "#{time.to_i}\n"
28
- end
29
-
30
- it "takes format argument both as string and as symbol" do
31
- [[:foo]].to_table("csv").should == "foo\n"
32
- [[:foo]].to_table(:csv).should == "foo\n"
33
- end
34
- end
35
-
36
- context "when format is table" do
37
- it "return Terminal::Table instance" do
38
- [].to_table.should be_instance_of(Terminal::Table)
39
- end
40
-
41
- it "returns table containing each subarray as a row" do
42
- data = [[:a, :b], [:c, :d]]
43
- table = [[:a, :b], [:c, :d]].to_table
44
- table.rows.map do |row|
45
- row.cells.map(&:to_s).map(&:strip).map(&:to_sym)
46
- end.should == data
47
- end
48
- end
49
-
50
- it "uses table format as default" do
51
- [].to_table.should be_instance_of(Terminal::Table)
52
- end
53
-
54
- it "uses table format unless it is :csv or 'csv'" do
55
- [].to_table(:unknown_format).should be_instance_of(Terminal::Table)
56
- end
57
- end
58
- end