From 5f4e9eed882788c3a4bd847b83607c68da2f50b5 Mon Sep 17 00:00:00 2001 From: Erik Hatcher Date: Sat, 17 Feb 2007 02:53:20 +0000 Subject: [PATCH] SOLR-160: work on functional tests functioning on Windows. This commit is a slight tweak to the code contributed by Mel Riffe git-svn-id: https://svn.apache.org/repos/asf/lucene/solr/trunk@508701 13f79535-47bb-0310-9956-ffa450edef68 --- .../solrb/test/functional/test_solr_server.rb | 69 ++++++++++++------- 1 file changed, 44 insertions(+), 25 deletions(-) diff --git a/client/ruby/solrb/test/functional/test_solr_server.rb b/client/ruby/solrb/test/functional/test_solr_server.rb index 43dcc8295c0..0e58bd76673 100644 --- a/client/ruby/solrb/test/functional/test_solr_server.rb +++ b/client/ruby/solrb/test/functional/test_solr_server.rb @@ -10,48 +10,27 @@ # See the License for the specific language governing permissions and # limitations under the License. -# A singleton class for starting/stopping a Solr server for testing purposes -# The behavior of TestSolrServer can be modified prior to start() by changing -# port, solr_home, and quiet properties. - class TestSolrServer require 'singleton' include Singleton attr_accessor :port, :solr_home, :quiet - + # configure the singleton with some defaults def initialize @port = 8888 @quiet = true root_dir = File.expand_path(File.dirname(__FILE__) + '/../..') @solr_dir = "#{root_dir}/solr" - @solr_home = "#{root_dir}/test" + @solr_home = "#{root_dir}/test" @pid = nil end - # start the solr server - def start - Dir.chdir(@solr_dir) do - @pid = fork do - STDERR.close if @quiet - exec "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} " + - "-jar start.jar" - end - end - end - - # stop a running solr server - def stop - Process.kill('TERM', @pid) - Process.wait - end - def self.wrap(params = {}) error = false solr_server = self.instance solr_server.quiet = params[:quiet] begin - puts "starting solr server" + puts "starting solr server on #{RUBY_PLATFORM}" solr_server.start sleep params[:startup_wait] || 5 yield @@ -61,8 +40,48 @@ class TestSolrServer puts "stopping solr server" solr_server.stop end - + return error end + + if RUBY_PLATFORM =~ /mswin32/ + require 'win32/process' + + # start the solr server + def start + Dir.chdir(@solr_dir) do + @pid = Process.create( + :app_name => "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -jar start.jar", + :creation_flags => Process::DETACHED_PROCESS, + :process_inherit => false, + :thread_inherit => true, + :cwd => "#{@solr_dir}" + ).process_id + end + end + + # stop a running solr server + def stop + Process.kill(1, @pid) + Process.wait + end + else # Not Windows + # start the solr server + def start + Dir.chdir(@solr_dir) do + @pid = fork do + STDERR.close if @quiet + exec "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} " + + "-jar start.jar" + end + end + end + + # stop a running solr server + def stop + Process.kill('TERM', @pid) + Process.wait + end + end end