jettywrapper 0.0.10 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
+ *.sw[po]
2
3
  .bundle
3
4
  Gemfile.lock
4
5
  pkg/*
data/.gitmodules CHANGED
@@ -1,6 +1,3 @@
1
- [submodule "jetty1"]
2
- path = jetty1
3
- url = git://github.com/projecthydra/hydra-jetty.git
4
- [submodule "jetty2"]
5
- path = jetty2
1
+ [submodule "jetty"]
2
+ path = jetty
6
3
  url = git://github.com/projecthydra/hydra-jetty.git
data/config/jetty.yml ADDED
@@ -0,0 +1,4 @@
1
+ jetty_port: 8983
2
+ java_opts:
3
+ - "-Xmx128mb"
4
+
data/jettywrapper.gemspec CHANGED
@@ -21,17 +21,15 @@ Gem::Specification.new do |s|
21
21
 
22
22
  s.add_dependency "logger"
23
23
  s.add_dependency "mediashelf-loggable"
24
+ s.add_dependency "childprocess"
25
+ s.add_dependency "i18n"
26
+ s.add_dependency "activesupport", ">=3.0.0"
24
27
 
25
28
  # Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
26
29
  # It will not add these as dependencies if you require lyber-core for other projects
27
30
  s.add_development_dependency "ruby-debug"
28
- s.add_development_dependency "ruby-debug-base"
29
31
  s.add_development_dependency "rspec", "< 2.0" # We're not ready to upgrade to rspec 2
30
- s.add_development_dependency 'rspec-rails', '<2.0.0' # rspec-rails 2.0.0 requires Rails 3.
31
32
  s.add_development_dependency 'mocha'
32
- s.add_development_dependency 'cucumber', '>=0.8.5'
33
- s.add_development_dependency 'cucumber-rails'
34
- s.add_development_dependency 'gherkin'
35
33
  s.add_development_dependency 'rcov'
36
34
 
37
35
  s.add_development_dependency 'yard', '0.6.5' # Yard > 0.6.5 won't generate docs.
data/lib/jettywrapper.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
2
- require 'rubygems'
3
- require 'logger'
2
+ #require 'logger'
4
3
  require 'loggable'
5
4
  require 'singleton'
6
5
  require 'ftools'
7
6
  require 'socket'
8
7
  require 'timeout'
9
- require 'ruby-debug'
8
+ require 'childprocess'
9
+ require 'active_support/core_ext/hash'
10
+
11
+ Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
12
+
10
13
 
11
14
  class Jettywrapper
12
15
 
@@ -19,49 +22,71 @@ class Jettywrapper
19
22
  attr_accessor :startup_wait # After jetty starts, how long to wait until starting the tests?
20
23
  attr_accessor :quiet # Keep quiet about jetty output?
21
24
  attr_accessor :solr_home # Where is solr located? Default is jetty_home/solr
22
- attr_accessor :fedora_home # Where is fedora located? Default is jetty_home/fedora
23
- attr_accessor :logger # Where should logs be written?
24
25
  attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
26
+ attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
25
27
 
26
28
  # configure the singleton with some defaults
27
29
  def initialize(params = {})
28
- # @pid = nil
29
30
  if defined?(Rails.root)
30
31
  @base_path = Rails.root
31
32
  else
32
33
  @base_path = "."
33
34
  end
34
- @logger = Logger.new(STDERR)
35
- @logger.debug 'Initializing jettywrapper'
35
+
36
+ logger.debug 'Initializing jettywrapper'
36
37
  end
37
38
 
38
39
  # Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
39
40
  # Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
40
41
  class << self
41
42
 
43
+ def load_config
44
+ if defined? Rails
45
+ config_name = Rails.env
46
+ app_root = Rails.root
47
+ else
48
+ config_name = ENV['environment']
49
+ app_root = ENV['APP_ROOT']
50
+ app_root ||= '.'
51
+ end
52
+ filename = "#{app_root}/config/jetty.yml"
53
+ begin
54
+ file = YAML.load_file(filename)
55
+ rescue Exception => e
56
+ logger.warn "Didn't find expected jettywrapper config file at #{filename}, using default file instead."
57
+ file ||= YAML.load_file(File.join(File.dirname(__FILE__),"../config/jetty.yml"))
58
+ #raise "Unable to load: #{file}" unless file
59
+ end
60
+ file.with_indifferent_access
61
+ end
62
+
63
+
42
64
  # Set the jetty parameters. It accepts a Hash of symbols.
43
65
  # @param [Hash<Symbol>] params
44
66
  # @param [Symbol] :jetty_home Required. Where is jetty located?
45
67
  # @param [Symbol] :jetty_port What port should jetty start on? Default is 8888
46
68
  # @param [Symbol] :startup_wait After jetty starts, how long to wait before running tests? If you don't let jetty start all the way before running the tests, they'll fail because they can't reach jetty.
47
69
  # @param [Symbol] :solr_home Where is solr? Default is jetty_home/solr
48
- # @param [Symbol] :fedora_home Where is fedora? Default is jetty_home/fedora/default
49
70
  # @param [Symbol] :quiet Keep quiet about jetty output? Default is true.
71
+ # @param [Symbol] :java_opts A list of options to pass to the jvm
50
72
  def configure(params = {})
51
73
  hydra_server = self.instance
52
74
  hydra_server.quiet = params[:quiet].nil? ? true : params[:quiet]
53
75
  if defined?(Rails.root)
54
76
  base_path = Rails.root
77
+ elsif defined?(APP_ROOT)
78
+ base_path = APP_ROOT
55
79
  else
56
- raise "You must set either RAILS_ROOT or :jetty_home so I know where jetty is" unless params[:jetty_home]
80
+ raise "You must set either Rails.root, APP_ROOT or pass :jetty_home as a parameter so I know where jetty is" unless params[:jetty_home]
57
81
  end
58
82
  hydra_server.jetty_home = params[:jetty_home] || File.expand_path(File.join(base_path, 'jetty'))
59
83
  hydra_server.solr_home = params[:solr_home] || File.join( hydra_server.jetty_home, "solr")
60
- hydra_server.fedora_home = params[:fedora_home] || File.join( hydra_server.jetty_home, "fedora","default")
61
84
  hydra_server.port = params[:jetty_port] || 8888
62
85
  hydra_server.startup_wait = params[:startup_wait] || 5
86
+ hydra_server.java_opts = params[:java_opts] || []
63
87
  return hydra_server
64
88
  end
89
+
65
90
 
66
91
  # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
67
92
  # jetty, and return the error.
@@ -83,13 +108,13 @@ class Jettywrapper
83
108
  # end
84
109
  def wrap(params)
85
110
  error = false
86
- jetty_server = self.instance
87
- jetty_server.quiet = params[:quiet] || true
88
- jetty_server.jetty_home = params[:jetty_home]
89
- jetty_server.solr_home = params[:solr_home]
90
- jetty_server.port = params[:jetty_port] || 8888
91
- jetty_server.startup_wait = params[:startup_wait] || 5
92
- jetty_server.fedora_home = params[:fedora_home] || File.join( jetty_server.jetty_home, "fedora","default")
111
+ jetty_server = self.configure(params)
112
+ # jetty_server = self.instance
113
+ # jetty_server.quiet = params[:quiet] || true
114
+ # jetty_server.jetty_home = params[:jetty_home]
115
+ # jetty_server.solr_home = params[:solr_home]
116
+ # jetty_server.port = params[:jetty_port] || 8888
117
+ # jetty_server.startup_wait = params[:startup_wait] || 5
93
118
 
94
119
  begin
95
120
  # puts "starting jetty on #{RUBY_PLATFORM}"
@@ -192,9 +217,15 @@ class Jettywrapper
192
217
 
193
218
  # What command is being run to invoke jetty?
194
219
  def jetty_command
195
- "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -Dfedora.home=#{@fedora_home} -jar start.jar"
220
+ opts = (java_variables + java_opts).join(' ')
221
+ "java #{opts} -jar start.jar"
196
222
  end
197
-
223
+
224
+ def java_variables
225
+ ["-Djetty.port=#{@port}",
226
+ "-Dsolr.solr.home=#{@solr_home}"]
227
+ end
228
+
198
229
  # Start the jetty server. Check the pid file to see if it is running already,
199
230
  # and stop it if so. After you start jetty, write the PID to a file.
200
231
  # This is the instance start method. It must be called on Jettywrapper.instance
@@ -204,11 +235,10 @@ class Jettywrapper
204
235
  # Jettywrapper.instance.start
205
236
  # return Jettywrapper.instance
206
237
  def start
207
- @logger.debug "Starting jetty with these values: "
208
- @logger.debug "jetty_home: #{@jetty_home}"
209
- @logger.debug "solr_home: #{@solr_home}"
210
- @logger.debug "fedora_home: #{@fedora_home}"
211
- @logger.debug "jetty_command: #{jetty_command}"
238
+ logger.debug "Starting jetty with these values: "
239
+ logger.debug "jetty_home: #{@jetty_home}"
240
+ logger.debug "solr_home: #{@solr_home}"
241
+ logger.debug "jetty_command: #{jetty_command}"
212
242
 
213
243
  # Check to see if we can start.
214
244
  # 1. If there is a pid, check to see if it is really running
@@ -217,7 +247,7 @@ class Jettywrapper
217
247
  if Jettywrapper.is_pid_running?(pid)
218
248
  raise("Server is already running with PID #{pid}")
219
249
  else
220
- @logger.warn "Removing stale PID file at #{pid_path}"
250
+ logger.warn "Removing stale PID file at #{pid_path}"
221
251
  File.delete(pid_path)
222
252
  end
223
253
  if Jettywrapper.is_port_in_use?(@jetty_port)
@@ -225,7 +255,8 @@ class Jettywrapper
225
255
  end
226
256
  end
227
257
  Dir.chdir(@jetty_home) do
228
- self.send "#{platform}_process".to_sym
258
+ process = build_process
259
+ @pid = process.pid
229
260
  end
230
261
  File.makedirs(pid_dir) unless File.directory?(pid_dir)
231
262
  begin
@@ -235,9 +266,15 @@ class Jettywrapper
235
266
  end
236
267
  f.puts "#{@pid}"
237
268
  f.close
238
- @logger.debug "Wrote pid file to #{pid_path} with value #{@pid}"
269
+ logger.debug "Wrote pid file to #{pid_path} with value #{@pid}"
239
270
  end
240
271
 
272
+ def build_process
273
+ process = ChildProcess.build(jetty_command)
274
+ process.io.inherit!
275
+ process.detach = true
276
+ process.start
277
+ end
241
278
  # Instance stop method. Must be called on Jettywrapper.instance
242
279
  # You're probably better off using Jettywrapper.stop(:jetty_home => "/path/to/jetty")
243
280
  # @example
@@ -245,13 +282,12 @@ class Jettywrapper
245
282
  # Jettywrapper.instance.stop
246
283
  # return Jettywrapper.instance
247
284
  def stop
248
- @logger.debug "Instance stop method called for pid #{pid}"
285
+ logger.debug "Instance stop method called for pid #{pid}"
249
286
  if pid
250
- begin
251
- self.send "#{platform}_stop".to_sym
252
- rescue Errno::ESRCH
253
- @logger.error "I tried to kill the process #{pid} but it seems it wasn't running."
254
- end
287
+ process = ChildProcess.new
288
+ process.instance_variable_set(:@pid, pid)
289
+ process.instance_variable_set(:@started, true)
290
+ process.stop
255
291
  begin
256
292
  File.delete(pid_path)
257
293
  rescue
@@ -259,58 +295,6 @@ class Jettywrapper
259
295
  end
260
296
  end
261
297
 
262
- # Spawn a process on windows
263
- def win_process
264
- @pid = Process.create(
265
- :app_name => jetty_command,
266
- :creation_flags => Process::DETACHED_PROCESS,
267
- :process_inherit => false,
268
- :thread_inherit => true,
269
- :cwd => "#{@jetty_home}"
270
- ).process_id
271
- end
272
-
273
- # Determine whether we're running on windows or unix. We need to know this so
274
- # we know how to start and stop processes.
275
- def platform
276
- case RUBY_PLATFORM
277
- when /mswin32/
278
- return 'win'
279
- else
280
- return 'nix'
281
- end
282
- end
283
-
284
- def nix_process
285
- @pid = fork do
286
- # STDERR.close if @quiet
287
- exec jetty_command
288
- end
289
- end
290
-
291
- # stop jetty the windows way
292
- def win_stop
293
- Process.kill(1, pid)
294
- end
295
-
296
- # stop jetty the *nix way
297
- def nix_stop
298
- @logger.debug "Attempting to kill process id #{pid}."
299
- return nil if pid == nil
300
- begin
301
- pid_keeper = pid
302
- # Try to kill the process a few times to make sure it dies
303
- 3.times do
304
- Process.kill(9,pid)
305
- break if Jettywrapper.is_pid_running?(pid_keeper)==false
306
- sleep 2
307
- end
308
- FileUtils.rm(pid_path)
309
- rescue Errno::ESRCH
310
- @logger.debug "I tried to kill #{pid_keeper} but it appears it wasn't running."
311
- FileUtils.rm(pid_path)
312
- end
313
- end
314
298
 
315
299
  # The fully qualified path to the pid_file
316
300
  def pid_path
@@ -352,4 +336,4 @@ class Jettywrapper
352
336
  File.open( pid_path ) { |f| return f.gets.to_i } if File.exist?(pid_path)
353
337
  end
354
338
 
355
- end
339
+ end
@@ -1 +1 @@
1
- GEMVERSION = "0.0.10"
1
+ GEMVERSION = "1.0.0"
@@ -0,0 +1,44 @@
1
+ ## These tasks get loaded into the host application when jettywrapper is required
2
+ require 'yaml'
3
+
4
+ namespace :jetty do
5
+
6
+ desc "Return the status of jetty"
7
+ task :status => :environment do
8
+ status = Jettywrapper.is_jetty_running?(JETTY_CONFIG) ? "Running: #{Jettywrapper.pid(JETTY_CONFIG)}" : "Not running"
9
+ puts status
10
+ end
11
+
12
+ desc "Start jetty"
13
+ task :start => :environment do
14
+ Jettywrapper.start(JETTY_CONFIG)
15
+ puts "jetty started at PID #{Jettywrapper.pid(JETTY_CONFIG)}"
16
+ end
17
+
18
+ desc "stop jetty"
19
+ task :stop => :environment do
20
+ Jettywrapper.stop(JETTY_CONFIG)
21
+ puts "jetty stopped"
22
+ end
23
+
24
+ desc "Restarts jetty"
25
+ task :restart do
26
+ Jettywrapper.stop(JETTY_CONFIG)
27
+ Jettywrapper.start(JETTY_CONFIG)
28
+ end
29
+
30
+
31
+ desc "Load the jetty config"
32
+ task :environment do
33
+ unless defined? JETTY_CONFIG
34
+ JETTY_CONFIG = Jettywrapper.load_config
35
+ end
36
+ end
37
+
38
+ end
39
+
40
+ namespace :repo do
41
+
42
+
43
+
44
+ end
@@ -14,7 +14,7 @@ module Hydra
14
14
 
15
15
  it "starts" do
16
16
  jetty_params = {
17
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
17
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
18
18
  }
19
19
  Jettywrapper.configure(jetty_params)
20
20
  ts = Jettywrapper.instance
@@ -28,7 +28,7 @@ module Hydra
28
28
 
29
29
  # Can we connect to solr?
30
30
  require 'net/http'
31
- response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
31
+ response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/development/admin/"))
32
32
  response.code.should eql("200")
33
33
  ts.stop
34
34
 
@@ -36,7 +36,7 @@ module Hydra
36
36
 
37
37
  it "won't start if it's already running" do
38
38
  jetty_params = {
39
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
39
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
40
40
  }
41
41
  Jettywrapper.configure(jetty_params)
42
42
  ts = Jettywrapper.instance
@@ -45,7 +45,7 @@ module Hydra
45
45
  ts.start
46
46
  sleep 30
47
47
  ts.logger.debug "Jetty started from rspec at #{ts.pid}"
48
- response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/admin/"))
48
+ response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/development/admin/"))
49
49
  response.code.should eql("200")
50
50
  lambda { ts.start }.should raise_exception(/Server is already running/)
51
51
  ts.stop
@@ -53,7 +53,7 @@ module Hydra
53
53
 
54
54
  it "can check to see whether a port is already in use" do
55
55
  params = {
56
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
56
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
57
57
  :jetty_port => '9999'
58
58
  }
59
59
  Jettywrapper.stop(params)
@@ -65,50 +65,9 @@ module Hydra
65
65
  Jettywrapper.stop(params)
66
66
  end
67
67
 
68
- # I'm commenting out this test b/c it keeps messing up the hudson server. For some
69
- # reason, when I spin up two copies at the same time, one of them won't shut down.
70
- # It runs fine on my local machine, and all of the individual commands work fine when
71
- # issued separately.
72
- #
73
- # it "can start multiple copies of jetty, as long as they have different jetty_homes" do
74
- # jetty1_params = {
75
- # :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
76
- # :jetty_port => '8983'
77
- # }
78
- # jetty2_params = {
79
- # :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty2"),
80
- # :jetty_port => '8984'
81
- # }
82
- #
83
- # # Ensure nothing is running when we start
84
- # Jettywrapper.stop(jetty1_params)
85
- # Jettywrapper.stop(jetty2_params)
86
- #
87
- # # Spin up two copies of jetty, with different jetty home values and on different ports
88
- # Jettywrapper.start(jetty1_params)
89
- # pid1 = Jettywrapper.pid(jetty1_params)
90
- # Jettywrapper.start(jetty2_params)
91
- # pid2 = Jettywrapper.pid(jetty2_params)
92
- #
93
- # # Ensure both are viable
94
- # sleep 40
95
- # response1 = Net::HTTP.get_response(URI.parse("http://localhost:8983/solr/admin/"))
96
- # response1.code.should eql("200")
97
- # response2 = Net::HTTP.get_response(URI.parse("http://localhost:8984/solr/admin/"))
98
- # response2.code.should eql("200")
99
- #
100
- # # Shut them both down
101
- # Jettywrapper.pid(jetty1_params).should eql(pid1)
102
- # Jettywrapper.stop(jetty1_params)
103
- # Jettywrapper.is_pid_running?(pid1).should eql(false)
104
- # Jettywrapper.pid(jetty2_params).should eql(pid2)
105
- # Jettywrapper.stop(jetty2_params)
106
- # Jettywrapper.is_pid_running?(pid2).should eql(false)
107
- # end
108
-
109
68
  it "raises an error if you try to start a jetty that is already running" do
110
69
  jetty_params = {
111
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
70
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
112
71
  :jetty_port => '8983'
113
72
  }
114
73
  ts = Jettywrapper.configure(jetty_params)
@@ -120,30 +79,8 @@ module Hydra
120
79
  ts.stop
121
80
  end
122
81
 
123
- # Not ready for this yet
124
- # it "won't start if there is a port conflict" do
125
- # jetty1_params = {
126
- # :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1"),
127
- # :jetty_port => '8983'
128
- # }
129
- # jetty2_params = {
130
- # :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty2"),
131
- # :jetty_port => '8983'
132
- # }
133
- # # Ensure nothing is running when we start
134
- # Jettywrapper.stop(jetty1_params)
135
- # Jettywrapper.stop(jetty2_params)
136
- #
137
- # # Spin up two copies of jetty, with different jetty home values but the same port
138
- # Jettywrapper.start(jetty1_params)
139
- # lambda{ Jettywrapper.start(jetty2_params) }.should raise_exception
140
- #
141
- # # Shut them both down
142
- # Jettywrapper.stop(jetty1_params)
143
- # Jettywrapper.stop(jetty2_params)
144
- # end
145
82
 
146
83
  end
147
84
 
148
85
  end
149
- end
86
+ end
@@ -14,8 +14,8 @@ module Hydra
14
14
  :jetty_home => "/path/to/jetty",
15
15
  :jetty_port => 8888,
16
16
  :solr_home => "/path/to/solr",
17
- :fedora_home => "/path/to/fedora",
18
- :startup_wait => 0
17
+ :startup_wait => 0,
18
+ :java_opts => ["-Xmx256mb"]
19
19
  }
20
20
  end
21
21
 
@@ -31,7 +31,6 @@ module Hydra
31
31
  ts.jetty_home.should == "/path/to/jetty"
32
32
  ts.port.should == 8888
33
33
  ts.solr_home.should == '/path/to/solr'
34
- ts.fedora_home.should == '/path/to/fedora'
35
34
  ts.startup_wait.should == 0
36
35
  end
37
36
 
@@ -46,7 +45,6 @@ module Hydra
46
45
  :jetty_home => '/path/to/jetty',
47
46
  :jetty_port => nil,
48
47
  :solr_home => nil,
49
- :fedora_home => nil,
50
48
  :startup_wait => nil
51
49
  }
52
50
 
@@ -55,16 +53,15 @@ module Hydra
55
53
  ts.jetty_home.should == "/path/to/jetty"
56
54
  ts.port.should == 8888
57
55
  ts.solr_home.should == File.join(ts.jetty_home, "solr")
58
- ts.fedora_home.should == File.join(ts.jetty_home, "fedora","default")
59
56
  ts.startup_wait.should == 5
60
57
  end
61
58
 
62
59
  it "passes all the expected values to jetty during startup" do
63
60
  ts = Jettywrapper.configure(@jetty_params)
64
61
  command = ts.jetty_command
65
- command.should include("-Dfedora.home=#{@jetty_params[:fedora_home]}")
66
62
  command.should include("-Dsolr.solr.home=#{@jetty_params[:solr_home]}")
67
63
  command.should include("-Djetty.port=#{@jetty_params[:jetty_port]}")
64
+ command.should include("-Xmx256mb")
68
65
 
69
66
  end
70
67
 
@@ -73,7 +70,7 @@ module Hydra
73
70
  :jetty_home => '/tmp'
74
71
  }
75
72
  ts = Jettywrapper.configure(jetty_params)
76
- Jettywrapper.any_instance.stubs(:fork).returns(5454)
73
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>5454))
77
74
  ts.stop
78
75
  ts.start
79
76
  ts.pid.should eql(5454)
@@ -86,7 +83,7 @@ module Hydra
86
83
  }
87
84
  ts = Jettywrapper.configure(jetty_params)
88
85
  ts.stop
89
- Jettywrapper.any_instance.stubs(:fork).returns(2323)
86
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2323))
90
87
  swp = Jettywrapper.start(jetty_params)
91
88
  swp.pid.should eql(2323)
92
89
  swp.pid_file.should eql("_tmp.pid")
@@ -100,10 +97,10 @@ module Hydra
100
97
  # return true if it's running, otherwise return false
101
98
  it "can get the status for a given jetty instance" do
102
99
  # Don't actually start jetty, just fake it
103
- Jettywrapper.any_instance.stubs(:fork).returns(12345)
100
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>12345))
104
101
 
105
102
  jetty_params = {
106
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
103
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
107
104
  }
108
105
  Jettywrapper.stop(jetty_params)
109
106
  Jettywrapper.is_jetty_running?(jetty_params).should eql(false)
@@ -114,9 +111,9 @@ module Hydra
114
111
 
115
112
  it "can get the pid for a given jetty instance" do
116
113
  # Don't actually start jetty, just fake it
117
- Jettywrapper.any_instance.stubs(:fork).returns(54321)
114
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>54321))
118
115
  jetty_params = {
119
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty1")
116
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
120
117
  }
121
118
  Jettywrapper.stop(jetty_params)
122
119
  Jettywrapper.pid(jetty_params).should eql(nil)
@@ -129,7 +126,7 @@ module Hydra
129
126
  jetty_params = {
130
127
  :jetty_home => '/tmp', :jetty_port => 8777
131
128
  }
132
- Jettywrapper.any_instance.stubs(:fork).returns(2323)
129
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2323))
133
130
  swp = Jettywrapper.start(jetty_params)
134
131
  (File.file? swp.pid_path).should eql(true)
135
132
 
@@ -152,7 +149,7 @@ module Hydra
152
149
  :jetty_home => '/tmp'
153
150
  }
154
151
  ts = Jettywrapper.configure(jetty_params)
155
- Jettywrapper.any_instance.stubs(:fork).returns(2222)
152
+ Jettywrapper.any_instance.stubs(:build_process).returns(stub('proc', :pid=>2222))
156
153
  ts.stop
157
154
  ts.pid_file?.should eql(false)
158
155
  ts.start
@@ -190,7 +187,6 @@ module Hydra
190
187
  ts.jetty_home.should == "/path/to/jetty"
191
188
  ts.port.should == 8888
192
189
  ts.solr_home.should == "/path/to/solr"
193
- ts.fedora_home.should == "/path/to/fedora"
194
190
  ts.startup_wait.should == 0
195
191
  end
196
192
  error.should eql(false)
@@ -208,4 +204,4 @@ module Hydra
208
204
 
209
205
  end # end of wrapping context
210
206
  end
211
- end
207
+ end
@@ -5,132 +5,87 @@ require 'jettywrapper'
5
5
 
6
6
  namespace :jettywrapper do
7
7
 
8
- jetty1 = {
9
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty1"),
10
- :jetty_port => "8983"
8
+ jetty = {
9
+ :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty"),
10
+ :jetty_port => "8983", :java_opts=>["-Xmx128mb"]
11
11
  }
12
12
 
13
- jetty2 = {
14
- :jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../jetty2"),
15
- :jetty_port => "8984"
16
- }
17
-
18
- namespace :status do
19
-
20
- desc "Return the status of jetty1"
21
- task :jetty1 do
22
- status = Jettywrapper.is_jetty_running?(jetty1) ? "Running: #{Jettywrapper.pid(jetty1)}" : "Not running"
23
- puts status
24
- end
25
-
26
- desc "Return the status of jetty2"
27
- task :jetty2 do
28
- status = Jettywrapper.is_jetty_running?(jetty2) ? "Running: #{Jettywrapper.pid(jetty2)}" : "Not running"
29
- puts status
30
- end
31
-
13
+ desc "Return the status of jetty"
14
+ task :status do
15
+ status = Jettywrapper.is_jetty_running?(jetty) ? "Running: #{Jettywrapper.pid(jetty)}" : "Not running"
16
+ puts status
32
17
  end
33
18
 
34
- namespace :start do
35
-
36
- desc "Start jetty1"
37
- task :jetty1 do
38
- Jettywrapper.start(jetty1)
39
- puts "jetty1 started at PID #{Jettywrapper.pid(jetty1)}"
40
- end
41
-
42
- desc "Start jetty2"
43
- task :jetty2 do
44
- Jettywrapper.start(jetty2)
45
- puts "jetty2 started at PID #{Jettywrapper.pid(jetty2)}"
46
- end
47
-
19
+ desc "Start jetty"
20
+ task :start do
21
+ Jettywrapper.start(jetty)
22
+ puts "jetty started at PID #{Jettywrapper.pid(jetty)}"
48
23
  end
49
24
 
50
- namespace :stop do
51
-
52
- desc "stop jetty1"
53
- task :jetty1 do
54
- Jettywrapper.stop(jetty1)
55
- puts "jetty1 stopped"
56
- end
57
-
58
- desc "stop jetty2"
59
- task :jetty2 do
60
- Jettywrapper.stop(jetty2)
61
- puts "jetty2 stopped"
62
- end
63
-
25
+ desc "stop jetty"
26
+ task :stop do
27
+ Jettywrapper.stop(jetty)
28
+ puts "jetty stopped"
64
29
  end
65
30
 
66
- namespace :restart do
67
-
68
- desc "Restarts jetty1"
69
- task :jetty1 do
70
- Jettywrapper.stop(jetty1)
71
- Jettywrapper.start(jetty1)
72
- end
73
-
74
- desc "Restarts jetty2"
75
- task :jetty2 do
76
- Jettywrapper.stop(jetty2)
77
- Jettywrapper.start(jetty2)
78
- end
79
-
31
+ desc "Restarts jetty"
32
+ task :restart do
33
+ Jettywrapper.stop(jetty)
34
+ Jettywrapper.start(jetty)
80
35
  end
81
36
 
82
- desc "Init Hydra configuration"
83
- task :init => [:environment] do
84
- if !ENV["environment"].nil?
85
- RAILS_ENV = ENV["environment"]
86
- end
87
-
88
- JETTY_HOME_TEST = File.expand_path(File.dirname(__FILE__) + '/../../jetty-test')
89
- JETTY_HOME_DEV = File.expand_path(File.dirname(__FILE__) + '/../../jetty-dev')
90
-
91
- JETTY_PARAMS_TEST = {
92
- :quiet => ENV['HYDRA_CONSOLE'] ? false : true,
93
- :jetty_home => JETTY_HOME_TEST,
94
- :jetty_port => 8983,
95
- :solr_home => File.expand_path(JETTY_HOME_TEST + '/solr'),
96
- :fedora_home => File.expand_path(JETTY_HOME_TEST + '/fedora/default')
97
- }
98
-
99
- JETTY_PARAMS_DEV = {
100
- :quiet => ENV['HYDRA_CONSOLE'] ? false : true,
101
- :jetty_home => JETTY_HOME_DEV,
102
- :jetty_port => 8984,
103
- :solr_home => File.expand_path(JETTY_HOME_DEV + '/solr'),
104
- :fedora_home => File.expand_path(JETTY_HOME_DEV + '/fedora/default')
105
- }
106
-
107
- # If Fedora Repository connection is not already initialized, initialize it using ActiveFedora defaults
108
- ActiveFedora.init unless Thread.current[:repo]
37
+ desc "Init Hydra configuration"
38
+ task :init => [:environment] do
39
+ if !ENV["environment"].nil?
40
+ RAILS_ENV = ENV["environment"]
109
41
  end
42
+
43
+ JETTY_HOME_TEST = File.expand_path(File.dirname(__FILE__) + '/../../jetty-test')
44
+ JETTY_HOME_DEV = File.expand_path(File.dirname(__FILE__) + '/../../jetty-dev')
45
+
46
+ JETTY_PARAMS_TEST = {
47
+ :quiet => ENV['HYDRA_CONSOLE'] ? false : true,
48
+ :jetty_home => JETTY_HOME_TEST,
49
+ :jetty_port => 8983,
50
+ :solr_home => File.expand_path(JETTY_HOME_TEST + '/solr'),
51
+ :fedora_home => File.expand_path(JETTY_HOME_TEST + '/fedora/default')
52
+ }
110
53
 
111
- desc "Copies the default SOLR config for the bundled jetty"
112
- task :config_solr => [:init] do
113
- FileList['solr/conf/*'].each do |f|
114
- cp("#{f}", JETTY_PARAMS_TEST[:solr_home] + '/conf/', :verbose => true)
115
- cp("#{f}", JETTY_PARAMS_DEV[:solr_home] + '/conf/', :verbose => true)
116
- end
117
- end
54
+ JETTY_PARAMS_DEV = {
55
+ :quiet => ENV['HYDRA_CONSOLE'] ? false : true,
56
+ :jetty_home => JETTY_HOME_DEV,
57
+ :jetty_port => 8984,
58
+ :solr_home => File.expand_path(JETTY_HOME_DEV + '/solr'),
59
+ :fedora_home => File.expand_path(JETTY_HOME_DEV + '/fedora/default')
60
+ }
118
61
 
119
- desc "Copies a custom fedora config for the bundled jetty"
120
- task :config_fedora => [:init] do
121
- fcfg = 'fedora/conf/fedora.fcfg'
122
- if File.exists?(fcfg)
123
- puts "copying over fedora.fcfg"
124
- cp("#{fcfg}", JETTY_PARAMS_TEST[:fedora_home] + '/server/config/', :verbose => true)
125
- cp("#{fcfg}", JETTY_PARAMS_DEV[:fedora_home] + '/server/config/', :verbose => true)
126
- else
127
- puts "#{fcfg} file not found -- skipping fedora config"
128
- end
62
+ # If Fedora Repository connection is not already initialized, initialize it using ActiveFedora defaults
63
+ ActiveFedora.init unless Thread.current[:repo]
64
+ end
65
+
66
+ desc "Copies the default SOLR config for the bundled jetty"
67
+ task :config_solr => [:init] do
68
+ FileList['solr/conf/*'].each do |f|
69
+ cp("#{f}", JETTY_PARAMS_TEST[:solr_home] + '/conf/', :verbose => true)
70
+ cp("#{f}", JETTY_PARAMS_DEV[:solr_home] + '/conf/', :verbose => true)
129
71
  end
130
-
131
- desc "Copies the default Solr & Fedora configs into the bundled jetty"
132
- task :config do
133
- Rake::Task["hydra:jetty:config_fedora"].invoke
134
- Rake::Task["hydra:jetty:config_solr"].invoke
72
+ end
73
+
74
+ desc "Copies a custom fedora config for the bundled jetty"
75
+ task :config_fedora => [:init] do
76
+ fcfg = 'fedora/conf/fedora.fcfg'
77
+ if File.exists?(fcfg)
78
+ puts "copying over fedora.fcfg"
79
+ cp("#{fcfg}", JETTY_PARAMS_TEST[:fedora_home] + '/server/config/', :verbose => true)
80
+ cp("#{fcfg}", JETTY_PARAMS_DEV[:fedora_home] + '/server/config/', :verbose => true)
81
+ else
82
+ puts "#{fcfg} file not found -- skipping fedora config"
135
83
  end
136
- end
84
+ end
85
+
86
+ desc "Copies the default Solr & Fedora configs into the bundled jetty"
87
+ task :config do
88
+ Rake::Task["hydra:jetty:config_fedora"].invoke
89
+ Rake::Task["hydra:jetty:config_solr"].invoke
90
+ end
91
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jettywrapper
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
+ - 1
7
8
  - 0
8
9
  - 0
9
- - 10
10
- version: 0.0.10
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bess Sadler
@@ -15,10 +15,13 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-15 00:00:00 -07:00
18
+ date: 2011-10-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
+ name: logger
23
+ type: :runtime
24
+ prerelease: false
22
25
  version_requirements: &id001 !ruby/object:Gem::Requirement
23
26
  none: false
24
27
  requirements:
@@ -29,10 +32,10 @@ dependencies:
29
32
  - 0
30
33
  version: "0"
31
34
  requirement: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: mediashelf-loggable
32
37
  type: :runtime
33
- name: logger
34
38
  prerelease: false
35
- - !ruby/object:Gem::Dependency
36
39
  version_requirements: &id002 !ruby/object:Gem::Requirement
37
40
  none: false
38
41
  requirements:
@@ -43,10 +46,10 @@ dependencies:
43
46
  - 0
44
47
  version: "0"
45
48
  requirement: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: childprocess
46
51
  type: :runtime
47
- name: mediashelf-loggable
48
52
  prerelease: false
49
- - !ruby/object:Gem::Dependency
50
53
  version_requirements: &id003 !ruby/object:Gem::Requirement
51
54
  none: false
52
55
  requirements:
@@ -57,10 +60,10 @@ dependencies:
57
60
  - 0
58
61
  version: "0"
59
62
  requirement: *id003
60
- type: :development
61
- name: ruby-debug
62
- prerelease: false
63
63
  - !ruby/object:Gem::Dependency
64
+ name: i18n
65
+ type: :runtime
66
+ prerelease: false
64
67
  version_requirements: &id004 !ruby/object:Gem::Requirement
65
68
  none: false
66
69
  requirements:
@@ -71,71 +74,69 @@ dependencies:
71
74
  - 0
72
75
  version: "0"
73
76
  requirement: *id004
74
- type: :development
75
- name: ruby-debug-base
76
- prerelease: false
77
77
  - !ruby/object:Gem::Dependency
78
+ name: activesupport
79
+ type: :runtime
80
+ prerelease: false
78
81
  version_requirements: &id005 !ruby/object:Gem::Requirement
79
82
  none: false
80
83
  requirements:
81
- - - <
84
+ - - ">="
82
85
  - !ruby/object:Gem::Version
83
- hash: 3
86
+ hash: 7
84
87
  segments:
85
- - 2
88
+ - 3
86
89
  - 0
87
- version: "2.0"
90
+ - 0
91
+ version: 3.0.0
88
92
  requirement: *id005
93
+ - !ruby/object:Gem::Dependency
94
+ name: ruby-debug
89
95
  type: :development
90
- name: rspec
91
96
  prerelease: false
92
- - !ruby/object:Gem::Dependency
93
97
  version_requirements: &id006 !ruby/object:Gem::Requirement
94
98
  none: false
95
99
  requirements:
96
- - - <
100
+ - - ">="
97
101
  - !ruby/object:Gem::Version
98
- hash: 15
102
+ hash: 3
99
103
  segments:
100
- - 2
101
- - 0
102
104
  - 0
103
- version: 2.0.0
105
+ version: "0"
104
106
  requirement: *id006
107
+ - !ruby/object:Gem::Dependency
108
+ name: rspec
105
109
  type: :development
106
- name: rspec-rails
107
110
  prerelease: false
108
- - !ruby/object:Gem::Dependency
109
111
  version_requirements: &id007 !ruby/object:Gem::Requirement
110
112
  none: false
111
113
  requirements:
112
- - - ">="
114
+ - - <
113
115
  - !ruby/object:Gem::Version
114
116
  hash: 3
115
117
  segments:
118
+ - 2
116
119
  - 0
117
- version: "0"
120
+ version: "2.0"
118
121
  requirement: *id007
119
- type: :development
122
+ - !ruby/object:Gem::Dependency
120
123
  name: mocha
124
+ type: :development
121
125
  prerelease: false
122
- - !ruby/object:Gem::Dependency
123
126
  version_requirements: &id008 !ruby/object:Gem::Requirement
124
127
  none: false
125
128
  requirements:
126
129
  - - ">="
127
130
  - !ruby/object:Gem::Version
128
- hash: 53
131
+ hash: 3
129
132
  segments:
130
133
  - 0
131
- - 8
132
- - 5
133
- version: 0.8.5
134
+ version: "0"
134
135
  requirement: *id008
136
+ - !ruby/object:Gem::Dependency
137
+ name: rcov
135
138
  type: :development
136
- name: cucumber
137
139
  prerelease: false
138
- - !ruby/object:Gem::Dependency
139
140
  version_requirements: &id009 !ruby/object:Gem::Requirement
140
141
  none: false
141
142
  requirements:
@@ -146,39 +147,11 @@ dependencies:
146
147
  - 0
147
148
  version: "0"
148
149
  requirement: *id009
149
- type: :development
150
- name: cucumber-rails
151
- prerelease: false
152
150
  - !ruby/object:Gem::Dependency
153
- version_requirements: &id010 !ruby/object:Gem::Requirement
154
- none: false
155
- requirements:
156
- - - ">="
157
- - !ruby/object:Gem::Version
158
- hash: 3
159
- segments:
160
- - 0
161
- version: "0"
162
- requirement: *id010
163
- type: :development
164
- name: gherkin
165
- prerelease: false
166
- - !ruby/object:Gem::Dependency
167
- version_requirements: &id011 !ruby/object:Gem::Requirement
168
- none: false
169
- requirements:
170
- - - ">="
171
- - !ruby/object:Gem::Version
172
- hash: 3
173
- segments:
174
- - 0
175
- version: "0"
176
- requirement: *id011
151
+ name: yard
177
152
  type: :development
178
- name: rcov
179
153
  prerelease: false
180
- - !ruby/object:Gem::Dependency
181
- version_requirements: &id012 !ruby/object:Gem::Requirement
154
+ version_requirements: &id010 !ruby/object:Gem::Requirement
182
155
  none: false
183
156
  requirements:
184
157
  - - "="
@@ -189,12 +162,12 @@ dependencies:
189
162
  - 6
190
163
  - 5
191
164
  version: 0.6.5
192
- requirement: *id012
165
+ requirement: *id010
166
+ - !ruby/object:Gem::Dependency
167
+ name: RedCloth
193
168
  type: :development
194
- name: yard
195
169
  prerelease: false
196
- - !ruby/object:Gem::Dependency
197
- version_requirements: &id013 !ruby/object:Gem::Requirement
170
+ version_requirements: &id011 !ruby/object:Gem::Requirement
198
171
  none: false
199
172
  requirements:
200
173
  - - ">="
@@ -203,10 +176,7 @@ dependencies:
203
176
  segments:
204
177
  - 0
205
178
  version: "0"
206
- requirement: *id013
207
- type: :development
208
- name: RedCloth
209
- prerelease: false
179
+ requirement: *id011
210
180
  description: Spin up a jetty instance (e.g., the one at https://github.com/projecthydra/hydra-jetty) and wrap test in it. This lets us run tests against a real copy of solr and fedora.
211
181
  email:
212
182
  - bess@stanford.edu
@@ -224,9 +194,11 @@ files:
224
194
  - README.textile
225
195
  - Rakefile
226
196
  - TODO.txt
197
+ - config/jetty.yml
227
198
  - jettywrapper.gemspec
228
199
  - lib/jettywrapper.rb
229
200
  - lib/jettywrapper/version.rb
201
+ - lib/tasks/jettywrapper.rake
230
202
  - spec/lib/jettywrapper_integration_spec.rb
231
203
  - spec/lib/jettywrapper_spec.rb
232
204
  - spec/spec_helper.rb