chillout 0.8.2 → 0.8.3

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -5
  3. data/CHANGELOG.md +7 -0
  4. data/lib/chillout/client.rb +12 -9
  5. data/lib/chillout/config.rb +21 -3
  6. data/lib/chillout/creations_container.rb +26 -0
  7. data/lib/chillout/job.rb +3 -3
  8. data/lib/chillout/railtie.rb +21 -4
  9. data/lib/chillout/server_side/dispatcher.rb +2 -2
  10. data/lib/chillout/server_side/server_side.rb +12 -11
  11. data/lib/chillout/subscribers/action_controller_notifications.rb +49 -0
  12. data/lib/chillout/version.rb +1 -1
  13. data/lib/chillout/worker.rb +13 -10
  14. data/lib/chillout.rb +1 -0
  15. data/test/acceptance/client_sends_controller_performance_test.rb +33 -0
  16. data/test/acceptance/client_sends_metrics_test.rb +5 -3
  17. data/test/client_test.rb +14 -1
  18. data/test/config_test.rb +14 -0
  19. data/test/creations_container_test.rb +48 -1
  20. data/test/dispatcher_test.rb +4 -4
  21. data/test/integration/creations_monitor_rack_test.rb +3 -3
  22. data/test/server_side_test.rb +0 -12
  23. data/test/subscribers/action_controller_notifications_test.rb +48 -0
  24. data/test/support/rails_4_0_0/config/environments/production.rb +7 -1
  25. data/test/support/rails_4_0_13/config/environments/production.rb +7 -1
  26. data/test/support/rails_4_1_0/config/environments/production.rb +7 -1
  27. data/test/support/rails_4_1_16/config/environments/production.rb +7 -1
  28. data/test/support/rails_4_2_0/config/environments/production.rb +1 -0
  29. data/test/test_helper.rb +18 -2
  30. data/test/worker_test.rb +43 -18
  31. metadata +7 -77
  32. data/lib/chillout/event_data_builder.rb +0 -34
  33. data/test/event_data_builder_test.rb +0 -90
  34. data/test/support/rails_3_2_13/Gemfile +0 -5
  35. data/test/support/rails_3_2_13/Rakefile +0 -7
  36. data/test/support/rails_3_2_13/app/controllers/application_controller.rb +0 -3
  37. data/test/support/rails_3_2_13/app/controllers/entities_controller.rb +0 -70
  38. data/test/support/rails_3_2_13/app/helpers/application_helper.rb +0 -2
  39. data/test/support/rails_3_2_13/app/models/entity.rb +0 -3
  40. data/test/support/rails_3_2_13/app/views/entities/_form.html.erb +0 -21
  41. data/test/support/rails_3_2_13/app/views/entities/edit.html.erb +0 -6
  42. data/test/support/rails_3_2_13/app/views/entities/index.html.erb +0 -23
  43. data/test/support/rails_3_2_13/app/views/entities/new.html.erb +0 -5
  44. data/test/support/rails_3_2_13/app/views/entities/show.html.erb +0 -10
  45. data/test/support/rails_3_2_13/app/views/layouts/application.html.erb +0 -14
  46. data/test/support/rails_3_2_13/config/application.rb +0 -63
  47. data/test/support/rails_3_2_13/config/boot.rb +0 -6
  48. data/test/support/rails_3_2_13/config/database.yml +0 -11
  49. data/test/support/rails_3_2_13/config/environment.rb +0 -5
  50. data/test/support/rails_3_2_13/config/environments/development.rb +0 -32
  51. data/test/support/rails_3_2_13/config/environments/production.rb +0 -56
  52. data/test/support/rails_3_2_13/config/environments/test.rb +0 -37
  53. data/test/support/rails_3_2_13/config/initializers/backtrace_silencers.rb +0 -7
  54. data/test/support/rails_3_2_13/config/initializers/inflections.rb +0 -15
  55. data/test/support/rails_3_2_13/config/initializers/load_schema.rb +0 -4
  56. data/test/support/rails_3_2_13/config/initializers/mime_types.rb +0 -5
  57. data/test/support/rails_3_2_13/config/initializers/secret_token.rb +0 -7
  58. data/test/support/rails_3_2_13/config/initializers/session_store.rb +0 -8
  59. data/test/support/rails_3_2_13/config/initializers/wrap_parameters.rb +0 -14
  60. data/test/support/rails_3_2_13/config/locales/en.yml +0 -5
  61. data/test/support/rails_3_2_13/config/routes.rb +0 -3
  62. data/test/support/rails_3_2_13/config.ru +0 -4
  63. data/test/support/rails_3_2_13/db/schema.rb +0 -22
  64. data/test/support/rails_3_2_13/public/404.html +0 -26
  65. data/test/support/rails_3_2_13/public/422.html +0 -26
  66. data/test/support/rails_3_2_13/public/500.html +0 -25
  67. data/test/support/rails_3_2_13/public/favicon.ico +0 -0
  68. data/test/support/rails_3_2_13/public/robots.txt +0 -5
  69. data/test/support/rails_3_2_13/script/rails +0 -6
