From 7947f100a9d9d60d1038e220aa41d44cf59d5af0 Mon Sep 17 00:00:00 2001 From: Ethan Rowe Date: Mon, 13 Apr 2009 07:33:11 -0400 Subject: 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. --- spec/unit/util/queue/stomp.rb | 62 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100755 spec/unit/util/queue/stomp.rb (limited to 'spec/unit/util/queue') 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/"' 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 + -- cgit