[Pkg-puppet-devel] [SCM] Puppet packaging for Debian branch, upstream, updated. 0.25.5-639-g8f94f35

test branch puppet-dev at googlegroups.com
Wed Jul 14 10:31:04 UTC 2010


The following commit has been merged in the upstream branch:
commit 68ce086e6b57f67998c52073109e0cca0aee7002
Author: Luke Kanies <luke at reductivelabs.com>
Date:   Mon Mar 22 16:31:42 2010 -0700

    Changing the method profile of EventManager#queue_event
    
    It now takes multiple events instead of just one.  This will
    help simplify a bunch of performance optimizations.
    
    Signed-off-by: Luke Kanies <luke at reductivelabs.com>

diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb
index 1b0c470..e7d8f63 100644
--- a/lib/puppet/transaction.rb
+++ b/lib/puppet/transaction.rb
@@ -42,9 +42,7 @@ class Puppet::Transaction
     def apply(resource)
         status = resource_harness.evaluate(resource)
         add_resource_status(status)
-        status.events.each do |event|
-            event_manager.queue_event(resource, event)
-        end
+        event_manager.queue_events(resource, status.events)
     rescue => detail
         resource.err "Could not evaluate: #{detail}"
     end
diff --git a/lib/puppet/transaction/event_manager.rb b/lib/puppet/transaction/event_manager.rb
index aacd17a..f74927b 100644
--- a/lib/puppet/transaction/event_manager.rb
+++ b/lib/puppet/transaction/event_manager.rb
@@ -22,7 +22,7 @@ class Puppet::Transaction::EventManager
         end
 
         if restarted
-            queue_event(resource, resource.event(:name => :restarted, :status => "success"))
+            queue_events(resource, [resource.event(:name => :restarted, :status => "success")])
 
             transaction.resource_status(resource).restarted = true
         end
@@ -30,21 +30,23 @@ class Puppet::Transaction::EventManager
 
     # Queue events for other resources to respond to.  All of these events have
     # to be from the same resource.
-    def queue_event(resource, event)
-        @events << event
-
-        # Collect the targets of any subscriptions to those events.  We pass
-        # the parent resource in so it will override the source in the events,
-        # since eval_generated children can't have direct relationships.
-        relationship_graph.matching_edges(event, resource).each do |edge|
-            next unless method = edge.callback
-            next unless edge.target.respond_to?(method)
-
-            queue_event_for_resource(resource, edge.target, method, event)
-        end
-
-        if resource.self_refresh? and ! resource.deleting?
-            queue_event_for_resource(resource, resource, :refresh, event)
+    def queue_events(resource, events)
+        @events += events
+
+        events.each do |event|
+            # Collect the targets of any subscriptions to those events.  We pass
+            # the parent resource in so it will override the source in the events,
+            # since eval_generated children can't have direct relationships.
+            relationship_graph.matching_edges(event, resource).each do |edge|
+                next unless method = edge.callback
+                next unless edge.target.respond_to?(method)
+
+                queue_event_for_resource(resource, edge.target, method, event)
+            end
+
+            if resource.self_refresh? and ! resource.deleting?
+                queue_event_for_resource(resource, resource, :refresh, event)
+            end
         end
     end
 
@@ -83,7 +85,7 @@ class Puppet::Transaction::EventManager
         resource.notice "Would have triggered '#{callback}' from #{events.length} events"
 
         # And then add an event for it.
-        queue_event(resource, resource.event(:status => "noop", :name => :noop_restart))
+        queue_events(resource, [resource.event(:status => "noop", :name => :noop_restart)])
         true # so the 'and if' works
     end
 end
diff --git a/spec/unit/transaction.rb b/spec/unit/transaction.rb
index f0c98db..2c8f605 100755
--- a/spec/unit/transaction.rb
+++ b/spec/unit/transaction.rb
@@ -146,7 +146,7 @@ describe Puppet::Transaction do
             @status = Puppet::Resource::Status.new(@resource)
 
             @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
-            @transaction.event_manager.stubs(:queue_event)
+            @transaction.event_manager.stubs(:queue_events)
             @transaction.resource_harness.stubs(:evaluate).returns(@status)
         end
 
@@ -162,8 +162,7 @@ describe Puppet::Transaction do
 
         it "should queue any events added to the resource status" do
             @status.expects(:events).returns %w{a b}
