jettywrapper 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +3 -0
- data/README.textile +20 -51
- data/lib/jettywrapper.rb +26 -14
- data/lib/jettywrapper/version.rb +1 -1
- data/lib/tasks/jettywrapper.rake +1 -1
- data/spec/lib/jettywrapper_integration_spec.rb +8 -8
- metadata +4 -4
data/History.txt
CHANGED
data/README.textile
CHANGED
@@ -1,64 +1,33 @@
|
|
1
1
|
h1. jettywrapper
|
2
2
|
|
3
|
-
This gem is designed to make it easier to
|
4
|
-
|
5
|
-
h2. Instructions for the impatient:
|
6
|
-
|
7
|
-
bc..
|
8
|
-
require 'jettywrapper'
|
9
|
-
desc "Hudson build"
|
10
|
-
task :hudson do
|
11
|
-
if (ENV['RAILS_ENV'] == "test")
|
12
|
-
jetty_params = {
|
13
|
-
:jetty_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty'),
|
14
|
-
:quiet => false,
|
15
|
-
:jetty_port => 8983,
|
16
|
-
:solr_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty/solr/test-core'),
|
17
|
-
:fedora_home => File.expand_path(File.dirname(__FILE__) + '/../../jetty/fedora/default'),
|
18
|
-
:startup_wait => 30
|
19
|
-
}
|
20
|
-
Rake::Task["db:drop"].invoke
|
21
|
-
Rake::Task["db:migrate"].invoke
|
22
|
-
Rake::Task["db:migrate:plugins"].invoke
|
23
|
-
error = Jettywrapper.wrap(jetty_params) do
|
24
|
-
Rake::Task["libra_oa:default_fixtures:refresh"].invoke
|
25
|
-
Rake::Task["hydra:fixtures:refresh"].invoke
|
26
|
-
Rake::Task["spec"].invoke
|
27
|
-
Rake::Task["cucumber"].invoke
|
28
|
-
end
|
29
|
-
raise "test failures: #{error}" if error
|
30
|
-
else
|
31
|
-
system("rake hudson RAILS_ENV=test")
|
32
|
-
fail unless $?.success?
|
33
|
-
end
|
34
|
-
end
|
3
|
+
This gem is designed to make it easier to integrate a jetty servlet container into a rails project.
|
4
|
+
Jettywrapper provides rake tasks for starting and stopping jetty, as well as a method (Jettywrapper.wrap) that will start the server before the block and stop the server after the block, which is useful for automated testing.
|
35
5
|
|
36
|
-
h2.
|
6
|
+
h2. Configuring Jettywrapper
|
37
7
|
|
38
|
-
|
39
|
-
If you use system(), the return value will be false for any exit codes other than 0. If you use backticks or %x(), you must use $? to check the exit status code
|
40
|
-
after the call. Failure to do so could result in false successes.
|
8
|
+
Jettywrapper starts the process with a list of options that you can specify in config/jetty.yml (otherwise a default is used). You can provide a per environment configuration, or you can have a default configuration which will be used when a per-environment configuration is not specified.
|
41
9
|
|
42
|
-
|
10
|
+
<pre>default:
|
11
|
+
jetty_port: 8983
|
12
|
+
java_opts:
|
13
|
+
- "-XX:MaxPermSize=128m"
|
14
|
+
- "-Xmx256m"
|
15
|
+
</pre>
|
43
16
|
|
44
|
-
bc..
|
45
|
-
#retval should return false for non-zero exit codes
|
46
|
-
retval = system("rake hudson RAILS_ENV=test")
|
47
|
-
fail unless retval
|
48
17
|
|
49
|
-
h3. Example 2: Checking $? with system()
|
50
18
|
|
51
|
-
|
52
|
-
system("rake hudson RAILS_ENV=test")
|
53
|
-
raise "rake hudson encoutered errors" unless $?.success?
|
19
|
+
h2. Example rake task:
|
54
20
|
|
55
|
-
|
21
|
+
bc.. require 'jettywrapper'
|
22
|
+
desc "Hudson build"
|
23
|
+
task :hudson do
|
24
|
+
jetty_params = Jettywrapper.load_config.merge({:jetty_home => File.expand_path(File.dirname(__FILE__) + '/../jetty')})
|
25
|
+
error = Jettywrapper.wrap(jetty_params) do
|
26
|
+
Rake::Task["spec"].invoke
|
27
|
+
end
|
28
|
+
raise "test failures: #{error}" if error
|
29
|
+
end
|
56
30
|
|
57
|
-
bc..
|
58
|
-
# %x[] or `` will return everything sent to stdout from the command
|
59
|
-
puts %x[cucumber --tags ~@pending --tags ~@overwritten features]
|
60
|
-
raise "Cucumber failed." unless $?.success?
|
61
|
-
|
62
31
|
h2. Testing the gem
|
63
32
|
|
64
33
|
If you haven't already, clone the git repository
|
data/lib/jettywrapper.rb
CHANGED
@@ -23,6 +23,7 @@ class Jettywrapper
|
|
23
23
|
attr_accessor :solr_home # Where is solr located? Default is jetty_home/solr
|
24
24
|
attr_accessor :base_path # The root of the application. Used for determining where log files and PID files should go.
|
25
25
|
attr_accessor :java_opts # Options to pass to java (ex. ["-Xmx512mb", "-Xms128mb"])
|
26
|
+
attr_accessor :port # The port jetty should listen on
|
26
27
|
|
27
28
|
# configure the singleton with some defaults
|
28
29
|
def initialize(params = {})
|
@@ -70,9 +71,9 @@ class Jettywrapper
|
|
70
71
|
# @param [Symbol] :quiet Keep quiet about jetty output? Default is true.
|
71
72
|
# @param [Symbol] :java_opts A list of options to pass to the jvm
|
72
73
|
def configure(params = {})
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
jetty_server = self.instance
|
75
|
+
jetty_server.reset_process!
|
76
|
+
jetty_server.quiet = params[:quiet].nil? ? true : params[:quiet]
|
76
77
|
if defined?(Rails.root)
|
77
78
|
base_path = Rails.root
|
78
79
|
elsif defined?(APP_ROOT)
|
@@ -80,12 +81,12 @@ class Jettywrapper
|
|
80
81
|
else
|
81
82
|
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]
|
82
83
|
end
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
return
|
84
|
+
jetty_server.jetty_home = params[:jetty_home] || File.expand_path(File.join(base_path, 'jetty'))
|
85
|
+
jetty_server.solr_home = params[:solr_home] || File.join( jetty_server.jetty_home, "solr")
|
86
|
+
jetty_server.port = params[:jetty_port] || 8888
|
87
|
+
jetty_server.startup_wait = params[:startup_wait] || 5
|
88
|
+
jetty_server.java_opts = params[:java_opts] || []
|
89
|
+
return jetty_server
|
89
90
|
end
|
90
91
|
|
91
92
|
|
@@ -113,11 +114,10 @@ class Jettywrapper
|
|
113
114
|
|
114
115
|
begin
|
115
116
|
jetty_server.start
|
116
|
-
sleep jetty_server.startup_wait
|
117
117
|
yield
|
118
118
|
rescue
|
119
119
|
error = $!
|
120
|
-
puts "*** Error starting
|
120
|
+
puts "*** Error starting jetty: #{error}"
|
121
121
|
ensure
|
122
122
|
# puts "stopping jetty server"
|
123
123
|
jetty_server.stop
|
@@ -243,8 +243,8 @@ class Jettywrapper
|
|
243
243
|
logger.warn "Removing stale PID file at #{pid_path}"
|
244
244
|
File.delete(pid_path)
|
245
245
|
end
|
246
|
-
if Jettywrapper.is_port_in_use?(
|
247
|
-
raise("Port #{self.
|
246
|
+
if Jettywrapper.is_port_in_use?(self.port)
|
247
|
+
raise("Port #{self.port} is already in use.")
|
248
248
|
end
|
249
249
|
end
|
250
250
|
Dir.chdir(@jetty_home) do
|
@@ -259,13 +259,25 @@ class Jettywrapper
|
|
259
259
|
f.puts "#{process.pid}"
|
260
260
|
f.close
|
261
261
|
logger.debug "Wrote pid file to #{pid_path} with value #{process.pid}"
|
262
|
+
startup_wait!
|
263
|
+
end
|
264
|
+
|
265
|
+
# Wait for the jetty server to start and begin listening for requests
|
266
|
+
def startup_wait!
|
267
|
+
begin
|
268
|
+
Timeout::timeout(startup_wait) do
|
269
|
+
sleep 1 until (Jettywrapper.is_port_in_use? self.port)
|
270
|
+
end
|
271
|
+
rescue Timeout::Error
|
272
|
+
logger.warn "Waited #{startup_wait} seconds for jetty to start, but it is not yet listening on port #{self.port}. Continuing anyway."
|
273
|
+
end
|
262
274
|
end
|
263
275
|
|
264
276
|
def process
|
265
277
|
@process ||= begin
|
266
278
|
process = ChildProcess.build(*jetty_command)
|
267
279
|
if self.quiet
|
268
|
-
process.io.stderr = File.open("jettywrapper.log", "w+")
|
280
|
+
process.io.stderr = File.open(File.expand_path("jettywrapper.log"), "w+")
|
269
281
|
process.io.stdout = process.io.stderr
|
270
282
|
logger.warn "Logging jettywrapper stdout to #{File.expand_path(process.io.stderr.path)}"
|
271
283
|
else
|
data/lib/jettywrapper/version.rb
CHANGED
@@ -1 +1 @@
|
|
1
|
-
GEMVERSION = "1.2.
|
1
|
+
GEMVERSION = "1.2.1"
|
data/lib/tasks/jettywrapper.rake
CHANGED
@@ -12,7 +12,8 @@ module Hydra
|
|
12
12
|
|
13
13
|
it "starts" do
|
14
14
|
jetty_params = {
|
15
|
-
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
|
15
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
|
16
|
+
:startup_wait => 30
|
16
17
|
}
|
17
18
|
Jettywrapper.configure(jetty_params)
|
18
19
|
ts = Jettywrapper.instance
|
@@ -22,7 +23,6 @@ module Hydra
|
|
22
23
|
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
23
24
|
pid_from_file = File.open( ts.pid_path ) { |f| f.gets.to_i }
|
24
25
|
ts.pid.should eql(pid_from_file)
|
25
|
-
sleep 30 # give jetty time to start
|
26
26
|
|
27
27
|
# Can we connect to solr?
|
28
28
|
require 'net/http'
|
@@ -34,14 +34,14 @@ module Hydra
|
|
34
34
|
|
35
35
|
it "won't start if it's already running" do
|
36
36
|
jetty_params = {
|
37
|
-
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty")
|
37
|
+
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
|
38
|
+
:startup_wait => 30
|
38
39
|
}
|
39
40
|
Jettywrapper.configure(jetty_params)
|
40
41
|
ts = Jettywrapper.instance
|
41
42
|
ts.logger.debug "Stopping jetty from rspec."
|
42
43
|
ts.stop
|
43
44
|
ts.start
|
44
|
-
sleep 30
|
45
45
|
ts.logger.debug "Jetty started from rspec at #{ts.pid}"
|
46
46
|
response = Net::HTTP.get_response(URI.parse("http://localhost:8888/solr/development/admin/"))
|
47
47
|
response.code.should eql("200")
|
@@ -52,13 +52,13 @@ module Hydra
|
|
52
52
|
it "can check to see whether a port is already in use" do
|
53
53
|
params = {
|
54
54
|
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
|
55
|
-
:jetty_port => '9999'
|
55
|
+
:jetty_port => '9999',
|
56
|
+
:startup_wait => 30
|
56
57
|
}
|
57
58
|
Jettywrapper.stop(params)
|
58
59
|
sleep 10
|
59
60
|
Jettywrapper.is_port_in_use?(params[:jetty_port]).should eql(false)
|
60
61
|
Jettywrapper.start(params)
|
61
|
-
sleep 30
|
62
62
|
Jettywrapper.is_port_in_use?(params[:jetty_port]).should eql(true)
|
63
63
|
Jettywrapper.stop(params)
|
64
64
|
end
|
@@ -66,13 +66,13 @@ module Hydra
|
|
66
66
|
it "raises an error if you try to start a jetty that is already running" do
|
67
67
|
jetty_params = {
|
68
68
|
:jetty_home => File.expand_path("#{File.dirname(__FILE__)}/../../jetty"),
|
69
|
-
:jetty_port => '8983'
|
69
|
+
:jetty_port => '8983',
|
70
|
+
:startup_wait => 30
|
70
71
|
}
|
71
72
|
ts = Jettywrapper.configure(jetty_params)
|
72
73
|
ts.stop
|
73
74
|
ts.pid_file?.should eql(false)
|
74
75
|
ts.start
|
75
|
-
sleep 30
|
76
76
|
lambda{ ts.start }.should raise_exception
|
77
77
|
ts.stop
|
78
78
|
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:
|
4
|
+
hash: 29
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 1.2.
|
9
|
+
- 1
|
10
|
+
version: 1.2.1
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Bess Sadler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
18
|
+
date: 2012-01-11 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|