Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make JRuby before command hook work on Aruba environment #610

Merged
merged 1 commit into from
May 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions lib/aruba/config/jruby.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,21 @@
config.before :command do
next unless RUBY_PLATFORM == 'java'

jruby_opts = aruba.environment['JRUBY_OPTS'] || ''

# disable JIT since these processes are so short lived
ENV['JRUBY_OPTS'] = "-X-C #{ENV['JRUBY_OPTS']}" unless (ENV['JRUBY_OPTS'] || '') .include? '-X-C'
jruby_opts = "-X-C #{jruby_opts}" unless jruby_opts.include? '-X-C'

# Faster startup for jruby
ENV['JRUBY_OPTS'] = "--dev #{ENV['JRUBY_OPTS']}" unless (ENV['JRUBY_OPTS'] || '').include? '--dev'
jruby_opts = "--dev #{jruby_opts}" unless jruby_opts.include? '--dev'

set_environment_variable('JRUBY_OPTS', jruby_opts)

if RbConfig::CONFIG['host_os'] =~ /solaris|sunos/i
java_opts = aruba.environment['JAVA_OPTS'] || ''

# force jRuby to use client JVM for faster startup times
ENV['JAVA_OPTS'] = "-d32 #{ENV['JAVA_OPTS']}" if RbConfig::CONFIG['host_os'] =~ /solaris|sunos/i && !(ENV['JAVA_OPTS'] || '').include?('-d32')
# force jRuby to use client JVM for faster startup times
set_environment_variable('JAVA_OPTS', "-d32 #{java_opts}") unless java_opts.include?('-d32')
end
end
end
73 changes: 47 additions & 26 deletions spec/aruba/jruby_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,75 @@
require 'aruba/api'

describe "Aruba JRuby Startup Helper" do
before(:all) do
@fake_env = ENV.clone
end
include Aruba::Api
include_context 'uses aruba API'

let(:rb_config) { double('RbConfig::CONFIG') }

before :each do
before do
Aruba.config.reset

# Define before_cmd-hook
# Define before :command hook
load 'aruba/config/jruby.rb'
end

before(:each) do
@fake_env['JRUBY_OPTS'] = "--1.9"
@fake_env['JAVA_OPTS'] = "-Xdebug"

stub_const('ENV', @fake_env)
around do |example|
with_environment('JRUBY_OPTS' => '--1.9', 'JAVA_OPTS' => '-Xdebug') do
example.run
end
end

context 'when some mri ruby' do
before :each do
context 'when running under some MRI Ruby' do
before do
stub_const('RUBY_PLATFORM', 'x86_64-chocolate')
end

before :each do
it 'keeps the existing JRuby and Java option values' do
# Run defined before :command hook
Aruba.config.before :command, self
end

it { expect(ENV['JRUBY_OPTS']).to eq '--1.9' }
it { expect(ENV['JAVA_OPTS']).to eq '-Xdebug' }
with_environment do
expect(ENV['JRUBY_OPTS']).to eq '--1.9'
expect(ENV['JAVA_OPTS']).to eq '-Xdebug'
end
end
end

context 'when jruby ruby' do
before :each do
stub_const('RUBY_PLATFORM', 'java')
context 'when running under JRuby but not on Solaris' do
before do
stub_const 'RUBY_PLATFORM', 'java'
stub_const 'RbConfig::CONFIG', rb_config

allow(rb_config).to receive(:[]).with('host_os').and_return('foo-os')
end

before :each do
rb_config = double('rb_config')
allow(rb_config).to receive(:[]).and_return('solaris')
it 'updates the existing JRuby but not Java option values' do
# Run defined before :command hook
Aruba.config.before :command, self

stub_const 'RbConfig::CONFIG', rb_config
with_environment do
expect(ENV['JRUBY_OPTS']).to eq '--dev -X-C --1.9'
expect(ENV['JAVA_OPTS']).to eq '-Xdebug'
end
end
end

context 'when running under JRuby on Solaris' do
before :each do
Aruba.config.before :command, self
stub_const 'RUBY_PLATFORM', 'java'
stub_const 'RbConfig::CONFIG', rb_config

allow(rb_config).to receive(:[]).with('host_os').and_return('solaris')
end

it { expect(ENV['JRUBY_OPTS']).to eq '--dev -X-C --1.9' }
it { expect(ENV['JAVA_OPTS']).to eq '-d32 -Xdebug' }
it 'keeps the existing JRuby and Java option values' do
# Run defined before :command hook
Aruba.config.before :command, self

with_environment do
expect(ENV['JRUBY_OPTS']).to eq '--dev -X-C --1.9'
expect(ENV['JAVA_OPTS']).to eq '-d32 -Xdebug'
end
end
end
end