Skip to content

Commit

Permalink
added more tests for multiple servers & apps
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrey Damick authored and Jeffrey Damick committed Jun 12, 2008
1 parent 6f83397 commit 1842c3f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 12 deletions.
2 changes: 2 additions & 0 deletions bin/jetty_rails
Expand Up @@ -20,6 +20,8 @@
# --environment ENV, -e ENV::
# change rails environment (default: development)
#
# --config
#
# BASEDIR (optional): directory to be run (default: current).

require "java"
Expand Down
9 changes: 5 additions & 4 deletions lib/jetty_rails/handler/web_app_handler.rb
@@ -1,18 +1,19 @@
module JettyRails
module Handler
class WebAppHandler < Jetty::Handler::WebAppContext

attr_reader :config, :adapter

def initialize(config)
super("/", config[:context_path])
@config = config

self.class_loader = JRuby.runtime.jruby_class_loader
self.resource_base = config[:base]

adapter = adapter_for(config[:adapter])
self.init_params = adapter.init_params
@adapter = adapter_for(config[:adapter])
self.init_params = @adapter.init_params

adapter.event_listeners.each do |listener|
@adapter.event_listeners.each do |listener|
add_event_listener(listener)
end

Expand Down
2 changes: 2 additions & 0 deletions spec/config.yml
Expand Up @@ -6,6 +6,7 @@
:environment: development
:port: 3000
:lib_dir: lib/**/*.jar
:jruby_initial_runtimes: 2
- :context_path: /testB
:base: /testing
:adapter: :merb
Expand All @@ -15,6 +16,7 @@
- :context_path: /testC
:base: /testing
:adapter: :merb
:environment: test
- :context_path: /testD
:base: /something
:adapter: :rails
Expand Down
55 changes: 47 additions & 8 deletions spec/jetty_rails/config_file_spec.rb
@@ -1,13 +1,12 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe JettyRails::Runner, "with config file" do
describe JettyRails::Runner, "with config file containing several servers and apps" do
before do
@yaml_config = YAML.load_file(File.join(File.dirname(__FILE__), '..', 'config.yml'))
end

it "should handle config.yml with several servers and apps" do
config = @yaml_config
runner = JettyRails::Runner.new(config)
it "should instantiate runner with config.yml and setup servers" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers.size.should == 3
runner.servers[4000].should_not == nil
runner.servers[3000].should_not == nil
Expand All @@ -16,14 +15,54 @@
server.app_contexts.size.should == 2
end

it "should setup correct context_paths from config.yml with several servers and apps" do
config = @yaml_config
runner = JettyRails::Runner.new(config)
it "should setup correct context_paths" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[4000].config[:context_path].should == "/testB"
runner.servers[3000].config[:context_path].should == "/testA"

runner.servers[8080].config[:context_path].should == "/"
runner.servers[8080].app_contexts[0].context_path.should == "/testC"
runner.servers[8080].app_contexts[1].context_path.should == "/testD"
end
end

it "should setup correct adapters" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[4000].config[:adapter].should == :merb
runner.servers[3000].config[:adapter].should == :rails

runner.servers[8080].config[:adapter].should == :rails # default
runner.servers[8080].app_contexts[0].config[:adapter].should == :merb
runner.servers[8080].app_contexts[1].config[:adapter].should == :rails
end

it "should inherit environment" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[4000].config[:environment].should == "production"
runner.servers[3000].config[:environment].should == "development"

runner.servers[8080].config[:environment].should == "production"
runner.servers[8080].app_contexts[0].config[:environment].should =="test"
runner.servers[8080].app_contexts[1].config[:environment].should =="production"
end

it "should setup jruby environment" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[4000].app_contexts.first.adapter.init_params['jruby.initial.runtimes'].should == '1'
runner.servers[4000].app_contexts.first.adapter.init_params['jruby.max.runtimes'].should == '2'

runner.servers[3000].app_contexts.first.adapter.init_params['jruby.initial.runtimes'].should == '2'
runner.servers[3000].app_contexts.first.adapter.init_params['jruby.max.runtimes'].should == '2'
end

it "should setup the server thread pool" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[4000].server.thread_pool.max_threads.should == 40
runner.servers[4000].server.thread_pool.min_threads.should == 1
end

it "should setup the server acceptors" do
runner = JettyRails::Runner.new(@yaml_config)
runner.servers[3000].server.connectors[0].acceptors.should == 20
end

end

0 comments on commit 1842c3f

Please sign in to comment.