@@ -0,0 +1,48 @@
1
+ require 'test_helper'
2
+ require 'active_job'
3
+ require 'active_job/test_helper'
4
+
5
+ module Chillout
6
+ module Subscribers
7
+ class ActionControllerNotificationsTest < ChilloutTestCase
8
+ include ActiveJob::TestHelper
9
+
10
+ def test_as_measurements
11
+ time = Time.utc(2017, 6, 27, 10, 26, 33)
12
+ metric = ActionControllerNotifications::RequestMetric.new(
13
+ ActiveSupport::Notifications::Event.new(
14
+ "asd", time, time+1, "uniq", {
15
+ controller: "PostsController",
16
+ action: "index",
17
+ params: {"action" => "index", "controller" => "posts"},
18
+ headers: nil, #ActionDispatch::Http::Headers.new,
19
+ format: :html,
20
+ method: "GET",
21
+ path: "/posts",
22
+ status: 200,
23
+ view_runtime: 46.848,
24
+ db_runtime: 0.157
25
+ }
26
+ ))
27
+
28
+ assert_equal [{
29
+ timestamp: "2017-06-27T10:26:34Z",
30
+ series: "request",
31
+ tags: {
32
+ controller: "PostsController",
33
+ action: "index",
34
+ format: "html",
35
+ method: "GET",
36
+ status: 200,
37
+ },
38
+ values: {
39
+ finished: 1,
40
+ duration: 1000.000,
41
+ db: 0.157,
42
+ view: 46.848,
43
+ },
44
+ }], metric.as_measurements
45
+ end
46
+ end
47
+ end
48
+ end
@@ -63,5 +63,11 @@ Rails400::Application.configure do
63
63
  # Use default logging formatter so that PID and timestamp are not suppressed.
64
64
  config.log_formatter = ::Logger::Formatter.new
65
65
 
66
- config.chillout = { secret: 'secret', ssl: false, port: 8080, hostname: 'localhost' }
66
+ config.chillout = {
67
+ secret: 'secret',
68
+ ssl: false,
69
+ port: (ENV['CHILLOUT_PORT'] || 8080).to_i,
70
+ hostname: 'localhost',
71
+ strategy: (ENV['STRATEGY'] || :thread).to_sym,
72
+ }
67
73
  end
@@ -63,5 +63,11 @@ Rails400::Application.configure do
63
63
  # Use default logging formatter so that PID and timestamp are not suppressed.
64
64
  config.log_formatter = ::Logger::Formatter.new
65
65
 
66
- config.chillout = { secret: 'secret', ssl: false, port: 8080, hostname: 'localhost' }
66
+ config.chillout = {
67
+ secret: 'secret',
68
+ ssl: false,
69
+ port: (ENV['CHILLOUT_PORT'] || 8080).to_i,
70
+ hostname: 'localhost',
71
+ strategy: (ENV['STRATEGY'] || :thread).to_sym,
72
+ }
67
73
  end
@@ -63,5 +63,11 @@ Rails400::Application.configure do
63
63
  # Use default logging formatter so that PID and timestamp are not suppressed.
64
64
  config.log_formatter = ::Logger::Formatter.new
65
65
 
66
- config.chillout = { secret: 'secret', ssl: false, port: 8080, hostname: 'localhost' }
66
+ config.chillout = {
67
+ secret: 'secret',
68
+ ssl: false,
69
+ port: (ENV['CHILLOUT_PORT'] || 8080).to_i,
70
+ hostname: 'localhost',
71
+ strategy: (ENV['STRATEGY'] || :thread).to_sym,
72
+ }
67
73
  end
@@ -63,5 +63,11 @@ Rails400::Application.configure do
63
63
  # Use default logging formatter so that PID and timestamp are not suppressed.
64
64
  config.log_formatter = ::Logger::Formatter.new
65
65
 
66
- config.chillout = { secret: 'secret', ssl: false, port: 8080, hostname: 'localhost' }
66
+ config.chillout = {
67
+ secret: 'secret',
68
+ ssl: false,
69
+ port: (ENV['CHILLOUT_PORT'] || 8080).to_i,
70
+ hostname: 'localhost',
71
+ strategy: (ENV['STRATEGY'] || :thread).to_sym,
72
+ }
67
73
  end
@@ -68,5 +68,6 @@ Rails400::Application.configure do
68
68
  ssl: false,
69
69
  port: (ENV['CHILLOUT_PORT'] || 8080).to_i,
70
70
  hostname: 'localhost',
71
+ strategy: (ENV['STRATEGY'] || :thread).to_sym,
71
72
  }
72
73
  end
data/test/test_helper.rb CHANGED
@@ -71,7 +71,7 @@ end
71
71
 
72
72
  class TestApp
73
73
 
74
- def boot
74
+ def boot(chillout_port:)
75
75
  sample_app_name = ENV['SAMPLE_APP'] || 'rails_4_0_0'
76
76
  sample_app_root = Pathname.new(File.expand_path('../support', __FILE__)).join(sample_app_name)
77
77
  command = [Gem.ruby, sample_app_root.join('script/rails').to_s, 'server'].join(' ')
@@ -79,6 +79,7 @@ class TestApp
79
79
  process.cwd = sample_app_root.to_s
80
80
  process.environment['BUNDLE_GEMFILE'] = sample_app_root.join('Gemfile').to_s
81
81
  process.environment['RAILS_ENV'] = 'production'
82
+ process.environment['CHILLOUT_PORT'] = chillout_port.to_s
82
83
  end
83
84
  @executor = Bbq::Spawn::CoordinatedExecutor.new(@executor, :url => 'http://127.0.0.1:3000/', timeout: 15)
84
85
  @executor.start
@@ -177,7 +178,22 @@ class TestEndpoint
177
178
  def has_one_creation_for_entity_resource
178
179
  10.times do
179
180
  begin
180
- return metrics.pop(true)
181
+ many = metrics.pop(true)
182
+ metric = many["measurements"].find{|m| m["series"] == "Entity" }
183
+ return metric if metric
184
+ rescue ThreadError
185
+ sleep(1)
186
+ end
187
+ end
188
+ false
189
+ end
190
+
191
+ def has_one_controller_metric
192
+ 10.times do
193
+ begin
194
+ many = metrics.pop(true)
195
+ metric = many["measurements"].find{|m| m["series"] == "request" }
196
+ return metric if metric
181
197
  rescue ThreadError
182
198
  sleep(1)
183
199
  end
data/test/worker_test.rb CHANGED
@@ -8,33 +8,58 @@ module Chillout
8
8
  @container = stub
9
9
  @logger = stub(info: "", error:"", debug: "")
10
10
  @container_class = stub(:new => @container)
