mirror of https://github.com/apache/lucene.git
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
This commit is contained in:
parent
47f7ed8e39
commit
5f4e9eed88
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue