Class: Hydra::Testing::TestServer
- Inherits:
-
Object
- Object
- Hydra::Testing::TestServer
- Includes:
- Singleton
- Defined in:
- lib/hydra-testing.rb
Instance Attribute Summary collapse
-
#fedora_home ⇒ Object
Returns the value of attribute fedora_home.
-
#jetty_home ⇒ Object
Returns the value of attribute jetty_home.
-
#port ⇒ Object
Returns the value of attribute port.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#solr_home ⇒ Object
Returns the value of attribute solr_home.
-
#startup_wait ⇒ Object
Returns the value of attribute startup_wait.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ TestServer
constructor
configure the singleton with some defaults.
-
#jetty_command ⇒ Object
end of class << self.
-
#jruby_raise_error? ⇒ Boolean
Not Windows.
-
#platform_specific_start ⇒ Object
start the solr server.
-
#platform_specific_stop ⇒ Object
stop a running solr server.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize ⇒ TestServer
configure the singleton with some defaults
10 11 12 |
# File 'lib/hydra-testing.rb', line 10 def initialize @pid = nil end |
Instance Attribute Details
#fedora_home ⇒ Object
Returns the value of attribute fedora_home.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def fedora_home @fedora_home end |
#jetty_home ⇒ Object
Returns the value of attribute jetty_home.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def jetty_home @jetty_home end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def port @port end |
#quiet ⇒ Object
Returns the value of attribute quiet.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def quiet @quiet end |
#solr_home ⇒ Object
Returns the value of attribute solr_home.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def solr_home @solr_home end |
#startup_wait ⇒ Object
Returns the value of attribute startup_wait.
7 8 9 |
# File 'lib/hydra-testing.rb', line 7 def startup_wait @startup_wait end |
Class Method Details
.configure(params = {}) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/hydra-testing.rb', line 15 def configure(params = {}) hydra_server = self.instance hydra_server.quiet = params[:quiet].nil? ? true : params[:quiet] if defined?(Rails.root) base_path = Rails.root else raise "You must set either RAILS_ROOT or :jetty_home so I know where jetty is" unless params[:jetty_home] end hydra_server.jetty_home = params[:jetty_home] || File.(File.join(base_path, 'jetty')) hydra_server.solr_home = params[:solr_home] || File.join( hydra_server.jetty_home, "solr") hydra_server.fedora_home = params[:fedora_home] || File.join( hydra_server.jetty_home, "fedora","default") hydra_server.port = params[:jetty_port] || 8888 hydra_server.startup_wait = params[:startup_wait] || 5 return hydra_server end |
.wrap(params = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/hydra-testing.rb', line 31 def wrap(params = {}) error = false jetty_server = self.instance jetty_server.quiet = params[:quiet] || true jetty_server.jetty_home = params[:jetty_home] jetty_server.solr_home = params[:solr_home] jetty_server.port = params[:jetty_port] || 8888 jetty_server.startup_wait = params[:startup_wait] || 5 jetty_server.fedora_home = params[:fedora_home] || File.join( jetty_server.jetty_home, "fedora","default") begin # puts "starting jetty on #{RUBY_PLATFORM}" jetty_server.start sleep jetty_server.startup_wait yield rescue error = $! puts "*** Error starting hydra-jetty: #{error}" ensure # puts "stopping jetty server" jetty_server.stop end return error end |
Instance Method Details
#jetty_command ⇒ Object
end of class << self
59 60 61 |
# File 'lib/hydra-testing.rb', line 59 def jetty_command "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -jar start.jar" end |
#jruby_raise_error? ⇒ Boolean
Not Windows
97 98 99 |
# File 'lib/hydra-testing.rb', line 97 def jruby_raise_error? raise 'JRuby requires that you start solr manually, then run "rake spec" or "rake features"' if defined?(JRUBY_VERSION) end |
#platform_specific_start ⇒ Object
start the solr server
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hydra-testing.rb', line 78 def platform_specific_start Dir.chdir(@jetty_home) do @pid = Process.create( :app_name => jetty_command, :creation_flags => Process::DETACHED_PROCESS, :process_inherit => false, :thread_inherit => true, :cwd => "#{@jetty_home}" ).process_id end end |
#platform_specific_stop ⇒ Object
stop a running solr server
91 92 93 94 |
# File 'lib/hydra-testing.rb', line 91 def platform_specific_stop Process.kill(1, @pid) Process.wait end |
#start ⇒ Object
63 64 65 66 67 68 |
# File 'lib/hydra-testing.rb', line 63 def start puts "jetty_home: #{@jetty_home}" puts "solr_home: #{@solr_home}" puts "jetty_command: #{jetty_command}" platform_specific_start end |
#stop ⇒ Object
70 71 72 |
# File 'lib/hydra-testing.rb', line 70 def stop platform_specific_stop end |