11
- @worker = Worker.new(@dispatcher, @queue, @logger, @container_class)
11
+ @max_queue = 50
12
+ @worker = Worker.new(@max_queue, @dispatcher, @queue, @logger, @container_class)
12
13
  end
13
14
 
14
15
  def test_get_all_containers_to_process_pops_all_existings_jobs_from_queue
15
16
  @queue.expects(:pop).times(3).returns(:container1, :container2).then.raises(ThreadError)
16
- all_jobs = @worker.get_all_containers_to_process
17
- assert_equal 2, all_jobs.count
18
- assert_includes all_jobs, :container1
19
- assert_includes all_jobs, :container2
17
+ assert_equal [:container1, :container2], @worker.get_all_containers_to_process
20
18
  end
21
19
 
22
- def test_merge_containers_to_one
23
- @container.expects(:merge).with(:container1)
24
- @container.expects(:merge).with(:container2)
25
- result = @worker.merge_containers([:container1, :container2])
26
- assert_equal @container, result
20
+ def test_does_not_pop_containers_infinitely
21
+ @queue.expects(:pop).returns(:bip).times(@max_queue)
22
+ assert_equal [:bip]*@max_queue, @worker.get_all_containers_to_process
27
23
  end
28
24
 
29
- def test_send_creations_just_send_creations_with_dispatcher
30
- @dispatcher.expects(:send_creations).with(:creations_container)
31
- @worker.send_creations(:creations_container)
25
+ def test_merge_heterogeneous_containers
26
+ @worker = Worker.new(@max_queue, @dispatcher, @queue, @logger, CreationsContainer)
27
+
28
+ result = @worker.merge_containers([
29
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 2); },
30
+ nil,
31
+ other = Object.new,
32
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 3); },
33
+ 1,
34
+ ])
35
+ assert_equal [
36
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 5); },
37
+ nil,
38
+ other,
39
+ 1
40
+ ], result
41
+ end
42
+
43
+ def test_merge_homogeneous_containers
44
+ @worker = Worker.new(@max_queue, @dispatcher, @queue, @logger, CreationsContainer)
45
+
46
+ result = @worker.merge_containers([
47
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 2); },
48
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 3); },
49
+ ])
50
+ assert_equal [
51
+ CreationsContainer.new.tap{|cc| cc.increment!("User", 5); },
52
+ ], result
53
+ end
54
+
55
+ def test_send_measurements_just_send_creations_with_dispatcher
56
+ @dispatcher.expects(:send_measurements).with(:creations_container)
57
+ @worker.send_measurements(:creations_container)
32
58
  end
33
59
 
34
- def test_send_creations_with_interuption
35
- @dispatcher.stubs(:send_creations).raises(Dispatcher::SendCreationsFailed)
36
- @queue.expects(:<<).with(:creations_container)
37
- @worker.send_creations(:creations_container)
60
+ def test_send_measurements_with_interuption
61
+ @dispatcher.stubs(:send_measurements).raises(Dispatcher::SendCreationsFailed)
62
+ @worker.send_measurements(:creations_container)
38
63
  end
39
64
 
40
65
  def test_send_startup_message_is_delegated_to_dispatcher
@@ -42,4 +67,4 @@ module Chillout
42
67
  @worker.send_startup_message
43
68
  end
44
69
  end
45
- end
70
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chillout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michal Lomnicki
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2017-06-26 00:00:00.000000000 Z
14
+ date: 2017-06-29 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: multi_json
@@ -207,7 +207,6 @@ files:
207
207
  - lib/chillout/creation_listener.rb
208
208
  - lib/chillout/creations_container.rb
209
209
  - lib/chillout/custom_metric.rb
210
- - lib/chillout/event_data_builder.rb
211
210
  - lib/chillout/generators/install.rb
212
211
  - lib/chillout/integrations/sidekiq.rb
213
212
  - lib/chillout/job.rb
@@ -221,9 +220,11 @@ files:
221
220
  - lib/chillout/server_side/http_client.rb
222
221
  - lib/chillout/server_side/plain_http_client.rb
