Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

JRuby version of integration server, started in-process w/ ScriptingC…

…ontainer
  • Loading branch information...
commit f1f69f09722f1d4bf616f73812c34dd766afd46a 1 parent 09d3918
@nicksieger nicksieger authored
Showing with 55 additions and 1 deletion.
  1. +55 −1 test/integration_helper.rb
View
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?
end
end
+ 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 = org.jruby.embed.ScriptingContainer.new(org.jruby.embed.LocalContextScope::SINGLETHREAD)
+ 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', '127.0.0.1', '-p', port.to_s, '-e', environment.to_s]
+
+ # Set stdout/stderr so we can retrieve log
+ @pipe = java.io.ByteArrayOutputStream.new
+ vm.output = java.io.PrintStream.new(@pipe)
+ vm.error = java.io.PrintStream.new(@pipe)
+
+ Thread.new 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 = Time.now
+ 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?
Please sign in to comment.
Something went wrong with that request. Please try again.