-            @transaction.event_manager.expects(:queue_event).with(@resource, "a")
-            @transaction.event_manager.expects(:queue_event).with(@resource, "b")
+            @transaction.event_manager.expects(:queue_events).with(@resource, ["a", "b"])
             @transaction.apply(@resource)
         end
 
diff --git a/spec/unit/transaction/event_manager.rb b/spec/unit/transaction/event_manager.rb
index 12407c3..f808377 100755
--- a/spec/unit/transaction/event_manager.rb
+++ b/spec/unit/transaction/event_manager.rb
@@ -32,10 +32,12 @@ describe Puppet::Transaction::EventManager do
             @event = Puppet::Transaction::Event.new(:name => :foo, :resource => @resource)
         end
 
-        it "should store each event in its event list" do
-            @manager.queue_event(@resource, @event)
+        it "should store all of the events in its event list" do
+            @event2 = Puppet::Transaction::Event.new(:name => :bar, :resource => @resource)
+            @manager.queue_events(@resource, [@event, @event2])
 
             @manager.events.should include(@event)
+            @manager.events.should include(@event2)
         end
 
         it "should queue events for the target and callback of any matching edges" do
@@ -47,7 +49,7 @@ describe Puppet::Transaction::EventManager do
             @manager.expects(:queue_event_for_resource).with(@resource, edge1.target, edge1.callback, @event)
             @manager.expects(:queue_event_for_resource).with(@resource, edge2.target, edge2.callback, @event)
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
 
         it "should queue events for the changed resource if the resource is self-refreshing and not being deleted" do
@@ -57,7 +59,7 @@ describe Puppet::Transaction::EventManager do
             @resource.expects(:deleting?).returns false
             @manager.expects(:queue_event_for_resource).with(@resource, @resource, :refresh, @event)
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
 
         it "should not queue events for the changed resource if the resource is not self-refreshing" do
@@ -67,7 +69,7 @@ describe Puppet::Transaction::EventManager do
             @resource.stubs(:deleting?).returns false
             @manager.expects(:queue_event_for_resource).never
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
 
         it "should not queue events for the changed resource if the resource is being deleted" do
@@ -77,7 +79,7 @@ describe Puppet::Transaction::EventManager do
             @resource.expects(:deleting?).returns true
             @manager.expects(:queue_event_for_resource).never
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
 
         it "should ignore edges that don't have a callback" do
@@ -87,7 +89,7 @@ describe Puppet::Transaction::EventManager do
 
             @manager.expects(:queue_event_for_resource).never
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
 
         it "should ignore targets that don't respond to the callback" do
@@ -97,7 +99,7 @@ describe Puppet::Transaction::EventManager do
 
             @manager.expects(:queue_event_for_resource).never
 
-            @manager.queue_event(@resource, @event)
+            @manager.queue_events(@resource, [@event])
         end
     end
 
@@ -136,7 +138,7 @@ describe Puppet::Transaction::EventManager do
         before do
             @transaction = Puppet::Transaction.new(Puppet::Resource::Catalog.new)
             @manager = Puppet::Transaction::EventManager.new(@transaction)
-            @manager.stubs(:queue_event)
+            @manager.stubs(:queue_events)
 
             @resource = Puppet::Type.type(:file).new :path => "/my/file"
             @event = Puppet::Transaction::Event.new(:name => :event, :resource => @resource)
@@ -167,7 +169,7 @@ describe Puppet::Transaction::EventManager do
             @resource.stubs(:callback1)
 
             @resource.expects(:event).with(:name => :restarted, :status => "success").returns "myevent"
-            @manager.expects(:queue_event).with(@resource, "myevent")
+            @manager.expects(:queue_events).with(@resource, ["myevent"])
 
             @manager.process_events(@resource)
         end
@@ -219,7 +221,7 @@ describe Puppet::Transaction::EventManager do
             it "should queue a new noop event generated from the resource" do
                 event = Puppet::Transaction::Event.new
                 @resource.expects(:event).with(:status => "noop", :name => :noop_restart).returns event
-                @manager.expects(:queue_event).with(@resource, event)
+                @manager.expects(:queue_events).with(@resource, [event])
 
                 @manager.process_events(@resource)
             end
@@ -245,7 +247,7 @@ describe Puppet::Transaction::EventManager do
             end
 
             it "should not queue a 'restarted' event" do
-                @manager.expects(:queue_event).never
+                @manager.expects(:queue_events).never
                 @manager.process_events(@resource)
             end
 

-- 
Puppet packaging for Debian



More information about the Pkg-puppet-devel mailing list