diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/autoload.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/cache.rb | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/orchestra.rb (renamed from activesupport/lib/active_support/notifications.rb) | 16 | ||||
-rw-r--r-- | activesupport/test/orchestra_test.rb (renamed from activesupport/test/notifications_test.rb) | 60 |
4 files changed, 40 insertions, 40 deletions
diff --git a/activesupport/lib/active_support/autoload.rb b/activesupport/lib/active_support/autoload.rb index da12ecceca..a0fc2bb123 100644 --- a/activesupport/lib/active_support/autoload.rb +++ b/activesupport/lib/active_support/autoload.rb @@ -17,7 +17,7 @@ module ActiveSupport autoload :MessageVerifier, 'active_support/message_verifier' autoload :Multibyte, 'active_support/multibyte' autoload :OptionMerger, 'active_support/option_merger' - autoload :Notifications, 'active_support/notifications' + autoload :Orchestra, 'active_support/orchestra' autoload :OrderedHash, 'active_support/ordered_hash' autoload :OrderedOptions, 'active_support/ordered_options' autoload :Rescuable, 'active_support/rescuable' diff --git a/activesupport/lib/active_support/cache.rb b/activesupport/lib/active_support/cache.rb index e0f671f283..a415686020 100644 --- a/activesupport/lib/active_support/cache.rb +++ b/activesupport/lib/active_support/cache.rb @@ -247,7 +247,7 @@ module ActiveSupport payload = { :key => key } payload.merge!(options) if options.is_a?(Hash) - event = ActiveSupport::Notifications.instrument(:"cache_#{operation}", payload, &block) + event = ActiveSupport::Orchestra.instrument(:"cache_#{operation}", payload, &block) log("#{operation} (%.1fms)" % event.duration, key, options) event.result end diff --git a/activesupport/lib/active_support/notifications.rb b/activesupport/lib/active_support/orchestra.rb index 6335686196..efe30669d8 100644 --- a/activesupport/lib/active_support/notifications.rb +++ b/activesupport/lib/active_support/orchestra.rb @@ -1,10 +1,10 @@ require 'thread' module ActiveSupport - # Notifications provides an instrumentation API for Ruby. To instrument an action + # Orchestra provides an instrumentation API for Ruby. To instrument an action # in Ruby you just need to: # - # ActiveSupport::Notifications.instrument(:render, :extra => :information) do + # ActiveSupport::Orchestra.instrument(:render, :extra => :information) do # render :text => "Foo" # end # @@ -12,23 +12,23 @@ module ActiveSupport # to push. You can even register an array: # # @listener = [] - # ActiveSupport::Notifications.register @listener + # ActiveSupport::Orchestra.register @listener # - # ActiveSupport::Notifications.instrument(:render, :extra => :information) do + # ActiveSupport::Orchestra.instrument(:render, :extra => :information) do # render :text => "Foo" # end # - # event #=> ActiveSupport::Notifications::Event + # event #=> ActiveSupport::Orchestra::Event # event.name #=> :render # event.duration #=> 10 (in miliseconds) # event.result #=> "Foo" # event.payload #=> { :extra => :information } # - # Notifications ships with a default listener implementation which puts events in + # Orchestra ships with a default listener implementation which puts events in # a stream and consume them in a Thread. This implementation is thread safe - # and is available at ActiveSupport::Notifications::Listener. + # and is available at ActiveSupport::Orchestra::Listener. # - module Notifications + module Orchestra @stacked_events = Hash.new { |h,k| h[k] = [] } @listeners = [] diff --git a/activesupport/test/notifications_test.rb b/activesupport/test/orchestra_test.rb index 8f00eff106..683cc36f6a 100644 --- a/activesupport/test/notifications_test.rb +++ b/activesupport/test/orchestra_test.rb @@ -1,59 +1,59 @@ require 'abstract_unit' -class NotificationsEventTest < Test::Unit::TestCase +class OrchestraEventTest < Test::Unit::TestCase def setup - @parent = ActiveSupport::Notifications::Event.new(:parent) + @parent = ActiveSupport::Orchestra::Event.new(:parent) end def test_initialization_with_name_and_parent_and_payload - event = ActiveSupport::Notifications::Event.new(:awesome, @parent, :payload => "notifications") + event = ActiveSupport::Orchestra::Event.new(:awesome, @parent, :payload => "orchestra") assert_equal(:awesome, event.name) assert_equal(@parent, event.parent) - assert_equal({ :payload => "notifications" }, event.payload) + assert_equal({ :payload => "orchestra" }, event.payload) end def test_thread_id_is_set_on_initialization - event = ActiveSupport::Notifications::Event.new(:awesome) + event = ActiveSupport::Orchestra::Event.new(:awesome) assert_equal Thread.current.object_id, event.thread_id end def test_current_time_is_set_on_initialization previous_time = Time.now.utc - event = ActiveSupport::Notifications::Event.new(:awesome) + event = ActiveSupport::Orchestra::Event.new(:awesome) assert_kind_of Time, event.time assert event.time.to_f >= previous_time.to_f end - + def test_duration_is_set_when_event_finishes - event = ActiveSupport::Notifications::Event.new(:awesome) + event = ActiveSupport::Orchestra::Event.new(:awesome) sleep(0.1) event.finish! assert_in_delta 100, event.duration, 30 end end -class NotificationsMainTest < Test::Unit::TestCase +class OrchestraMainTest < Test::Unit::TestCase def setup @listener = [] - ActiveSupport::Notifications.register @listener + ActiveSupport::Orchestra.register @listener end def teardown - ActiveSupport::Notifications.unregister @listener + ActiveSupport::Orchestra.unregister @listener end - def test_notifications_allows_any_action_to_be_instrumented - event = ActiveSupport::Notifications.instrument(:awesome, "notifications") do + def test_orchestra_allows_any_action_to_be_instrumented + event = ActiveSupport::Orchestra.instrument(:awesome, "orchestra") do sleep(0.1) end assert_equal :awesome, event.name - assert_equal "notifications", event.payload + assert_equal "orchestra", event.payload assert_in_delta 100, event.duration, 30 end def test_block_result_is_stored - event = ActiveSupport::Notifications.instrument(:awesome, "notifications") do + event = ActiveSupport::Orchestra.instrument(:awesome, "orchestra") do 1 + 1 end @@ -61,18 +61,18 @@ class NotificationsMainTest < Test::Unit::TestCase end def test_events_are_published_to_a_listener - event = ActiveSupport::Notifications.instrument(:awesome, "notifications") do + event = ActiveSupport::Orchestra.instrument(:awesome, "orchestra") do 1 + 1 end assert_equal 1, @listener.size assert_equal :awesome, @listener.last.name - assert_equal "notifications", @listener.last.payload + assert_equal "orchestra", @listener.last.payload end def test_nested_events_can_be_instrumented - ActiveSupport::Notifications.instrument(:awesome, "notifications") do - ActiveSupport::Notifications.instrument(:wot, "child") do + ActiveSupport::Orchestra.instrument(:awesome, "orchestra") do + ActiveSupport::Orchestra.instrument(:wot, "child") do sleep(0.1) end @@ -86,23 +86,23 @@ class NotificationsMainTest < Test::Unit::TestCase assert_equal 2, @listener.size assert_equal :awesome, @listener.last.name - assert_equal "notifications", @listener.last.payload + assert_equal "orchestra", @listener.last.payload assert_in_delta 100, @listener.first.parent.duration, 30 end def test_event_is_pushed_even_if_block_fails - ActiveSupport::Notifications.instrument(:awesome, "notifications") do + ActiveSupport::Orchestra.instrument(:awesome, "orchestra") do raise "OMG" end rescue RuntimeError assert_equal 1, @listener.size assert_equal :awesome, @listener.last.name - assert_equal "notifications", @listener.last.payload + assert_equal "orchestra", @listener.last.payload end end -class NotificationsListenerTest < Test::Unit::TestCase - class MyListener < ActiveSupport::Notifications::Listener +class OrchestraListenerTest < Test::Unit::TestCase + class MyListener < ActiveSupport::Orchestra::Listener attr_reader :consumed def consume(event) @@ -113,11 +113,11 @@ class NotificationsListenerTest < Test::Unit::TestCase def setup @listener = MyListener.new - ActiveSupport::Notifications.register @listener + ActiveSupport::Orchestra.register @listener end def teardown - ActiveSupport::Notifications.unregister @listener + ActiveSupport::Orchestra.unregister @listener end def test_thread_is_exposed_by_listener @@ -125,7 +125,7 @@ class NotificationsListenerTest < Test::Unit::TestCase end def test_event_is_consumed_when_an_action_is_instrumented - ActiveSupport::Notifications.instrument(:sum) do + ActiveSupport::Orchestra.instrument(:sum) do 1 + 1 end sleep 0.1 @@ -136,10 +136,10 @@ class NotificationsListenerTest < Test::Unit::TestCase def test_with_sevaral_consumers_and_several_events @another = MyListener.new - ActiveSupport::Notifications.register @another + ActiveSupport::Orchestra.register @another 1.upto(100) do |i| - ActiveSupport::Notifications.instrument(:value) do + ActiveSupport::Orchestra.instrument(:value) do i end end @@ -156,6 +156,6 @@ class NotificationsListenerTest < Test::Unit::TestCase assert_equal 1, @another.consumed.first.result assert_equal 100, @another.consumed.last.result ensure - ActiveSupport::Notifications.unregister @another + ActiveSupport::Orchestra.unregister @another end end |