223
222
  - lib/chillout/server_side/server_side.rb
223
+ - lib/chillout/subscribers/action_controller_notifications.rb
224
224
  - lib/chillout/tasks.rb
225
225
  - lib/chillout/version.rb
226
226
  - lib/chillout/worker.rb
227
+ - test/acceptance/client_sends_controller_performance_test.rb
227
228
  - test/acceptance/client_sends_metrics_test.rb
228
229
  - test/acceptance/sidekiq_workers_send_metrics_test.rb
229
230
  - test/check_result_test.rb
@@ -232,7 +233,6 @@ files:
232
233
  - test/creations_container_test.rb
233
234
  - test/custom_metric_test.rb
234
235
  - test/dispatcher_test.rb
235
- - test/event_data_builder_test.rb
236
236
  - test/http_client_test.rb
237
237
  - test/integration/client_test.rb
238
238
  - test/integration/creations_monitor_rack_test.rb
@@ -243,42 +243,7 @@ files:
243
243
  - test/prefixed_logger_test.rb
244
244
  - test/registration_test.rb
245
245
  - test/server_side_test.rb
246
- - test/support/rails_3_2_13/Gemfile
247
- - test/support/rails_3_2_13/Rakefile
248
- - test/support/rails_3_2_13/app/controllers/application_controller.rb
249
- - test/support/rails_3_2_13/app/controllers/entities_controller.rb
250
- - test/support/rails_3_2_13/app/helpers/application_helper.rb
251
- - test/support/rails_3_2_13/app/models/entity.rb
252
- - test/support/rails_3_2_13/app/views/entities/_form.html.erb
253
- - test/support/rails_3_2_13/app/views/entities/edit.html.erb
254
- - test/support/rails_3_2_13/app/views/entities/index.html.erb
255
- - test/support/rails_3_2_13/app/views/entities/new.html.erb
256
- - test/support/rails_3_2_13/app/views/entities/show.html.erb
257
- - test/support/rails_3_2_13/app/views/layouts/application.html.erb
258
- - test/support/rails_3_2_13/config.ru
259
- - test/support/rails_3_2_13/config/application.rb
260
- - test/support/rails_3_2_13/config/boot.rb
261
- - test/support/rails_3_2_13/config/database.yml
262
- - test/support/rails_3_2_13/config/environment.rb
263
- - test/support/rails_3_2_13/config/environments/development.rb
264
- - test/support/rails_3_2_13/config/environments/production.rb
265
- - test/support/rails_3_2_13/config/environments/test.rb
266
- - test/support/rails_3_2_13/config/initializers/backtrace_silencers.rb
267
- - test/support/rails_3_2_13/config/initializers/inflections.rb
268
- - test/support/rails_3_2_13/config/initializers/load_schema.rb
269
- - test/support/rails_3_2_13/config/initializers/mime_types.rb
270
- - test/support/rails_3_2_13/config/initializers/secret_token.rb
271
- - test/support/rails_3_2_13/config/initializers/session_store.rb
272
- - test/support/rails_3_2_13/config/initializers/wrap_parameters.rb
273
- - test/support/rails_3_2_13/config/locales/en.yml
274
- - test/support/rails_3_2_13/config/routes.rb
275
- - test/support/rails_3_2_13/db/schema.rb
276
- - test/support/rails_3_2_13/public/404.html
277
- - test/support/rails_3_2_13/public/422.html
278
- - test/support/rails_3_2_13/public/500.html
279
- - test/support/rails_3_2_13/public/favicon.ico
280
- - test/support/rails_3_2_13/public/robots.txt
281
- - test/support/rails_3_2_13/script/rails
246
+ - test/subscribers/action_controller_notifications_test.rb
282
247
  - test/support/rails_4_0_0/Gemfile
283
248
  - test/support/rails_4_0_0/Rakefile
284
249
  - test/support/rails_4_0_0/app/controllers/application_controller.rb
@@ -661,6 +626,7 @@ signing_key:
661
626
  specification_version: 4
