Permalink
Browse files

Implemented tests for Rack behavior and async requests.

  • Loading branch information...
1 parent 324e2ed commit 3434ff77c8b32bad1cbf68e5b679fe9794f72178 @matadon matadon committed Feb 11, 2011
View
@@ -17,7 +17,8 @@ Mizuno is the fastest option for Rack applications on JRuby:
Jetty (via jruby-rack): 2011.67 req/s (mean)
Mongrel: 1479.15 req/sec (mean)
-Mizuno also supports asynchronous request handling.
+Mizuno also supports asynchronous request handling, via the Java Servlet
+3.0 asynchronous processing mechanism
All the speed comes from Jetty 7; Mizuno just ties it to Rack through
JRuby's Ruby/Java integration layer.
@@ -28,10 +29,8 @@ Rack application for installation in a Java web container.
There's also a few features that I have yet to implement:
-1. Integrate the cometd servlet to provide Comet/Bayeux.
-2. Route Jetty's logs into Rack::Logger.
-3. Add hooks for realtime monitoring of server performance.
-4. Add the ability to run multiple Rack apps in a single JVM.
+1. Route Jetty's logs into Rack::Logger.
+2. Add hooks for realtime monitoring of server performance.
Mizuno is licensed under the Apache Public License, version 2.0; see
the LICENSE file for details, and was developed on behalf of
View
@@ -0,0 +1,5 @@
+require 'rspec/core/rake_task'
+
+RSpec::Core::RakeTask.new(:spec)
+
+task :default => :spec
Binary file not shown.
Binary file not shown.
View
@@ -1,13 +0,0 @@
-../../tmp/cometd-2.1.0/cometd-archetypes/dojo-jetty6/target/cometd-archetype-dojo-jetty6-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-archetypes/dojo-jetty7/target/cometd-archetype-dojo-jetty7-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-archetypes/jquery-jetty6/target/cometd-archetype-jquery-jetty6-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-archetypes/jquery-jetty7/target/cometd-archetype-jquery-jetty7-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-archetypes/spring-dojo-jetty7/target/cometd-archetype-spring-dojo-jetty7-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-archetypes/spring-jquery-jetty7/target/cometd-archetype-spring-jquery-jetty7-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/bayeux-api/target/bayeux-api-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/cometd-java-annotations/target/cometd-java-annotations-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/cometd-java-client/target/cometd-java-client-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/cometd-java-common/target/cometd-java-common-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/cometd-java-oort/target/cometd-java-oort-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-java/cometd-java-server/target/cometd-java-server-2.1.0.jar
-../../tmp/cometd-2.1.0/cometd-javascript/common-test/target/cometd-javascript-common-test-2.1.0.jar
View
@@ -9,45 +9,79 @@ class HttpServer
include_class 'org.eclipse.jetty.servlet.ServletHolder'
include_class 'org.eclipse.jetty.server.nio.SelectChannelConnector'
include_class 'org.eclipse.jetty.util.thread.QueuedThreadPool'
+ include_class 'org.eclipse.jetty.servlet.DefaultServlet'
+ #
+ # Provide accessors so we can set a custom logger and a location
+ # for static assets.
+ #
+ class << self
+ attr_accessor :logger
+ end
+
+ #
+ # Start up an instance of Jetty, running a Rack application.
+ # Options can be any of the follwing, and are not
+ # case-sensitive:
+ #
+ # :host::
+ # String specifying the IP address to bind to; defaults
+ # to 0.0.0.0.
+ #
+ # :port::
+ # String or integer with the port to bind to; defaults
+ # to 9292.
+ #
+ # FIXME: Clean up options hash (all downcase, all symbols)
+ #
def self.run(app, options = {})
# The Jetty server
- server = Server.new
+ @server = Server.new
+
+ options = Hash[options.map { |o|
+ [ o[0].to_s.downcase.to_sym, o[1] ] }]
# Thread pool
thread_pool = QueuedThreadPool.new
thread_pool.min_threads = 5
thread_pool.max_threads = 50
- server.set_thread_pool(thread_pool)
+ @server.set_thread_pool(thread_pool)
# Connector
connector = SelectChannelConnector.new
- connector.setPort(options[:Port].to_i)
- connector.setHost(options[:Host])
- server.addConnector(connector)
+ connector.setPort(options[:port].to_i)
+ connector.setHost(options[:host])
+ @server.addConnector(connector)
# Servlet context.
context = ServletContextHandler.new(nil, "/",
ServletContextHandler::NO_SESSIONS)
# The servlet itself.
- servlet = RackServlet.new
- servlet.rackup(app)
- holder = ServletHolder.new(servlet)
+ rack_servlet = RackServlet.new
+ rack_servlet.rackup(app)
+ holder = ServletHolder.new(rack_servlet)
context.addServlet(holder, "/")
# Add the context to the server and start.
- server.set_handler(context)
- puts "Started Jetty on #{connector.getHost}:#{connector.getPort}"
- server.start
+ @server.set_handler(context)
+ puts "Listening on #{connector.getHost}:#{connector.getPort}"
+ @server.start
# Stop the server when we get The Signal.
- trap("SIGINT") { server.stop and exit }
+ trap("SIGINT") { @server.stop and exit }
# Join with the server thread, so that currently open file
# descriptors don't get closed by accident.
# http://www.ruby-forum.com/topic/209252
- server.join
+ @server.join unless options[:embedded]
+ end
+
+ #
+ # Shuts down an embedded Jetty instance.
+ #
+ def self.stop
+ @server.stop
end
end
end
@@ -3,8 +3,9 @@
#
# Relevant documentation:
#
-# http://rack.rubyforge.org/doc/SPEC.html
-# http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet.html
+# http://rack.rubyforge.org/doc/SPEC.html
+# http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax
+# /servlet/http/HttpServlet.html
#
module Mizuno
include_class javax.servlet.http.HttpServlet
View
@@ -1,73 +0,0 @@
-require 'yaml'
-require 'net/http'
-
-class TestApp
- def call(env)
- status = env["QUERY_STRING"] =~ /secret/ ? 403 : 200
- env["test.postdata"] = env["rack.input"].read
- body = env.to_yaml
- size = body.respond_to?(:bytesize) ? body.bytesize : body.size
- [status, {"Content-Type" => "text/yaml",
- "Content-Length" => size.to_s}, [body]]
- end
-
- module Helpers
- attr_reader :status, :response
-
- ROOT = File.expand_path(File.dirname(__FILE__) + "/..")
- ENV["RUBYOPT"] = "-I#{ROOT}/lib -rubygems"
-
- def root
- ROOT
- end
-
- def rackup
- "#{ROOT}/bin/rackup"
- end
-
- def GET(path, header={})
- Net::HTTP.start(@options[:Host], @options[:Port]) { |http|
- user = header.delete(:user)
- passwd = header.delete(:passwd)
-
- get = Net::HTTP::Get.new(path, header)
- get.basic_auth user, passwd if user && passwd
- http.request(get) { |response|
- @status = response.code.to_i
- begin
- @response = YAML.load(response.body)
- rescue ArgumentError
- @response = nil
- end
- }
- }
- end
-
- def POST(path, formdata={}, header={})
- Net::HTTP.start(@options[:Host], @options[:Port]) { |http|
- user = header.delete(:user)
- passwd = header.delete(:passwd)
-
- post = Net::HTTP::Post.new(path, header)
- post.form_data = formdata
- post.basic_auth user, passwd if user && passwd
- http.request(post) { |response|
- @status = response.code.to_i
- @response = YAML.load(response.body)
- }
- }
- end
- end
-end
-
-class StreamingRequest
- def self.call(env)
- [200, {"Content-Type" => "text/plain"}, new]
- end
-
- def each
- yield "hello there!\n"
- sleep 5
- yield "that is all.\n"
- end
-end
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |spec|
spec.name = "mizuno"
- spec.version = "0.3.7"
+ spec.version = "0.4.0"
spec.required_rubygems_version = Gem::Requirement.new(">= 1.2") \
if spec.respond_to?(:required_rubygems_version=)
spec.authors = [ "Don Werve" ]
@@ -12,8 +12,6 @@ Gem::Specification.new do |spec|
README.markdown
LICENSE
mizuno.gemspec
- lib/java/bayeux-api-2.1.0.jar
- lib/java/cometd-java-server-2.1.0.jar
lib/java/jetty-continuation-7.3.0.v20110203.jar
lib/java/jetty-http-7.3.0.v20110203.jar
lib/java/jetty-io-7.3.0.v20110203.jar
@@ -24,12 +22,13 @@ Gem::Specification.new do |spec|
lib/java/jetty-servlets-7.3.0.v20110203.jar
lib/java/jetty-util-7.3.0.v20110203.jar
lib/java/servlet-api-2.5.jar
- lib/rack/handler/mizuno/http_server.rb
- lib/rack/handler/mizuno/rack_servlet.rb
- lib/rack/handler/mizuno.rb
+ lib/mizuno/http_server.rb
+ lib/mizuno/rack_servlet.rb
+ lib/mizuno.rb
bin/mizuno )
spec.homepage = 'http://github.com/matadon/mizuno'
spec.has_rdoc = false
spec.require_paths = [ "lib" ]
spec.rubygems_version = '1.3.6'
+ spec.add_dependency('rack', '>= 1.0.0')
end
View
@@ -0,0 +1 @@
+Hello, world!
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.

0 comments on commit 3434ff7

Please sign in to comment.