diff options
| author | Ethan Rowe <ethan@endpoint.com> | 2009-04-13 07:33:11 -0400 |
|---|---|---|
| committer | James Turnbull <james@lovedthanlost.net> | 2009-04-22 14:39:37 +1000 |
| commit | 7947f100a9d9d60d1038e220aa41d44cf59d5af0 (patch) | |
| tree | f9c71a5783ad85d17b7e702b1ff706dc34a7dff6 /spec/unit/util/queue | |
| parent | 80dc83715190335ec0aac142e383d60ca28ea3b3 (diff) | |
| download | puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.gz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.tar.xz puppet-7947f100a9d9d60d1038e220aa41d44cf59d5af0.zip | |
Introduce queue client "plugin" namespace and interface, with a Stomp client implementation.
Puppet::Util::Queue provides queue client mix-in behaviors that enable easy queue client management for consumer classes. Some relevant behaviors include:
* standard Puppet instance loader behavior for loading queue client modules on-demand based on the client module specified by symbolic name
* singleton registry of known queue client types (based on symbol-to-class mappings from the instance loading behavior)
* simple interface for working with an actual queue client instance
Puppet::Util::Queue::Stomp wraps the Stomp::Client class to provide an initial queue client option supporting the Stomp messaging protocol. This defines the interface for all Puppet queue client plugins going forward.
Diffstat (limited to 'spec/unit/util/queue')
| -rwxr-xr-x | spec/unit/util/queue/stomp.rb | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/unit/util/queue/stomp.rb b/spec/unit/util/queue/stomp.rb new file mode 100755 index 000000000..c4d8b7672 --- /dev/null +++ b/spec/unit/util/queue/stomp.rb @@ -0,0 +1,62 @@ +#!/usr/bin/env ruby + +require File.dirname(__FILE__) + '/../../../spec_helper' +require 'puppet/util/queue' + +describe Puppet::Util::Queue do + it 'should load :stomp client appropriately' do + Puppet.settings.stubs(:value).returns 'faux_queue_source' + Puppet::Util::Queue.queue_type_to_class(:stomp).name.should == 'Puppet::Util::Queue::Stomp' + end +end + +describe 'Puppet::Util::Queue::Stomp' do + before :all do + class Stomp::Client + include Mocha::Standalone + attr_accessor :queue_source + + def send(q, m) + 'To %s: %s' % [q, m] + end + + def subscribe(q) + yield(stub(:body => 'subscribe: %s' % q)) + end + + def initialize(s) + self.queue_source = s + end + end + end + + before :each do + Puppet.settings.stubs(:value).returns 'faux_queue_source' + end + + it 'should make send function like core Ruby instead of stomp client send method' do + o = Puppet::Util::Queue::Stomp.new + o.expects(:pants).with('foo').once + o.send(:pants, 'foo') + end + + it 'should be registered with Puppet::Util::Queue as :stomp type' do + Puppet::Util::Queue.queue_type_to_class(:stomp).should == Puppet::Util::Queue::Stomp + end + + it 'should initialize using Puppet[:queue_source] for configuration' do + o = Puppet::Util::Queue::Stomp.new + o.stomp_client.queue_source.should == 'faux_queue_source' + end + + it 'should transform the simple queue name to "/queue/<queue_name>"' do + Puppet::Util::Queue::Stomp.new.stompify_target('blah').should == '/queue/blah' + end + + it 'should transform the queue name properly and pass along to superclass for send and subscribe' do + o = Puppet::Util::Queue::Stomp.new + o.send_message('fooqueue', 'Smite!').should == 'To /queue/fooqueue: Smite!' + o.subscribe('moodew') {|obj| obj}.should == 'subscribe: /queue/moodew' + end +end + |