662
627
  summary: Chillout.io Ruby client
663
628
  test_files:
629
+ - test/acceptance/client_sends_controller_performance_test.rb
664
630
  - test/acceptance/client_sends_metrics_test.rb
665
631
  - test/acceptance/sidekiq_workers_send_metrics_test.rb
666
632
  - test/check_result_test.rb
@@ -669,7 +635,6 @@ test_files:
669
635
  - test/creations_container_test.rb
670
636
  - test/custom_metric_test.rb
671
637
  - test/dispatcher_test.rb
672
- - test/event_data_builder_test.rb
673
638
  - test/http_client_test.rb
674
639
  - test/integration/client_test.rb
675
640
  - test/integration/creations_monitor_rack_test.rb
@@ -680,42 +645,7 @@ test_files:
680
645
  - test/prefixed_logger_test.rb
681
646
  - test/registration_test.rb
682
647
  - test/server_side_test.rb
683
- - test/support/rails_3_2_13/Gemfile
684
- - test/support/rails_3_2_13/Rakefile
685
- - test/support/rails_3_2_13/app/controllers/application_controller.rb
686
- - test/support/rails_3_2_13/app/controllers/entities_controller.rb
687
- - test/support/rails_3_2_13/app/helpers/application_helper.rb
688
- - test/support/rails_3_2_13/app/models/entity.rb
689
- - test/support/rails_3_2_13/app/views/entities/_form.html.erb
690
- - test/support/rails_3_2_13/app/views/entities/edit.html.erb
691
- - test/support/rails_3_2_13/app/views/entities/index.html.erb
692
- - test/support/rails_3_2_13/app/views/entities/new.html.erb
693
- - test/support/rails_3_2_13/app/views/entities/show.html.erb
694
- - test/support/rails_3_2_13/app/views/layouts/application.html.erb
695
- - test/support/rails_3_2_13/config.ru
696
- - test/support/rails_3_2_13/config/application.rb
697
- - test/support/rails_3_2_13/config/boot.rb
698
- - test/support/rails_3_2_13/config/database.yml
699
- - test/support/rails_3_2_13/config/environment.rb
700
- - test/support/rails_3_2_13/config/environments/development.rb
701
- - test/support/rails_3_2_13/config/environments/production.rb
702
- - test/support/rails_3_2_13/config/environments/test.rb
703
- - test/support/rails_3_2_13/config/initializers/backtrace_silencers.rb
704
- - test/support/rails_3_2_13/config/initializers/inflections.rb
705
- - test/support/rails_3_2_13/config/initializers/load_schema.rb
706
- - test/support/rails_3_2_13/config/initializers/mime_types.rb
707
- - test/support/rails_3_2_13/config/initializers/secret_token.rb
708
- - test/support/rails_3_2_13/config/initializers/session_store.rb
709
- - test/support/rails_3_2_13/config/initializers/wrap_parameters.rb
710
- - test/support/rails_3_2_13/config/locales/en.yml
711
- - test/support/rails_3_2_13/config/routes.rb
712
- - test/support/rails_3_2_13/db/schema.rb
713
- - test/support/rails_3_2_13/public/404.html
714
- - test/support/rails_3_2_13/public/422.html
715
- - test/support/rails_3_2_13/public/500.html
716
- - test/support/rails_3_2_13/public/favicon.ico
717
- - test/support/rails_3_2_13/public/robots.txt
718
- - test/support/rails_3_2_13/script/rails
648
+ - test/subscribers/action_controller_notifications_test.rb
719
649
  - test/support/rails_4_0_0/Gemfile
720
650
  - test/support/rails_4_0_0/Rakefile
721
651
  - test/support/rails_4_0_0/app/controllers/application_controller.rb
