Move the configure() method to help support deferred configuration.  Fix tests for CZTop.
2 files changed, 36 insertions(+), 35 deletions(-)

M lib/thingfish/handler.rb
M spec/thingfish/handler_spec.rb
M lib/thingfish/handler.rb +21 -20
@@ 74,22 74,6 @@ class Thingfish::Handler < Strelka::App
 	singleton_attr_accessor :processors
 
 
-	### Configurability API -- install the configuration
-	def self::configure( config=nil )
-		config = self.defaults.merge( config || {} )
-
-		self.datastore        = config[:datastore]
-		self.metastore        = config[:metastore]
-		self.event_socket_uri = config[:event_socket_uri]
-
-		self.processors = self.load_processors( config[:processors] )
-		self.processors.each do |processor|
-			self.filter( :request, &processor.method(:process_request) )
-			self.filter( :response, &processor.method(:process_response) )
-		end
-	end
-
-
 	### Load the Thingfish::Processors in the given +processor_list+ and return an instance
 	### of each one.
 	def self::load_processors( processor_list )

          
@@ 110,6 94,24 @@ class Thingfish::Handler < Strelka::App
 	end
 
 
+	### Configurability API -- install the configuration
+	def self::configure( config=nil )
+		config = self.defaults.merge( config || {} )
+
+		self.datastore        = config[:datastore]
+		self.metastore        = config[:metastore]
+		self.event_socket_uri = config[:event_socket_uri]
+
+		self.plugin( :filters ) # pre-load the filters plugin for deferred config
+
+		self.processors = self.load_processors( config[:processors] )
+		self.processors.each do |processor|
+			self.filter( :request, &processor.method(:process_request) )
+			self.filter( :response, &processor.method(:process_response) )
+		end
+	end
+
+
 	### Set up the metastore, datastore, and event socket when the handler is
 	### created.
 	def initialize( * ) # :notnew:

          
@@ 145,8 147,8 @@ class Thingfish::Handler < Strelka::App
 	### Set up the event socket.
 	def setup_event_socket
 		if self.class.event_socket_uri && ! @event_socket
-			@event_socket = Mongrel2.zmq_context.socket( :PUB )
-			@event_socket.linger = 0
+			@event_socket = CZTop::Socket::PUB.new
+			@event_socket.options.linger = 0
 			@event_socket.bind( self.class.event_socket_uri )
 		end
 	end

          
@@ 781,8 783,7 @@ class Thingfish::Handler < Strelka::App
 	def send_event( type, msg )
 		esock = self.event_socket or return
 		self.log.debug "Publishing %p event: %p" % [ type, msg ]
-		esock.sendm( type.to_s )
-		esock.send( Yajl.dump(msg) )
+		esock << CZTop::Message.new([ type.to_s, Yajl.dump(msg) ])
 	end
 
 

          
M spec/thingfish/handler_spec.rb +15 -15
@@ 9,7 9,7 @@ require 'thingfish/processor'
 
 describe Thingfish::Handler do
 
-	EVENT_SOCKET_URI = 'tcp://127.0.0.1:0'
+	EVENT_SOCKET_URI = 'tcp://127.0.0.1:*'
 
 	before( :all ) do
 		Thingfish::Handler.configure( :event_socket_uri => EVENT_SOCKET_URI )

          
@@ 865,10 865,10 @@ describe Thingfish::Handler do
 		before( :each ) do
 			@handler.setup_event_socket
 
-			@subsock = Mongrel2.zmq_context.socket( :SUB )
-			@subsock.linger = 0
+			@subsock = CZTop::Socket::SUB.new
+			@subsock.options.linger = 0
 			@subsock.subscribe( '' )
-			@subsock.connect( @handler.event_socket.endpoint )
+			@subsock.connect( @handler.event_socket.last_endpoint )
 		end
 
 		after( :each ) do

          
@@ 878,20 878,20 @@ describe Thingfish::Handler do
 		it "publishes notifications about uploaded assets to a PUBSUB socket" do
 			req = factory.post( '/', TEST_TEXT_DATA, content_type: 'text/plain' )
 			req.headers.content_length = TEST_TEXT_DATA.bytesize
-			res = @handler.handle( req )
 
-			handles = ZMQ.select( [@subsock], nil, nil, 0 )
-			expect( handles ).to be_an( Array )
-			expect( handles[0].size ).to eq( 1 )
-			expect( handles[0].first ).to be( @subsock )
+			poller = CZTop::Poller.new
+			poller.add_reader( @subsock )
+
+			res = @handler.handle( req )
+			event = poller.wait( 500 )
 
-			event = @subsock.recv
-			expect( @subsock.rcvmore? ).to be_truthy
-			expect( event ).to eq( 'created' )
+			expect( event ).to_not be_nil
 
-			resource = @subsock.recv
-			expect( @subsock.rcvmore? ).to be_falsey
-			expect( resource ).to match( /^\{"uuid":"#{UUID_PATTERN}"\}$/ )
+			message = event.socket.receive
+			expect( message.frames.count ).to be( 2 )
+
+			expect( message.frames.first.to_s ).to eq( 'created' )
+			expect( message.frames.last.to_s ).to match( /^\{"uuid":"#{UUID_PATTERN}"\}$/ )
 		end
 	end