From adf942c342df636cdc5b6ffb63a2a6e31de98ec7 Mon Sep 17 00:00:00 2001 From: Colin Surprenant Date: Wed, 9 Apr 2014 13:41:40 -0400 Subject: [PATCH] removed assess_jruby! & renamed spec/environment.rb --- lib/logstash/environment.rb | 15 +-------------- lib/logstash/outputs/elasticsearch.rb | 6 +++--- spec/environment.rb | 24 ------------------------ 3 files changed, 4 insertions(+), 41 deletions(-) diff --git a/lib/logstash/environment.rb b/lib/logstash/environment.rb index cced4ed57..1a03b22a1 100644 --- a/lib/logstash/environment.rb +++ b/lib/logstash/environment.rb @@ -10,7 +10,7 @@ module LogStash # loads currenly embedded elasticsearch jars # @raise LogStash::EnvironmentError if not runnig under JRuby or if no jar files found def load_elasticsearch_jars! - assess_jruby! + raise(LogStash::EnvironmentError, "JRuby is required") unless jruby? require "java" jars_path = ::File.join(JAR_DIR, "/elasticsearch*/lib/*.jar") @@ -24,19 +24,6 @@ module LogStash end end - # @yield execute optional block if not currently running under JRuby - # @yieldreturn [Exception] exception to raise if Exception class returned otherwise raise default exception - # @raise [Exception] yielded exception or default if not runnig under JRuby - def assess_jruby! - unless jruby? - # grab return value from block if present, use default exception if not an exception class - exception = block_given? ? yield : nil - exception = LogStash::EnvironmentError.new("JRuby is required") unless exception.is_a?(Exception) - - raise(exception) - end - end - def jruby? RUBY_PLATFORM == "java" end diff --git a/lib/logstash/outputs/elasticsearch.rb b/lib/logstash/outputs/elasticsearch.rb index 5bd74d26f..ddf237a29 100644 --- a/lib/logstash/outputs/elasticsearch.rb +++ b/lib/logstash/outputs/elasticsearch.rb @@ -192,12 +192,12 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base end if @protocol.nil? - @protocol = (RUBY_PLATFORM == "java") ? "node" : "http" + @protocol = LogStash::Environment.jruby? ? "node" : "http" end if ["node", "transport"].include?(@protocol) # Node or TransportClient; requires JRuby - LogStash::Environment.assess_jruby!{LogStash::PluginLoadingError.new("This configuration requires JRuby. If you are not using JRuby, you must set 'protocol' to 'http'. For example: output { elasticsearch { protocol => \"http\" } }")} + raise(LogStash::PluginLoadingError, "This configuration requires JRuby. If you are not using JRuby, you must set 'protocol' to 'http'. For example: output { elasticsearch { protocol => \"http\" } }") unless LogStash::Environment.jruby? LogStash::Environment.load_elasticsearch_jars! # setup log4j properties for Elasticsearch @@ -241,7 +241,7 @@ class LogStash::Outputs::ElasticSearch < LogStash::Outputs::Base :protocol => @protocol) if @embedded - LogStash::Environment.assess_jruby!{LogStash::ConfigurationError.new("The 'embedded => true' setting is only valid for the elasticsearch output under JRuby. You are running #{RUBY_DESCRIPTION}")} + raise(LogStash::ConfigurationError, "The 'embedded => true' setting is only valid for the elasticsearch output under JRuby. You are running #{RUBY_DESCRIPTION}") unless LogStash::Environment.jruby? LogStash::Environment.load_elasticsearch_jars! # Default @host with embedded to localhost. This should help avoid diff --git a/spec/environment.rb b/spec/environment.rb index c9e8f1772..d0dea75ff 100644 --- a/spec/environment.rb +++ b/spec/environment.rb @@ -13,28 +13,4 @@ describe LogStash::Environment do expect{LogStash::Environment.load_elasticsearch_jars!}.to raise_error(LogStash::EnvironmentError) end end - - describe "assess_jruby!" do - - it "should not raise when jruby" do - expect(LogStash::Environment).to receive(:jruby?).twice.and_return(true) - expect{LogStash::Environment.assess_jruby!}.to_not raise_error - expect{LogStash::Environment.assess_jruby!{StandardError.new}}.to_not raise_error - end - - it "should raise default exception" do - expect(LogStash::Environment).to receive(:jruby?).once.and_return(false) - expect{LogStash::Environment.assess_jruby!}.to raise_error(LogStash::EnvironmentError) - end - - it "should yield to block and raise returned exception" do - expect(LogStash::Environment).to receive(:jruby?).once.and_return(false) - expect{LogStash::Environment.assess_jruby!{StandardError.new}}.to raise_error(StandardError) - end - - it "should yield to block and raise default exception if exception not returned" do - expect(LogStash::Environment).to receive(:jruby?).once.and_return(false) - expect{LogStash::Environment.assess_jruby!{nil}}.to raise_error(LogStash::EnvironmentError) - end - end end