jettywrapper 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ coverage
6
+ coverage.data
7
+ *~
8
+ .yardoc
9
+ doc
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.8.7@hydra-testing --create
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/README.textile ADDED
@@ -0,0 +1,28 @@
1
+ h1. jettywrapper
2
+
3
+ This gem is designed to make it easier to run automated tests against jetty. Solr comes bundled in a jetty instance, and the hydra project has taken a similar approach with hydra-jetty, an instance of jetty pre-configured to load fedora, solr, and various other java servlets of use to the hydra project.
4
+
5
+ h2. Instructions for the impatient:
6
+
7
+ bc..
8
+ require 'jettywrapper'
9
+ desc "New way of running tests"
10
+ task :newtest do
11
+ Rake::Task["rake:db:test:clone_structure"].invoke
12
+ Rake::Task["rake:hydra:jetty:config_fedora"].invoke
13
+ Rake::Task["rake:hydra:jetty:config"].invoke
14
+ jetty_params = {
15
+ :jetty_home => "/usr/local/projects/hydra-hydrus/jetty",
16
+ :quiet => false,
17
+ :jetty_port => 8983,
18
+ :solr_home => "/usr/local/projects/hydra-hydrus/jetty/solr/test-core",
19
+ :startup_wait => 30
20
+ }
21
+ error = Jettywrapper.wrap(jetty_params) do
22
+ # Rake::Task["libra_oa:default_fixtures:refresh"].invoke
23
+ Rake::Task["rake:hydra:default_fixtures:load"].invoke
24
+ Rake::Task["rake:spec"].invoke
25
+ Rake::Task["rake:cucumber"].invoke
26
+ end
27
+ raise "test failures: #{error}" if error
28
+ end
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rake'
2
+ require 'bundler'
3
+ require 'spec/rake/spectask'
4
+ require 'yard'
5
+
6
+ Bundler::GemHelper.install_tasks
7
+ Dir.glob('lib/tasks/*.rake').each { |r| import r }
8
+
9
+
10
+ begin
11
+ Bundler.setup(:default, :development)
12
+ rescue Bundler::BundlerError => e
13
+ $stderr.puts e.message
14
+ $stderr.puts "Run `bundle install` to install missing gems"
15
+ exit e.status_code
16
+ end
17
+
18
+ Spec::Rake::SpecTask.new(:spec) do |spec|
19
+ spec.libs << 'lib' << 'spec'
20
+ spec.spec_files = FileList['spec/**/*_spec.rb']
21
+ end
22
+
23
+ Spec::Rake::SpecTask.new(:rcov) do |spec|
24
+ spec.libs << 'lib' << 'spec'
25
+ spec.pattern = 'spec/**/*_spec.rb'
26
+ spec.rcov = true
27
+ spec.rcov_opts = %w{--exclude spec\/*,gems\/*,ruby\/* --aggregate coverage.data}
28
+ end
29
+
30
+ task :clean do
31
+ puts 'Cleaning old coverage.data'
32
+ FileUtils.rm('coverage.data') if(File.exists? 'coverage.data')
33
+ end
34
+
35
+ # Use yard to build docs
36
+ begin
37
+ require 'yard'
38
+ require 'yard/rake/yardoc_task'
39
+ project_root = File.expand_path(File.dirname(__FILE__))
40
+ doc_destination = File.join(project_root, 'doc')
41
+
42
+ YARD::Rake::YardocTask.new(:doc) do |yt|
43
+ yt.files = Dir.glob(File.join(project_root, 'lib', '**', '*.rb')) +
44
+ [ File.join(project_root, 'README.textile') ]
45
+ yt.options = ['--output-dir', doc_destination, '--readme', 'README.textile']
46
+ end
47
+ rescue LoadError
48
+ desc "Generate YARD Documentation"
49
+ task :doc do
50
+ abort "Please install the YARD gem to generate rdoc."
51
+ end
52
+ end
53
+
54
+ task :default => [:rcov, :doc]
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "jettywrapper/version"
4
+ require 'bundler'
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "jettywrapper"
8
+ s.version = GEMVERSION
9
+ s.platform = Gem::Platform::RUBY
10
+ s.authors = ["Bess Sadler"]
11
+ s.email = ["bess@stanford.edu"]
12
+ s.homepage = ""
13
+ s.summary = %q{Convenience tasks for working with jetty from within a ruby project.}
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
+ s.files = `git ls-files`.split("\n")
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
+ s.require_paths = ["lib"]
19
+
20
+ s.required_rubygems_version = ">= 1.3.6"
21
+
22
+ # Bundler will install these gems too if you've checked this out from source from git and run 'bundle install'
23
+ # It will not add these as dependencies if you require lyber-core for other projects
24
+ s.add_development_dependency "ruby-debug"
25
+ s.add_development_dependency "ruby-debug-base"
26
+ s.add_development_dependency "rspec", "< 2.0" # We're not ready to upgrade to rspec 2
27
+ s.add_development_dependency 'rspec-rails', '<2.0.0' # rspec-rails 2.0.0 requires Rails 3.
28
+ s.add_development_dependency 'mocha'
29
+ s.add_development_dependency 'cucumber', '>=0.8.5'
30
+ s.add_development_dependency 'cucumber-rails'
31
+ s.add_development_dependency 'gherkin'
32
+ s.add_development_dependency 'rcov'
33
+
34
+ s.add_development_dependency 'yard', '0.6.5' # Yard > 0.6.5 won't generate docs.
35
+ # I don't know why & don't have time to
36
+ # debug it right now
37
+
38
+ s.add_development_dependency 'RedCloth'
39
+
40
+ end
41
+
@@ -0,0 +1,157 @@
1
+ # Jettywrapper is a Singleton class, so you can only create one jetty instance at a time.
2
+
3
+ class Jettywrapper
4
+
5
+ require 'singleton'
6
+ include Singleton
7
+
8
+ attr_accessor :port # What port should jetty start on? Default is 8888
9
+ attr_accessor :jetty_home # Where is jetty located?
10
+ attr_accessor :startup_wait # After jetty starts, how long to wait until starting the tests?
11
+ attr_accessor :quiet # Keep quiet about jetty output?
12
+ attr_accessor :solr_home # Where is solr located? Default is jetty_home/solr
13
+ attr_accessor :fedora_home # Where is fedora located? Default is jetty_home/fedora
14
+
15
+ # configure the singleton with some defaults
16
+ def initialize
17
+ @pid = nil
18
+ end
19
+
20
+ class << self
21
+
22
+ # Set the jetty parameters. It accepts a Hash of symbols.
23
+ # @param [Hash<Symbol>] params
24
+ # @param [Symbol] :jetty_home Required. Where is jetty located?
25
+ # @param [Symbol] :jetty_port What port should jetty start on? Default is 8888
26
+ # @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.
27
+ # @param [Symbol] :solr_home Where is solr? Default is jetty_home/solr
28
+ # @param [Symbol] :fedora_home Where is fedora? Default is jetty_home/fedora
29
+ # @param [Symbol] :quiet Keep quiet about jetty output? Default is true.
30
+ def configure(params = {})
31
+ hydra_server = self.instance
32
+ hydra_server.quiet = params[:quiet].nil? ? true : params[:quiet]
33
+ if defined?(Rails.root)
34
+ base_path = Rails.root
35
+ else
36
+ raise "You must set either RAILS_ROOT or :jetty_home so I know where jetty is" unless params[:jetty_home]
37
+ end
38
+ hydra_server.jetty_home = params[:jetty_home] || File.expand_path(File.join(base_path, 'jetty'))
39
+ hydra_server.solr_home = params[:solr_home] || File.join( hydra_server.jetty_home, "solr")
40
+ hydra_server.fedora_home = params[:fedora_home] || File.join( hydra_server.jetty_home, "fedora","default")
41
+ hydra_server.port = params[:jetty_port] || 8888
42
+ hydra_server.startup_wait = params[:startup_wait] || 5
43
+ return hydra_server
44
+ end
45
+
46
+ # Wrap the tests. Startup jetty, yield to the test task, capture any errors, shutdown
47
+ # jetty, and return the error.
48
+ # @example Using this method in a rake task
49
+ # require 'jettywrapper'
50
+ # desc "Spin up jetty and run tests against it"
51
+ # task :newtest do
52
+ # jetty_params = {
53
+ # :jetty_home => "/path/to/jetty",
54
+ # :quiet => false,
55
+ # :jetty_port => 8983,
56
+ # :startup_wait => 30
57
+ # }
58
+ # error = Jettywrapper.wrap(jetty_params) do
59
+ # Rake::Task["rake:spec"].invoke
60
+ # Rake::Task["rake:cucumber"].invoke
61
+ # end
62
+ # raise "test failures: #{error}" if error
63
+ # end
64
+ def wrap(params = {})
65
+ error = false
66
+ jetty_server = self.instance
67
+ jetty_server.quiet = params[:quiet] || true
68
+ jetty_server.jetty_home = params[:jetty_home]
69
+ jetty_server.solr_home = params[:solr_home]
70
+ jetty_server.port = params[:jetty_port] || 8888
71
+ jetty_server.startup_wait = params[:startup_wait] || 5
72
+ jetty_server.fedora_home = params[:fedora_home] || File.join( jetty_server.jetty_home, "fedora","default")
73
+
74
+ begin
75
+ # puts "starting jetty on #{RUBY_PLATFORM}"
76
+ jetty_server.start
77
+ sleep jetty_server.startup_wait
78
+ yield
79
+ rescue
80
+ error = $!
81
+ puts "*** Error starting hydra-jetty: #{error}"
82
+ ensure
83
+ # puts "stopping jetty server"
84
+ jetty_server.stop
85
+ end
86
+
87
+ return error
88
+ end
89
+
90
+ end #end of class << self
91
+
92
+ # What command is being run to invoke jetty?
93
+ def jetty_command
94
+ "java -Djetty.port=#{@port} -Dsolr.solr.home=#{@solr_home} -jar start.jar"
95
+ end
96
+
97
+ def start
98
+ puts "jetty_home: #{@jetty_home}"
99
+ puts "solr_home: #{@solr_home}"
100
+ puts "jetty_command: #{jetty_command}"
101
+ platform_specific_start
102
+ end
103
+
104
+ def stop
105
+ platform_specific_stop
106
+ end
107
+
108
+ if RUBY_PLATFORM =~ /mswin32/
109
+ require 'win32/process'
110
+
111
+ # start the solr server
112
+ def platform_specific_start
113
+ Dir.chdir(@jetty_home) do
114
+ @pid = Process.create(
115
+ :app_name => jetty_command,
116
+ :creation_flags => Process::DETACHED_PROCESS,
117
+ :process_inherit => false,
118
+ :thread_inherit => true,
119
+ :cwd => "#{@jetty_home}"
120
+ ).process_id
121
+ end
122
+ end
123
+
124
+ # stop a running solr server
125
+ def platform_specific_stop
126
+ Process.kill(1, @pid)
127
+ Process.wait
128
+ end
129
+ else # Not Windows
130
+
131
+ def jruby_raise_error?
132
+ raise 'JRuby requires that you start solr manually, then run "rake spec" or "rake features"' if defined?(JRUBY_VERSION)
133
+ end
134
+
135
+ # start the solr server
136
+ def platform_specific_start
137
+
138
+ jruby_raise_error?
139
+
140
+ puts self.inspect
141
+ Dir.chdir(@jetty_home) do
142
+ @pid = fork do
143
+ STDERR.close if @quiet
144
+ exec jetty_command
145
+ end
146
+ end
147
+ end
148
+
149
+ # stop a running solr server
150
+ def platform_specific_stop
151
+ jruby_raise_error?
152
+ Process.kill('TERM', @pid)
153
+ Process.wait
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1 @@
1
+ GEMVERSION = "0.0.2"
@@ -0,0 +1,96 @@
1
+ require File.join(File.dirname(__FILE__), "/../spec_helper")
2
+ require File.join(File.dirname(__FILE__), "/../../lib/jettywrapper")
3
+
4
+ module Hydra
5
+ describe Jettywrapper do
6
+
7
+ before(:all) do
8
+ @jetty_params = {
9
+ :quiet => false,
10
+ :jetty_home => "/path/to/jetty",
11
+ :jetty_port => 8888,
12
+ :solr_home => "/path/to/solr",
13
+ :fedora_home => "/path/to/fedora",
14
+ :startup_wait => 0
15
+ }
16
+ end
17
+
18
+ context "instantiation" do
19
+ it "can be instantiated" do
20
+ ts = Jettywrapper.instance
21
+ ts.class.should eql(Jettywrapper)
22
+ end
23
+
24
+ it "can be configured with a params hash" do
25
+ ts = Jettywrapper.configure(@jetty_params)
26
+ ts.quiet.should == false
27
+ ts.jetty_home.should == "/path/to/jetty"
28
+ ts.port.should == 8888
29
+ ts.solr_home.should == '/path/to/solr'
30
+ ts.fedora_home.should == '/path/to/fedora'
31
+ ts.startup_wait.should == 0
32
+ end
33
+
34
+ # passing in a hash is no longer optional
35
+ it "raises an error when called without a :jetty_home value" do
36
+ lambda { ts = Jettywrapper.configure }.should raise_exception
37
+ end
38
+
39
+ it "should override nil params with defaults" do
40
+ jetty_params = {
41
+ :quiet => nil,
42
+ :jetty_home => '/path/to/jetty',
43
+ :jetty_port => nil,
44
+ :solr_home => nil,
45
+ :fedora_home => nil,
46
+ :startup_wait => nil
47
+ }
48
+
49
+ ts = Jettywrapper.configure(jetty_params)
50
+ ts.quiet.should == true
51
+ ts.jetty_home.should == "/path/to/jetty"
52
+ ts.port.should == 8888
53
+ ts.solr_home.should == File.join(ts.jetty_home, "solr")
54
+ ts.fedora_home.should == File.join(ts.jetty_home, "fedora","default")
55
+ ts.startup_wait.should == 5
56
+ end
57
+ end # end of instantiation context
58
+
59
+ context "wrapping a task" do
60
+ it "wraps another method" do
61
+ Jettywrapper.any_instance.stubs(:start).returns(true)
62
+ Jettywrapper.any_instance.stubs(:stop).returns(true)
63
+ error = Jettywrapper.wrap(@jetty_params) do
64
+ end
65
+ error.should eql(false)
66
+ end
67
+
68
+ it "configures itself correctly when invoked via the wrap method" do
69
+ Jettywrapper.any_instance.stubs(:start).returns(true)
70
+ Jettywrapper.any_instance.stubs(:stop).returns(true)
71
+ error = Jettywrapper.wrap(@jetty_params) do
72
+ ts = Jettywrapper.instance
73
+ ts.quiet.should == true
74
+ ts.jetty_home.should == "/path/to/jetty"
75
+ ts.port.should == 8888
76
+ ts.solr_home.should == "/path/to/solr"
77
+ ts.fedora_home.should == "/path/to/fedora"
78
+ ts.startup_wait.should == 0
79
+ end
80
+ error.should eql(false)
81
+ end
82
+
83
+ it "captures any errors produced" do
84
+ Jettywrapper.any_instance.stubs(:start).returns(true)
85
+ Jettywrapper.any_instance.stubs(:stop).returns(true)
86
+ error = Jettywrapper.wrap(@jetty_params) do
87
+ raise "foo"
88
+ end
89
+ error.class.should eql(RuntimeError)
90
+ error.message.should eql("foo")
91
+ end
92
+
93
+ end
94
+
95
+ end
96
+ end
@@ -0,0 +1,7 @@
1
+ $: << File.join(File.dirname(__FILE__), "/../../lib")
2
+ require 'spec/autorun'
3
+ # require 'spec/rails'
4
+
5
+ Spec::Runner.configure do |config|
6
+ config.mock_with :mocha
7
+ end
metadata ADDED
@@ -0,0 +1,239 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jettywrapper
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 2
10
+ version: 0.0.2
11
+ platform: ruby
12
+ authors:
13
+ - Bess Sadler
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-04-13 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
+ none: false
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ hash: 3
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ requirement: *id001
33
+ prerelease: false
34
+ name: ruby-debug
35
+ - !ruby/object:Gem::Dependency
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ hash: 3
42
+ segments:
43
+ - 0
44
+ version: "0"
45
+ type: :development
46
+ requirement: *id002
47
+ prerelease: false
48
+ name: ruby-debug-base
49
+ - !ruby/object:Gem::Dependency
50
+ version_requirements: &id003 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - <
54
+ - !ruby/object:Gem::Version
55
+ hash: 3
56
+ segments:
57
+ - 2
58
+ - 0
59
+ version: "2.0"
60
+ type: :development
61
+ requirement: *id003
62
+ prerelease: false
63
+ name: rspec
64
+ - !ruby/object:Gem::Dependency
65
+ version_requirements: &id004 !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - <
69
+ - !ruby/object:Gem::Version
70
+ hash: 15
71
+ segments:
72
+ - 2
73
+ - 0
74
+ - 0
75
+ version: 2.0.0
76
+ type: :development
77
+ requirement: *id004
78
+ prerelease: false
79
+ name: rspec-rails
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
82
+ none: false
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ hash: 3
87
+ segments:
88
+ - 0
89
+ version: "0"
90
+ type: :development
91
+ requirement: *id005
92
+ prerelease: false
93
+ name: mocha
94
+ - !ruby/object:Gem::Dependency
95
+ version_requirements: &id006 !ruby/object:Gem::Requirement
96
+ none: false
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ hash: 53
101
+ segments:
102
+ - 0
103
+ - 8
104
+ - 5
105
+ version: 0.8.5
106
+ type: :development
107
+ requirement: *id006
108
+ prerelease: false
109
+ name: cucumber
110
+ - !ruby/object:Gem::Dependency
111
+ version_requirements: &id007 !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ hash: 3
117
+ segments:
118
+ - 0
119
+ version: "0"
120
+ type: :development
121
+ requirement: *id007
122
+ prerelease: false
123
+ name: cucumber-rails
124
+ - !ruby/object:Gem::Dependency
125
+ version_requirements: &id008 !ruby/object:Gem::Requirement
126
+ none: false
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ hash: 3
131
+ segments:
132
+ - 0
133
+ version: "0"
134
+ type: :development
135
+ requirement: *id008
136
+ prerelease: false
137
+ name: gherkin
138
+ - !ruby/object:Gem::Dependency
139
+ version_requirements: &id009 !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ hash: 3
145
+ segments:
146
+ - 0
147
+ version: "0"
148
+ type: :development
149
+ requirement: *id009
150
+ prerelease: false
151
+ name: rcov
152
+ - !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: 13
159
+ segments:
160
+ - 0
161
+ - 6
162
+ - 5
163
+ version: 0.6.5
164
+ type: :development
165
+ requirement: *id010
166
+ prerelease: false
167
+ name: yard
168
+ - !ruby/object:Gem::Dependency
169
+ version_requirements: &id011 !ruby/object:Gem::Requirement
170
+ none: false
171
+ requirements:
172
+ - - ">="
173
+ - !ruby/object:Gem::Version
174
+ hash: 3
175
+ segments:
176
+ - 0
177
+ version: "0"
178
+ type: :development
179
+ requirement: *id011
180
+ prerelease: false
181
+ name: RedCloth
182
+ 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.
183
+ email:
184
+ - bess@stanford.edu
185
+ executables: []
186
+
187
+ extensions: []
188
+
189
+ extra_rdoc_files: []
190
+
191
+ files:
192
+ - .gitignore
193
+ - .rvmrc
194
+ - Gemfile
195
+ - README.textile
196
+ - Rakefile
197
+ - jettywrapper.gemspec
198
+ - lib/jettywrapper.rb
199
+ - lib/jettywrapper/version.rb
200
+ - spec/lib/jettywrapper_spec.rb
201
+ - spec/spec_helper.rb
202
+ has_rdoc: true
203
+ homepage: ""
204
+ licenses: []
205
+
206
+ post_install_message:
207
+ rdoc_options: []
208
+
209
+ require_paths:
210
+ - lib
211
+ required_ruby_version: !ruby/object:Gem::Requirement
212
+ none: false
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ hash: 3
217
+ segments:
218
+ - 0
219
+ version: "0"
220
+ required_rubygems_version: !ruby/object:Gem::Requirement
221
+ none: false
222
+ requirements:
223
+ - - ">="
224
+ - !ruby/object:Gem::Version
225
+ hash: 23
226
+ segments:
227
+ - 1
228
+ - 3
229
+ - 6
230
+ version: 1.3.6
231
+ requirements: []
232
+
233
+ rubyforge_project:
234
+ rubygems_version: 1.6.2
235
+ signing_key:
236
+ specification_version: 3
237
+ summary: Convenience tasks for working with jetty from within a ruby project.
238
+ test_files: []
239
+