Skip to content

Apache Lucene open-source search software

SOLR-94: start Solr before tests are run, shut it down afterwards (contributed by Ed Summers). Original patch modified slightly to set the Jetty port to 8888

Erik Hatcher7641746534ac
diff --git a/client/ruby/solrb/Rakefile b/client/ruby/solrb/Rakefile
index 7c1d71e76f6..f420ff17b6d 100644
--- a/client/ruby/solrb/Rakefile
+++ b/client/ruby/solrb/Rakefile
@@ -6,16 +6,10 @@ require 'rake/testtask'
require 'rake/rdoctask'
require 'rake/packagetask'
require 'rake/gempackagetask'
+require 'test/solr_server.rb'
task :default => [:test]
-Rake::TestTask.new('test') do |t|
- t.libs << 'lib'
- t.pattern = 'test/*_test.rb'
- t.verbose = true
- t.ruby_opts = ['-r solr', '-r test/unit']
-end
-
spec = Gem::Specification.new do |s|
s.name = 'solr'
s.version = SOLRB_VERSION
@@ -28,9 +22,6 @@ spec = Gem::Specification.new do |s|
s.require_path = 'lib'
s.autorequire = 'solr'
s.has_rdoc = true
-
-# s.test_file = 'test/ts_solr.rb'
-# s.bindir = 'bin'
end
Rake::GemPackageTask.new(spec) do |pkg|
@@ -43,3 +34,20 @@ Rake::RDocTask.new('doc') do |rd|
rd.main = 'Solr::Connection'
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
+end
+
+Rake::TestTask.new('test') do |t|
+ t.pattern = 'test/*_test.rb'
+ t.verbose = true
+ t.ruby_opts = ['-r solr', '-r test/unit']
+end
+
+task :test do
+ stop_solr
+end
diff --git a/client/ruby/solrb/test/solr_server.rb b/client/ruby/solrb/test/solr_server.rb
new file mode 100644
index 00000000000..6f21fd69a20
--- /dev/null
+++ b/client/ruby/solrb/test/solr_server.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/ruby
+
+# TODO: would be nice to be able to start up
+# solr on another port than the default one
+# so we don't interfere with one that's currently
+# running.
+
+def start_solr
+ Dir.chdir(File.dirname(__FILE__) + '/../solr') do
+ puts "starting solr server"
+
+ # subprocess to run our solr server
+ $SOLR_PID = fork do
+
+ # dissassociate from the process group for the unit tests
+ Process.setsid
+
+ # don't want to see the messages about solr starting up
+ STDERR.close
+
+ # start 'er up
+ system 'java -Djetty.port=8888 -jar start.jar'
+ end
+ end
+
+ # wait for the jvm and solr to start
+ sleep 5
+end
+
+def stop_solr
+ puts "stopping solr server"
+ # stop all the processes we can by terminating the group
+ process_group_id = Process.getpgid($SOLR_PID)
+ Process.kill(-15, process_group_id)
+end
+
+if __FILE__ == $0
+ start_solr
+ stop_solr
+end
+