@@ -1,34 +0,0 @@
1
- module Chillout
2
- class EventDataBuilder
3
- def initialize(config)
4
- @config = config
5
- end
6
-
7
- def build_from_creations_container(creations_container, timestamp)
8
- {
9
- :metric => "creations",
10
- :timestamp => timestamp,
11
- :content => {
12
- :creations => build_creations_content(creations_container),
13
- :environment => @config.environment
14
- },
15
- :notifier => build_notifier
16
- }
17
- end
18
-
19
- def build_creations_content(creations_container)
20
- creation_tuples = creations_container.resource_keys.map do |key|
21
- [key, creations_container[key]]
22
- end
23
- Hash[creation_tuples]
24
- end
25
-
26
- def build_notifier
27
- {
28
- :name => @config.notifier_name,
29
- :version => @config.version,
30
- :url => @config.notifier_url
31
- }
32
- end
33
- end
34
- end
@@ -1,90 +0,0 @@
1
- require 'test_helper'
2
- require 'chillout/event_data_builder'
3
- require 'chillout/creations_container'
4
-
5
- module Chillout
6
- class EventDataBuilderTest < ChilloutTestCase
7
- def setup
8
- super
9
- @shell_env = { 'PATH' => '/bin:/usr/bin' }
10
- @api_key = "s3cr3t"
11
-
12
- @config = Config.new(@api_key)
13
- @config.platform = "rails"
14
- @config.environment = "development"
15
- @config.notifier_name = "chillout"
16
- @config.version = "0.1"
17
- @config.notifier_url = "http://github.com/arkency/chillout"
18
-
19
- @timestamp = Time.now.iso8601
20
- end
21
-
22
- def build_from_creations_container
23
- @creations_container = CreationsContainer.new
24
- 5.times { @creations_container.increment!("User") }
25
- 3.times { @creations_container.increment!("Cart") }
26
- 8.times { @creations_container.increment!("CartItem") }
27
-
28
- @event_data_builder = EventDataBuilder.new(@config)
29
- @event_data = @event_data_builder.build_from_creations_container(@creations_container, @timestamp)
30
- end
31
-
32
- def test_metric_type
33
- build_from_creations_container
34
- assert_param :metric, "creations"
35
- end
36
-
37
- def test_timestamp
38
- build_from_creations_container
39
- assert_param :timestamp, @timestamp
40
- end
41
-
42
- def test_each_counter
43
- build_from_creations_container
44
- assert_creations :User, 5
45
- assert_creations :Cart, 3
46
- assert_creations :CartItem, 8
47
- end
48
-
49
- def test_environment
50
- build_from_creations_container
51
- assert_content :environment, "development"
52
- end
53
-
54
- def test_notifier_name
55
- build_from_creations_container
56
- assert_notifier :name, "chillout"
57
- end
58
-
59
- def test_notifier_version
60
- build_from_creations_container
61
- assert_notifier :version, "0.1"
62
- end
63
-
64
- def test_notifier_url
65
- build_from_creations_container
66
- assert_notifier :url, "http://github.com/arkency/chillout"
67
- end
68
-
69
- private
70
- def event_data
71
- @event_data
72
- end
73
-
74
- def assert_param(key, value)
75
- assert_equal value, event_data[key]
76
- end
77
-
78
- def assert_content(key, value)
79
- assert_equal value, event_data[:content][key]
80
- end
81
-
82
- def assert_creations(key, value)
83
- assert_equal value, event_data[:content][:creations][key]
84
- end
85
-
86
- def assert_notifier(key, value)
87
- assert_equal value, event_data[:notifier][key]
88
- end
89
- end
90
- end
@@ -1,5 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'rails', '3.2.13'
4
- gem 'sqlite3'
5
- gem 'chillout', :path => '../../../'
@@ -1,7 +0,0 @@
1
- #!/usr/bin/env rake
2
- # Add your own tasks in files placed in lib/tasks ending in .rake,
3
- # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
-
5
- require File.expand_path('../config/application', __FILE__)
6
-
7
- Rails3213::Application.load_tasks
@@ -1,3 +0,0 @@
1
- class ApplicationController < ActionController::Base
2
- # protect_from_forgery
3
- end
@@ -1,70 +0,0 @@
1
- class EntitiesController < ApplicationController
2
- def index
3
- @entities = Entity.all
4
-
5
- respond_to do |format|
6
- format.html # index.html.erb
7
- format.json { render :json => @entities }
8
- end
9
- end
10
-
11
- def show
12
- @entity = Entity.find(params[:id])
13
-
14
- respond_to do |format|
15
- format.html # show.html.erb
16
- format.json { render :json => @entity }
17
- end
18
- end
19
-
20
- def new
21
- @entity = Entity.new
22
-
23
- respond_to do |format|
24
- format.html # new.html.erb
25
- format.json { render :json => @entity }
26
- end
27
- end
28
-
29
- def edit
30
- @entity = Entity.find(params[:id])
31
- end
32
-
33
- def create
34
- @entity = Entity.new(params[:entity])
35
-
36
- respond_to do |format|
37
- if @entity.save
38
- format.html { redirect_to @entity, :notice => 'Entity was successfully created.' }
39
- format.json { render :json => @entity, :status => :created, :location => @entity }
40
- else
41
- format.html { render :action => "new" }
42
- format.json { render :json => @entity.errors, :status => :unprocessable_entity }
43
- end
44
- end
45
- end
46
-
47
- def update
48
- @entity = Entity.find(params[:id])
49
-
50
- respond_to do |format|
51
- if @entity.update_attributes(params[:entity])
52
- format.html { redirect_to @entity, :notice => 'Entity was successfully updated.' }
53
- format.json { head :no_content }
54
- else
55
- format.html { render :action => "edit" }
56
- format.json { render :json => @entity.errors, :status => :unprocessable_entity }
57
- end
58
- end
59
- end
60
-
61
- def destroy
62
- @entity = Entity.find(params[:id])
63
- @entity.destroy
64
-
65
- respond_to do |format|
66
- format.html { redirect_to entities_url }
67
- format.json { head :no_content }
68
- end
69
- end
70
- end
@@ -1,2 +0,0 @@
1
- module ApplicationHelper
2
- end
@@ -1,3 +0,0 @@
1
- class Entity < ActiveRecord::Base
2
- attr_accessible :name
3
- end
@@ -1,21 +0,0 @@
1
- <%= form_for(@entity) do |f| %>
2
- <% if @entity.errors.any? %>
3
- <div id="error_explanation">
4
- <h2><%= pluralize(@entity.errors.count, "error") %> prohibited this entity from being saved:</h2>
5
-
6
- <ul>
7
- <% @entity.errors.full_messages.each do |msg| %>
8
- <li><%= msg %></li>
9
- <% end %>
10
- </ul>
11
- </div>
12
- <% end %>
13
-
14
- <div class="field">
15
- <%= f.label :name %><br />
16
- <%= f.text_field :name %>
17
- </div>
18
- <div class="actions">
19
- <%= f.submit %>
20
- </div>
21
- <% end %>
@@ -1,6 +0,0 @@
1
- <h1>Editing entity</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Show', @entity %> |
6
- <%= link_to 'Back', entities_path %>
@@ -1,23 +0,0 @@
1
- <h1>Listing entities</h1>
2
-
3
- <table>
4
- <tr>
5
- <th>Name</th>
6
- <th></th>
7
- <th></th>
8
- <th></th>
9
- </tr>
10
-
11
- <% @entities.each do |entity| %>
12
- <tr>
13
- <td><%= entity.name %></td>
14
- <td><%= link_to 'Show', entity %></td>
15
- <td><%= link_to 'Edit', edit_entity_path(entity) %></td>
16
- <td><%= link_to 'Destroy', entity, method: :delete, data: { confirm: 'Are you sure?' } %></td>
17
- </tr>
18
- <% end %>
19
- </table>
20
-
21
- <br />
22
-
23
- <%= link_to 'New Entity', new_entity_path %>
@@ -1,5 +0,0 @@
1
- <h1>New entity</h1>
2
-
3
- <%= render 'form' %>
4
-
5
- <%= link_to 'Back', entities_path %>