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,10 +10,6 @@
|
||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# 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
|
class TestSolrServer
|
||||||
require 'singleton'
|
require 'singleton'
|
||||||
include Singleton
|
include Singleton
|
||||||
|
@ -29,6 +25,47 @@ class TestSolrServer
|
||||||
@pid = nil
|
@pid = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.wrap(params = {})
|
||||||
|
error = false
|
||||||
|
solr_server = self.instance
|
||||||
|
solr_server.quiet = params[:quiet]
|
||||||
|
begin
|
||||||
|
puts "starting solr server on #{RUBY_PLATFORM}"
|
||||||
|
solr_server.start
|
||||||
|
sleep params[:startup_wait] || 5
|
||||||
|
yield
|
||||||
|
rescue
|
||||||
|
error = true
|
||||||
|
ensure
|
||||||
|
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
|
# start the solr server
|
||||||
def start
|
def start
|
||||||
Dir.chdir(@solr_dir) do
|
Dir.chdir(@solr_dir) do
|
||||||
|
@ -45,24 +82,6 @@ class TestSolrServer
|
||||||
Process.kill('TERM', @pid)
|
Process.kill('TERM', @pid)
|
||||||
Process.wait
|
Process.wait
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.wrap(params = {})
|
|
||||||
error = false
|
|
||||||
solr_server = self.instance
|
|
||||||
solr_server.quiet = params[:quiet]
|
|
||||||
begin
|
|
||||||
puts "starting solr server"
|
|
||||||
solr_server.start
|
|
||||||
sleep params[:startup_wait] || 5
|
|
||||||
yield
|
|
||||||
rescue
|
|
||||||
error = true
|
|
||||||
ensure
|
|
||||||
puts "stopping solr server"
|
|
||||||
solr_server.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
return error
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue