diff options
author | Rick Bradley <rick@rickbradley.com> | 2007-10-15 23:04:24 -0500 |
---|---|---|
committer | Rick Bradley <rick@rickbradley.com> | 2007-10-15 23:04:24 -0500 |
commit | b1d62231c587e13ad78fe1bbd292a6c9f1cb99a1 (patch) | |
tree | d7a93ce3be6b72f43bff152418925eda609bd861 | |
parent | 298eff27a6c702c177fa11e08c980c7365382162 (diff) | |
download | puppet-b1d62231c587e13ad78fe1bbd292a6c9f1cb99a1.tar.gz puppet-b1d62231c587e13ad78fe1bbd292a6c9f1cb99a1.tar.xz puppet-b1d62231c587e13ad78fe1bbd292a6c9f1cb99a1.zip |
Bringing in initial handlers for server+protocol pairs.
-rw-r--r-- | lib/puppet/network/http/mongrel.rb | 16 | ||||
-rw-r--r-- | lib/puppet/network/http/webrick.rb | 15 | ||||
-rw-r--r-- | spec/unit/network/http/mongrel.rb | 30 | ||||
-rw-r--r-- | spec/unit/network/http/webrick.rb | 20 | ||||
-rw-r--r-- | spec/unit/network/server.rb | 9 |
5 files changed, 47 insertions, 43 deletions
diff --git a/lib/puppet/network/http/mongrel.rb b/lib/puppet/network/http/mongrel.rb index ab1e616b1..5b14d93c9 100644 --- a/lib/puppet/network/http/mongrel.rb +++ b/lib/puppet/network/http/mongrel.rb @@ -14,10 +14,10 @@ class Puppet::Network::HTTP::Mongrel @protocols = args[:protocols] @handlers = args[:handlers] - - setup_handlers - @server = Mongrel::HttpServer.new(args[:address], args[:port]) + + setup_handlers + @server.run @listening = true end @@ -37,12 +37,16 @@ class Puppet::Network::HTTP::Mongrel def setup_handlers @protocols.each do |protocol| @handlers.each do |handler| - class_for_protocol_handler(protocol, handler).new + class_for_protocol(protocol).new(:server => @server, :handler => handler) end end end - def class_for_protocol_handler(protocol, handler) - Class.new + # TODO/FIXME: need a spec which forces delegation to the real class + def class_for_protocol(protocol) + Class.new do + def initialize(args = {}) + end + end end end diff --git a/lib/puppet/network/http/webrick.rb b/lib/puppet/network/http/webrick.rb index 00d13437c..474f66e4f 100644 --- a/lib/puppet/network/http/webrick.rb +++ b/lib/puppet/network/http/webrick.rb @@ -14,12 +14,11 @@ class Puppet::Network::HTTP::WEBrick raise "WEBrick server is already listening" if listening? @protocols = args[:protocols] - @handlers = args[:handlers] + @handlers = args[:handlers] + @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port]) setup_handlers - @server = WEBrick::HTTPServer.new(:BindAddress => args[:address], :Port => args[:port]) - # TODO / FIXME is this really necessary? -- or can we do it in both mongrel and webrick? Puppet.newservice(@server) Puppet.start @@ -42,12 +41,16 @@ class Puppet::Network::HTTP::WEBrick def setup_handlers @handlers.each do |handler| @protocols.each do |protocol| - class_for_protocol_handler(protocol, handler).new + class_for_protocol(protocol).new(:server => @server, :handler => handler) end end end - def class_for_protocol_handler(protocol, handler) - Class.new + # TODO/FIXME: need a spec which forces delegation to the real class + def class_for_protocol(protocol) + Class.new do + def initialize(args = {}) + end + end end end diff --git a/spec/unit/network/http/mongrel.rb b/spec/unit/network/http/mongrel.rb index 6c8b65582..0990a42d0 100644 --- a/spec/unit/network/http/mongrel.rb +++ b/spec/unit/network/http/mongrel.rb @@ -60,28 +60,16 @@ describe Puppet::Network::HTTP::Mongrel, "when turning on listening" do @server.should be_listening end - it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do - @listen_params[:handlers].each do |handler| - @listen_params[:protocols].each do |protocol| - mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]") - mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]") - mock_handler_class.expects(:new).returns(mock_handler) - @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class) - end - end - @server.listen(@listen_params) - end - - it "should mount each handler on a mongrel path" do - pending "a moment of clarity" - @listen_params[:handlers].each do |handler| - @listen_params[:protocols].each do |protocol| - mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]") - mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]") - mock_handler_class.stubs(:new).returns(mock_handler) - @server.stubs(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class) - # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection + it "should instantiate a handler for each protocol+handler pair to configure web server routing" do + @listen_params[:protocols].each do |protocol| + mock_handler = mock("handler instance for [#{protocol}]") + mock_handler_class = mock("handler class for [#{protocol}]") + @listen_params[:handlers].each do |handler| + mock_handler_class.expects(:new).with {|args| + args[:server] == @mock_mongrel and args[:handler] == handler + }.returns(mock_handler) end + @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class) end @server.listen(@listen_params) end diff --git a/spec/unit/network/http/webrick.rb b/spec/unit/network/http/webrick.rb index b94a6a78d..4d914dc76 100644 --- a/spec/unit/network/http/webrick.rb +++ b/spec/unit/network/http/webrick.rb @@ -60,19 +60,19 @@ describe Puppet::Network::HTTP::WEBrick, "when turning on listening" do @server.should be_listening end - it "should instantiate a specific handler (mongrel+rest, e.g.) for each named handler, for each named protocol)" do - @listen_params[:handlers].each do |handler| - @listen_params[:protocols].each do |protocol| - mock_handler = mock("handler instance for [#{protocol}]+[#{handler}]") - mock_handler_class = mock("handler class for [#{protocol}]+[#{handler}]") - mock_handler_class.expects(:new).returns(mock_handler) - @server.expects(:class_for_protocol_handler).with(protocol, handler).returns(mock_handler_class) + it "should instantiate a handler for each protocol+handler pair to configure web server routing" do + @listen_params[:protocols].each do |protocol| + mock_handler = mock("handler instance for [#{protocol}]") + mock_handler_class = mock("handler class for [#{protocol}]") + @listen_params[:handlers].each do |handler| + mock_handler_class.expects(:new).with {|args| + args[:server] == @mock_webrick and args[:handler] == handler + }.returns(mock_handler) end + @server.expects(:class_for_protocol).with(protocol).at_least_once.returns(mock_handler_class) end - @server.listen(@listen_params) + @server.listen(@listen_params) end - - it "should mount handlers on a webrick path" end describe Puppet::Network::HTTP::WEBrick, "when turning off listening" do diff --git a/spec/unit/network/server.rb b/spec/unit/network/server.rb index 6802c6aaa..528d47d0e 100644 --- a/spec/unit/network/server.rb +++ b/spec/unit/network/server.rb @@ -268,6 +268,15 @@ describe Puppet::Network::Server, "when listening is being turned off" do end end + + # TODO / FIXME : HERE -- need to begin resolving the model behind the indirection + # looks like: get the handler class, providing @server to it + # have the handler class register the handler @ the right URL + # handler class knows the correct path to use, correct registration method to call + # handler also know how to get the model class from the indirection name + # do we change indirection name to indirection (instead of saying "handlers")? + + describe Class.new, "Puppet::Network::Handler::*::* (handler class (e.g., webrick+rest or mongrel+xmlrpc))" do it "should be able to unserialize a request from the given httpserver answering for the given protocol handler, to be used by a controller" it "should be able to serialize a result from a controller for return by the given httpserver responding with the given protocol" |