diff --git a/client/ruby/solrb/Rakefile b/client/ruby/solrb/Rakefile index b6ec03a342a..8148667f612 100644 --- a/client/ruby/solrb/Rakefile +++ b/client/ruby/solrb/Rakefile @@ -1,3 +1,34 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +# the default task is to run both the unit and functional tests +# functional tests require that a solr test server is running +# but this Rakefil should take care of starting and stopping it +# for you +# +# if you just want to run unit tests: +# +# rake test_units +# +# and if you just want to run functional tests +# +# rake test_functionals +# +# if you would like to see solr startup messages on STDERR +# when starting solr test server during functional tests use: +# +# rake SOLR_CONSOLE=true + SOLRB_VERSION = '0.0.1' require 'rubygems' @@ -6,7 +37,7 @@ require 'rake/testtask' require 'rake/rdoctask' require 'rake/packagetask' require 'rake/gempackagetask' -require 'test/test_helper.rb' +require 'test/test_solr_server.rb' task :default => [:test] @@ -35,19 +66,51 @@ Rake::RDocTask.new('doc') do |rd| rd.rdoc_dir = 'doc' end -# append to the test task so that we can wrap -# Rake::TestTask with a call to start/stop a solr server - -task :test do - start_solr_server -end - -Rake::TestTask.new('test') do |t| - t.pattern = 'test/*_test.rb' +Rake::TestTask.new(:test_units) do |t| + t.pattern = 'test/unit/*_test.rb' t.verbose = true - t.ruby_opts = ['-r solr', '-r test/unit', '-Itest'] + t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/unit'] +end + +Rake::TestTask.new(:test_functionals) do |t| + t.pattern = 'test/functional/*_test.rb' + t.verbose = true + t.ruby_opts = ['-r solr', '-r test/unit', '-Itest/functional'] end task :test do - stop_solr_server + # unit tests don't require a solr server + Rake::Task[:test_units].invoke rescue got_error = true + + # functional tests do + solr_server = TestSolrServer.instance + solr_server.quiet = false if ENV['SOLR_CONSOLE'] + + begin + puts + puts "starting solr server for functional tests" + solr_server.start + sleep 10 + Rake::Task[:test_functionals].invoke + rescue + got_error = true + ensure + puts "stopping solr server" + solr_server.stop + end + + raise "test failures" if got_error end + +# TODO: fix this so it works, it is not happy with connection_test.rb for some reason +# borrowed from here: http://clarkware.com/cgi/blosxom/2007/01/05#RcovRakeTask +namespace :test do + desc 'Measures test coverage' + task :coverage do + rm_f "coverage" + rm_f "coverage.data" + system("rcov --text-summary -Ilib test/unit/*_test.rb") + system("open coverage/index.html") if PLATFORM['darwin'] + end + +end \ No newline at end of file diff --git a/client/ruby/solrb/test/test_helper.rb b/client/ruby/solrb/test/functional/server_test.rb similarity index 53% rename from client/ruby/solrb/test/test_helper.rb rename to client/ruby/solrb/test/functional/server_test.rb index f13e0265939..e387d5ae892 100644 --- a/client/ruby/solrb/test/test_helper.rb +++ b/client/ruby/solrb/test/functional/server_test.rb @@ -10,26 +10,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -def start_solr_server - Dir.chdir(File.dirname(__FILE__) + '/../solr') do - puts "starting solr server" - - # start solr and capture the process ID in a global - $SOLR_PID = fork do - - # don't want to see the messages about solr starting up -# STDERR.close - - exec "java -Djetty.port=8888 -Dsolr.solr.home=../test -jar start.jar" - end +class TestServer < Test::Unit::TestCase + def test_ok + assert_equal true, true end - - # wait for the jvm and solr to start - sleep 10 end - -def stop_solr_server - puts "stopping solr server" - Process.kill('TERM', $SOLR_PID) -end - diff --git a/client/ruby/solrb/test/test_solr_server.rb b/client/ruby/solrb/test/test_solr_server.rb new file mode 100644 index 00000000000..0b40b3ee1eb --- /dev/null +++ b/client/ruby/solrb/test/test_solr_server.rb @@ -0,0 +1,48 @@ +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# 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" + @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 + end diff --git a/client/ruby/solrb/test/connection_test.rb b/client/ruby/solrb/test/unit/connection_test.rb similarity index 100% rename from client/ruby/solrb/test/connection_test.rb rename to client/ruby/solrb/test/unit/connection_test.rb diff --git a/client/ruby/solrb/test/request_test.rb b/client/ruby/solrb/test/unit/request_test.rb similarity index 100% rename from client/ruby/solrb/test/request_test.rb rename to client/ruby/solrb/test/unit/request_test.rb diff --git a/client/ruby/solrb/test/solr_mock_base.rb b/client/ruby/solrb/test/unit/solr_mock_base.rb similarity index 100% rename from client/ruby/solrb/test/solr_mock_base.rb rename to client/ruby/solrb/test/unit/solr_mock_base.rb