jettywrapper 1.8.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +11 -3
- data/Gemfile +2 -1
- data/History.txt +5 -1
- data/LICENSE +1086 -0
- data/gemfiles/rails4.1.gemfile +10 -0
- data/gemfiles/rails4.2.beta.gemfile +10 -0
- data/jettywrapper.gemspec +1 -1
- data/lib/jettywrapper/version.rb +1 -1
- data/lib/jettywrapper.rb +64 -66
- data/spec/lib/jettywrapper_spec.rb +52 -50
- metadata +8 -5
data/jettywrapper.gemspec
CHANGED
|
@@ -14,8 +14,8 @@ Gem::Specification.new do |s|
|
|
|
14
14
|
s.description = %q{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.}
|
|
15
15
|
s.files = `git ls-files`.split("\n")
|
|
16
16
|
s.test_files = `git ls-files -- {spec}/*`.split("\n")
|
|
17
|
-
# s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
18
17
|
s.require_paths = ["lib"]
|
|
18
|
+
s.license = 'APACHE2'
|
|
19
19
|
|
|
20
20
|
s.required_rubygems_version = ">= 1.3.6"
|
|
21
21
|
|
data/lib/jettywrapper/version.rb
CHANGED
data/lib/jettywrapper.rb
CHANGED
|
@@ -4,21 +4,21 @@ require 'shellwords'
|
|
|
4
4
|
require 'socket'
|
|
5
5
|
require 'timeout'
|
|
6
6
|
require 'childprocess'
|
|
7
|
+
require 'active_support/benchmarkable'
|
|
7
8
|
require 'active_support/core_ext/hash'
|
|
8
9
|
require 'erb'
|
|
9
10
|
require 'yaml'
|
|
11
|
+
require 'logger'
|
|
10
12
|
|
|
11
13
|
Dir[File.expand_path(File.join(File.dirname(__FILE__),"tasks/*.rake"))].each { |ext| load ext } if defined?(Rake)
|
|
12
14
|
|
|
13
|
-
|
|
14
15
|
# Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
|
|
15
16
|
class Jettywrapper
|
|
16
|
-
|
|
17
|
+
|
|
17
18
|
include Singleton
|
|
18
19
|
include ActiveSupport::Benchmarkable
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
attr_accessor :jetty_home # Jetty's home directory
|
|
20
|
+
|
|
21
|
+
attr_accessor :jetty_home # Jetty's home directory
|
|
22
22
|
attr_accessor :port # Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
|
|
23
23
|
attr_accessor :startup_wait # How many seconds to wait for jetty to spin up. Default is 5.
|
|
24
24
|
attr_accessor :quiet # true (default) to reduce Jetty's output
|
|
@@ -26,21 +26,20 @@ class Jettywrapper
|
|
|
26
26
|
attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
|
|
27
27
|
attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
|
|
28
28
|
attr_accessor :jetty_opts # Options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
|
|
29
|
-
|
|
29
|
+
|
|
30
30
|
# configure the singleton with some defaults
|
|
31
31
|
def initialize(params = {})
|
|
32
32
|
self.base_path = self.class.app_root
|
|
33
33
|
end
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
# Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
|
|
35
|
+
# Methods inside of the class << self block can be called directly on Jettywrapper, as class methods.
|
|
37
36
|
# Methods outside the class << self block must be called on Jettywrapper.instance, as instance methods.
|
|
38
37
|
class << self
|
|
39
38
|
|
|
40
39
|
attr_writer :hydra_jetty_version, :url, :tmp_dir, :jetty_dir, :env
|
|
41
40
|
|
|
42
41
|
def hydra_jetty_version
|
|
43
|
-
@hydra_jetty_version ||= '
|
|
42
|
+
@hydra_jetty_version ||= 'v8.1.1'
|
|
44
43
|
end
|
|
45
44
|
|
|
46
45
|
def url
|
|
@@ -61,16 +60,17 @@ class Jettywrapper
|
|
|
61
60
|
end
|
|
62
61
|
|
|
63
62
|
def download(url = nil)
|
|
63
|
+
return if File.exists? zip_file
|
|
64
64
|
self.url = url if url
|
|
65
65
|
logger.info "Downloading jetty at #{self.url} ..."
|
|
66
66
|
FileUtils.mkdir tmp_dir unless File.exists? tmp_dir
|
|
67
67
|
system "curl -L #{self.url} -o #{zip_file}"
|
|
68
68
|
abort "Unable to download jetty from #{self.url}" unless $?.success?
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
def unzip
|
|
72
72
|
download unless File.exists? zip_file
|
|
73
|
-
logger.info "Unpacking
|
|
73
|
+
logger.info "Unpacking #{zip_file}..."
|
|
74
74
|
tmp_save_dir = File.join tmp_dir, 'jetty_generator'
|
|
75
75
|
system "unzip -d #{tmp_save_dir} -qo #{zip_file}"
|
|
76
76
|
abort "Unable to unzip #{zip_file} into tmp_save_dir/" unless $?.success?
|
|
@@ -86,8 +86,8 @@ class Jettywrapper
|
|
|
86
86
|
|
|
87
87
|
def expanded_zip_dir(tmp_save_dir)
|
|
88
88
|
# This old way is more specific, but won't work for blacklight-jetty
|
|
89
|
-
#expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
|
|
90
|
-
Dir[File.join(tmp_save_dir, "*")].first
|
|
89
|
+
#expanded_dir = Dir[File.join(tmp_save_dir, "hydra-jetty-*")].first
|
|
90
|
+
Dir[File.join(tmp_save_dir, "*")].first
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
def clean
|
|
@@ -111,25 +111,25 @@ class Jettywrapper
|
|
|
111
111
|
|
|
112
112
|
def env
|
|
113
113
|
@env ||= begin
|
|
114
|
-
case
|
|
115
|
-
when ENV['JETTYWRAPPER_ENV']
|
|
114
|
+
case
|
|
115
|
+
when ENV['JETTYWRAPPER_ENV']
|
|
116
116
|
ENV['JETTYWRAPPER_ENV']
|
|
117
117
|
when defined?(Rails) && Rails.respond_to?(:env)
|
|
118
118
|
Rails.env
|
|
119
|
-
when ENV['RAILS_ENV']
|
|
120
|
-
ENV['RAILS_ENV']
|
|
121
|
-
when ENV['environment']
|
|
122
|
-
ENV['environment']
|
|
119
|
+
when ENV['RAILS_ENV']
|
|
120
|
+
ENV['RAILS_ENV']
|
|
121
|
+
when ENV['environment']
|
|
122
|
+
ENV['environment']
|
|
123
123
|
else
|
|
124
124
|
default_environment
|
|
125
125
|
end
|
|
126
126
|
end
|
|
127
127
|
end
|
|
128
|
-
|
|
128
|
+
|
|
129
129
|
def default_environment
|
|
130
130
|
'development'
|
|
131
131
|
end
|
|
132
|
-
|
|
132
|
+
|
|
133
133
|
def load_config(config_name = env)
|
|
134
134
|
@env = config_name
|
|
135
135
|
jetty_file = "#{app_root}/config/jetty.yml"
|
|
@@ -158,15 +158,14 @@ class Jettywrapper
|
|
|
158
158
|
config = jetty_yml.with_indifferent_access
|
|
159
159
|
config[config_name] || config['default'.freeze]
|
|
160
160
|
end
|
|
161
|
-
|
|
162
161
|
|
|
163
|
-
# Set the jetty parameters. It accepts a Hash of symbols.
|
|
162
|
+
# Set the jetty parameters. It accepts a Hash of symbols.
|
|
164
163
|
# @param [Hash<Symbol>] params
|
|
165
164
|
# :jetty_home Required. Jetty's home direcotry
|
|
166
165
|
# :jetty_port Jetty's port. Default is 8888. Note that attribute is named port, but params passed in expect :jetty_port
|
|
167
166
|
# :startup_wait How many seconds to wait for jetty to spin up. Default is 5. If jetty doesn't finish spinning up, tests can fail because they can't reach jetty.
|
|
168
167
|
# :solr_home Solr's home directory. Default is jetty_home/solr
|
|
169
|
-
# :quiet Keep True(default) to reduce jetty's output
|
|
168
|
+
# :quiet Keep True(default) to reduce jetty's output
|
|
170
169
|
# :java_opts options to pass to the jvm (ex. ["-Xmx512mb", "-Xms128mb"])
|
|
171
170
|
# :jetty_opts options to pass to jetty (ex. ["etc/my_jetty.xml", "etc/other.xml"] as in http://wiki.eclipse.org/Jetty/Reference/jetty.xml_usage
|
|
172
171
|
def configure(params = {})
|
|
@@ -182,25 +181,24 @@ class Jettywrapper
|
|
|
182
181
|
jetty_server.jetty_opts = params[:jetty_opts] || []
|
|
183
182
|
return jetty_server
|
|
184
183
|
end
|
|
185
|
-
|
|
186
|
-
|
|
184
|
+
|
|
187
185
|
# Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
|
|
188
|
-
# jetty, and return the error.
|
|
186
|
+
# jetty, and return the error.
|
|
189
187
|
# @example Using this method in a rake task
|
|
190
188
|
# require 'jettywrapper'
|
|
191
189
|
# desc "Spin up jetty and run tests against it"
|
|
192
190
|
# task :newtest do
|
|
193
|
-
# jetty_params = {
|
|
194
|
-
# :jetty_home => "/path/to/jetty",
|
|
195
|
-
# :quiet => false,
|
|
196
|
-
# :jetty_port => 8983,
|
|
191
|
+
# jetty_params = {
|
|
192
|
+
# :jetty_home => "/path/to/jetty",
|
|
193
|
+
# :quiet => false,
|
|
194
|
+
# :jetty_port => 8983,
|
|
197
195
|
# :startup_wait => 30,
|
|
198
196
|
# :jetty_opts => "/etc/jetty.xml"
|
|
199
197
|
# }
|
|
200
|
-
# error = Jettywrapper.wrap(jetty_params) do
|
|
201
|
-
# Rake::Task["rake:spec"].invoke
|
|
202
|
-
# Rake::Task["rake:cucumber"].invoke
|
|
203
|
-
# end
|
|
198
|
+
# error = Jettywrapper.wrap(jetty_params) do
|
|
199
|
+
# Rake::Task["rake:spec"].invoke
|
|
200
|
+
# Rake::Task["rake:cucumber"].invoke
|
|
201
|
+
# end
|
|
204
202
|
# raise "test failures: #{error}" if error
|
|
205
203
|
# end
|
|
206
204
|
def wrap(params)
|
|
@@ -222,42 +220,43 @@ class Jettywrapper
|
|
|
222
220
|
|
|
223
221
|
return error
|
|
224
222
|
end
|
|
225
|
-
|
|
223
|
+
|
|
226
224
|
# Convenience method for configuring and starting jetty with one command
|
|
227
225
|
# @param [Hash] params: The configuration to use for starting jetty
|
|
228
|
-
# @example
|
|
226
|
+
# @example
|
|
229
227
|
# Jettywrapper.start(:jetty_home => '/path/to/jetty', :jetty_port => '8983')
|
|
230
228
|
def start(params)
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
229
|
+
unzip unless File.exists? jetty_dir
|
|
230
|
+
Jettywrapper.configure(params)
|
|
231
|
+
Jettywrapper.instance.start
|
|
232
|
+
return Jettywrapper.instance
|
|
234
233
|
end
|
|
235
|
-
|
|
234
|
+
|
|
236
235
|
# Convenience method for configuring and starting jetty with one command. Note
|
|
237
|
-
# that for stopping, only the :jetty_home value is required (including other values won't
|
|
238
|
-
# hurt anything, though).
|
|
236
|
+
# that for stopping, only the :jetty_home value is required (including other values won't
|
|
237
|
+
# hurt anything, though).
|
|
239
238
|
# @param [Hash] params: The jetty_home to use for stopping jetty
|
|
240
239
|
# @return [Jettywrapper.instance]
|
|
241
|
-
# @example
|
|
240
|
+
# @example
|
|
242
241
|
# Jettywrapper.stop_with_params(:jetty_home => '/path/to/jetty')
|
|
243
242
|
def stop(params)
|
|
244
243
|
Jettywrapper.configure(params)
|
|
245
244
|
Jettywrapper.instance.stop
|
|
246
245
|
return Jettywrapper.instance
|
|
247
246
|
end
|
|
248
|
-
|
|
247
|
+
|
|
249
248
|
# Determine whether the jetty at the given jetty_home is running
|
|
250
249
|
# @param [Hash] params: :jetty_home is required. Which jetty do you want to check the status of?
|
|
251
250
|
# @return [Boolean]
|
|
252
251
|
# @example
|
|
253
252
|
# Jettywrapper.is_jetty_running?(:jetty_home => '/path/to/jetty')
|
|
254
|
-
def is_jetty_running?(params)
|
|
253
|
+
def is_jetty_running?(params)
|
|
255
254
|
Jettywrapper.configure(params)
|
|
256
255
|
pid = Jettywrapper.instance.pid
|
|
257
256
|
return false unless pid
|
|
258
257
|
true
|
|
259
258
|
end
|
|
260
|
-
|
|
259
|
+
|
|
261
260
|
# Return the pid of the specified jetty, or return nil if it isn't running
|
|
262
261
|
# @param [Hash] params: :jetty_home is required.
|
|
263
262
|
# @return [Fixnum] or [nil]
|
|
@@ -269,7 +268,7 @@ class Jettywrapper
|
|
|
269
268
|
return nil unless pid
|
|
270
269
|
pid
|
|
271
270
|
end
|
|
272
|
-
|
|
271
|
+
|
|
273
272
|
# Check to see if the port is open so we can raise an error if we have a conflict
|
|
274
273
|
# @param [Fixnum] port the port to check
|
|
275
274
|
# @return [Boolean]
|
|
@@ -293,8 +292,8 @@ class Jettywrapper
|
|
|
293
292
|
|
|
294
293
|
return false
|
|
295
294
|
end
|
|
296
|
-
|
|
297
|
-
# Check to see if the pid is actually running. This only works on unix.
|
|
295
|
+
|
|
296
|
+
# Check to see if the pid is actually running. This only works on unix.
|
|
298
297
|
def is_pid_running?(pid)
|
|
299
298
|
begin
|
|
300
299
|
return Process.getpgid(pid) != -1
|
|
@@ -306,20 +305,20 @@ class Jettywrapper
|
|
|
306
305
|
def logger=(logger)
|
|
307
306
|
@@logger = logger
|
|
308
307
|
end
|
|
309
|
-
|
|
310
|
-
# If ::Rails.logger is defined,
|
|
308
|
+
|
|
309
|
+
# If ::Rails.logger is defined and is not nil, it will be returned.
|
|
311
310
|
# If no logger has been defined, a new STDOUT Logger will be created.
|
|
312
311
|
def logger
|
|
313
|
-
@@logger ||= defined?(::Rails) ? ::Rails.logger : ::Logger.new(STDOUT)
|
|
312
|
+
@@logger ||= defined?(::Rails) && Rails.logger ? ::Rails.logger : ::Logger.new(STDOUT)
|
|
314
313
|
end
|
|
315
314
|
|
|
316
315
|
end #end of class << self
|
|
317
|
-
|
|
316
|
+
|
|
318
317
|
def logger
|
|
319
318
|
self.class.logger
|
|
320
319
|
end
|
|
321
|
-
|
|
322
|
-
# What command is being run to invoke jetty?
|
|
320
|
+
|
|
321
|
+
# What command is being run to invoke jetty?
|
|
323
322
|
def jetty_command
|
|
324
323
|
["java", java_variables, java_opts, "-jar", "start.jar", jetty_opts].flatten
|
|
325
324
|
end
|
|
@@ -329,8 +328,8 @@ class Jettywrapper
|
|
|
329
328
|
"-Dsolr.solr.home=#{Shellwords.escape(@solr_home)}"]
|
|
330
329
|
end
|
|
331
330
|
|
|
332
|
-
# Start the jetty server. Check the pid file to see if it is running already,
|
|
333
|
-
# and stop it if so. After you start jetty, write the PID to a file.
|
|
331
|
+
# Start the jetty server. Check the pid file to see if it is running already,
|
|
332
|
+
# and stop it if so. After you start jetty, write the PID to a file.
|
|
334
333
|
# This is the instance start method. It must be called on Jettywrapper.instance
|
|
335
334
|
# You're probably better off using Jettywrapper.start(:jetty_home => "/path/to/jetty")
|
|
336
335
|
# @example
|
|
@@ -341,10 +340,10 @@ class Jettywrapper
|
|
|
341
340
|
logger.debug "Starting jetty with these values: "
|
|
342
341
|
logger.debug "jetty_home: #{@jetty_home}"
|
|
343
342
|
logger.debug "jetty_command: #{jetty_command.join(' ')}"
|
|
344
|
-
|
|
343
|
+
|
|
345
344
|
# Check to see if we can start.
|
|
346
345
|
# 1. If there is a pid, check to see if it is really running
|
|
347
|
-
# 2. Check to see if anything is blocking the port we want to use
|
|
346
|
+
# 2. Check to see if anything is blocking the port we want to use
|
|
348
347
|
if pid
|
|
349
348
|
if Jettywrapper.is_pid_running?(pid)
|
|
350
349
|
raise("Server is already running with PID #{pid}")
|
|
@@ -378,12 +377,12 @@ class Jettywrapper
|
|
|
378
377
|
begin
|
|
379
378
|
Timeout::timeout(startup_wait) do
|
|
380
379
|
sleep 1 until (Jettywrapper.is_port_in_use? self.port)
|
|
381
|
-
end
|
|
380
|
+
end
|
|
382
381
|
rescue Timeout::Error
|
|
383
382
|
logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
|
|
384
383
|
end
|
|
385
384
|
end
|
|
386
|
-
|
|
385
|
+
|
|
387
386
|
def process
|
|
388
387
|
@process ||= begin
|
|
389
388
|
process = ChildProcess.build(*jetty_command)
|
|
@@ -410,7 +409,7 @@ class Jettywrapper
|
|
|
410
409
|
# Jettywrapper.configure(params)
|
|
411
410
|
# Jettywrapper.instance.stop
|
|
412
411
|
# return Jettywrapper.instance
|
|
413
|
-
def stop
|
|
412
|
+
def stop
|
|
414
413
|
logger.debug "Instance stop method called for pid '#{pid}'"
|
|
415
414
|
if pid
|
|
416
415
|
if @process
|
|
@@ -425,7 +424,6 @@ class Jettywrapper
|
|
|
425
424
|
end
|
|
426
425
|
end
|
|
427
426
|
end
|
|
428
|
-
|
|
429
427
|
|
|
430
428
|
# The fully qualified path to the pid_file
|
|
431
429
|
def pid_path
|
|
@@ -437,7 +435,7 @@ class Jettywrapper
|
|
|
437
435
|
def pid_file
|
|
438
436
|
jetty_home_to_pid_file(@jetty_home)
|
|
439
437
|
end
|
|
440
|
-
|
|
438
|
+
|
|
441
439
|
# Take the @jetty_home value and transform it into a legal filename
|
|
442
440
|
# @return [String] the name of the pid_file
|
|
443
441
|
# @example
|
|
@@ -454,7 +452,7 @@ class Jettywrapper
|
|
|
454
452
|
def pid_dir
|
|
455
453
|
File.expand_path(File.join(base_path,'tmp','pids'))
|
|
456
454
|
end
|
|
457
|
-
|
|
455
|
+
|
|
458
456
|
# Check to see if there is a pid file already
|
|
459
457
|
# @return true if the file exists, otherwise false
|
|
460
458
|
def pid_file?
|