Skip to content


Subversion checkout URL

You can clone with
Download ZIP


JRuby version of integration server, started in-process w/ ScriptingContainer #479

merged 1 commit into from

3 participants


It's a little verbose and has to work around a couple of issues that diverge from behavior when launched from the command-line, but it seems to work :).

@rkh rkh merged commit cc1ca2a into sinatra:master

Thanks a ton. <3


Works like a charm for WEBrick. However, with Trinidad (see trinidad branch), for some reason the vm.output/vm.error redirecting doesn't work properly.


Hmm. I'm guessing Trinidad is printing its output to the JVM's stdin/stdout. If I had my choice I'd prefer to see if Trinidad would accept a patch to set up its loggers to log to the JRuby runtime's provided streams. @calavera, do you have any thoughts?


Nick, what's your take on these changes:


@nicksieger any patch in Trinidad is really welcome. If I'm not wrong one of the log handlers in the line below is a console handler that prints directly to the stdout. I guess we should modify it to print to the runtime output stream:


@rkh the JRuby-specific changes look fine to me. I'd like to see if we could set up Trinidad to log to the runtime's configured streams. Maybe that will help solve some of the issues with #482.


@nicksieger I think this can work:



@calavera cool! Now I think we just need to fix the jruby-rack embed context to not log to System.out and System.err.

@kares kares referenced this pull request in jruby/jruby-rack

embedded RackConfig with out/err streams correctly setup #103

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 55 additions and 1 deletion.
  1. +55 −1 test/integration_helper.rb
56 test/integration_helper.rb
@@ -4,7 +4,7 @@
require 'net/http'
module IntegrationHelper
- class Server
+ class BaseServer
extend Enumerable
attr_accessor :server, :port, :pipe
alias name server
@@ -127,6 +127,60 @@ def webrick?
+ if RUBY_ENGINE == "jruby"
+ class JRubyServer < BaseServer
+ def start_vm
+ require 'java'
+ # Create a new container, set load paths and env
+ # SINGLETHREAD means create a new runtime
+ vm =
+ vm.load_paths = [File.expand_path('../../lib', __FILE__)]
+ vm.environment = ENV.merge('RACK_ENV' => environment.to_s)
+ # This ensures processing of RUBYOPT which activates Bundler
+ vm.provider.ruby_instance_config.process_arguments []
+ vm.argv = ['-s', server.to_s, '-o', '', '-p', port.to_s, '-e', environment.to_s]
+ # Set stdout/stderr so we can retrieve log
+ @pipe =
+ vm.output =
+ vm.error =
+ do
+ # Hack to ensure that Kernel#caller has the same info as
+ # when run from command-line, for Sintra::Application.app_file.
+ # Also, line numbers are zero-based in JRuby's parser
+ vm.provider.runtime.current_context.set_file_and_line(app_file, 0)
+ # Run the app
+ vm.run_scriptlet org.jruby.embed.PathType::ABSOLUTE, app_file
+ # terminate launches at_exit hooks which start server
+ vm.terminate
+ end
+ end
+ def run
+ return unless installed?
+ kill
+ @thread = start_vm
+ @started =
+ warn "#{server} up and running on port #{port}" if ping
+ at_exit { kill }
+ end
+ def log
+ String.from_java_bytes @pipe.to_byte_array
+ end
+ def kill
+ @thread.kill if @thread
+ @thread = nil
+ end
+ end
+ Server = JRubyServer
+ else
+ Server = BaseServer
+ end
def it(message, &block)
Server.each do |server|
next unless server.installed?
Something went wrong with that request. Please try again.