torquespec 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/lib/torquespec.rb +2 -0
- data/lib/torquespec/rspec.rb +44 -0
- data/lib/torquespec/server.rb +108 -0
- data/lib/torquespec/torquespec.rb +33 -0
- data/lib/torquespec/version.rb +3 -0
- data/torquespec.gemspec +23 -0
- metadata +89 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/lib/torquespec.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'torquespec/server'
|
2
|
+
|
3
|
+
begin
|
4
|
+
# RSpec v2
|
5
|
+
require 'rspec'
|
6
|
+
TorqueSpec::Configurator = RSpec
|
7
|
+
rescue Exception
|
8
|
+
# RSpec v1
|
9
|
+
require 'spec'
|
10
|
+
TorqueSpec::Configurator = Spec::Runner
|
11
|
+
end
|
12
|
+
|
13
|
+
# Global configuration
|
14
|
+
TorqueSpec::Configurator.configure do |config|
|
15
|
+
|
16
|
+
# Add :deploy method to ExampleGroups
|
17
|
+
config.extend(TorqueSpec)
|
18
|
+
|
19
|
+
config.before(:suite) do
|
20
|
+
Thread.current[:app_server] = TorqueSpec::Server.new
|
21
|
+
Thread.current[:app_server].start(:wait => 120)
|
22
|
+
end
|
23
|
+
|
24
|
+
config.before(:all) do
|
25
|
+
if self.class.respond_to?( :deploy_paths )
|
26
|
+
self.class.deploy_paths.each do |path|
|
27
|
+
Thread.current[:app_server].deploy(path)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
config.after(:all) do
|
33
|
+
if self.class.respond_to?( :deploy_paths )
|
34
|
+
self.class.deploy_paths.each do |path|
|
35
|
+
Thread.current[:app_server].undeploy(path)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
config.after(:suite) do
|
41
|
+
Thread.current[:app_server].stop
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
|
3
|
+
module TorqueSpec
|
4
|
+
class Server
|
5
|
+
|
6
|
+
def start(opts={})
|
7
|
+
return if TorqueSpec.lazy and ready?
|
8
|
+
wait = opts[:wait].to_i
|
9
|
+
raise "JBoss is already running" if ready?
|
10
|
+
cmd = command
|
11
|
+
@process = IO.popen( cmd )
|
12
|
+
Thread.new(@process) { |console| while(console.gets); end }
|
13
|
+
%w{ INT TERM KILL }.each { |signal| trap(signal) { stop } }
|
14
|
+
puts "#{cmd}\npid=#{@process.pid}"
|
15
|
+
wait > 0 ? wait_for_ready(wait) : @process.pid
|
16
|
+
end
|
17
|
+
|
18
|
+
def deploy(url)
|
19
|
+
t0 = Time.now
|
20
|
+
puts "#{url}"
|
21
|
+
success?( deployer( 'redeploy', url ) )
|
22
|
+
puts " deployed in #{(Time.now - t0).to_i}s"
|
23
|
+
end
|
24
|
+
|
25
|
+
def undeploy(url)
|
26
|
+
success?( deployer( 'undeploy', url ) )
|
27
|
+
puts " undeployed #{url.split('/')[-1]}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop
|
31
|
+
return if TorqueSpec.lazy
|
32
|
+
if @process
|
33
|
+
unless clean_stop
|
34
|
+
puts "Unable to shutdown JBoss cleanly, interrupting process"
|
35
|
+
Process.kill("INT", @process.pid)
|
36
|
+
end
|
37
|
+
@process = nil
|
38
|
+
puts "JBoss stopped"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def clean_stop
|
43
|
+
success?( jmx_console( :action => 'invokeOpByName',
|
44
|
+
:name => 'jboss.system:type=Server',
|
45
|
+
:methodName => 'shutdown' ) )
|
46
|
+
end
|
47
|
+
|
48
|
+
def ready?
|
49
|
+
response = jmx_console( :action => 'inspectMBean', :name => 'jboss.system:type=Server' )
|
50
|
+
"True" == response.match(/>Started<.*?<pre>\s+^(\w+)/m)[1]
|
51
|
+
rescue
|
52
|
+
false
|
53
|
+
end
|
54
|
+
|
55
|
+
def wait_for_ready(timeout)
|
56
|
+
puts "Waiting up to #{timeout}s for JBoss to boot"
|
57
|
+
t0 = Time.now
|
58
|
+
while (Time.now - t0 < timeout && @process) do
|
59
|
+
if ready?
|
60
|
+
puts "JBoss started in #{(Time.now - t0).to_i}s"
|
61
|
+
return true
|
62
|
+
end
|
63
|
+
sleep(1)
|
64
|
+
end
|
65
|
+
raise "JBoss failed to start"
|
66
|
+
end
|
67
|
+
|
68
|
+
protected
|
69
|
+
|
70
|
+
def command
|
71
|
+
java_home = java.lang::System.getProperty( 'java.home' )
|
72
|
+
"#{java_home}/bin/java -cp #{TorqueSpec.jboss_home}/bin/run.jar #{TorqueSpec.jvm_args} -Djava.endorsed.dirs=#{TorqueSpec.jboss_home}/lib/endorsed org.jboss.Main -c #{TorqueSpec.jboss_conf} -b #{TorqueSpec.host}"
|
73
|
+
end
|
74
|
+
|
75
|
+
def deployer(method, url)
|
76
|
+
jmx_console( :action => 'invokeOpByName',
|
77
|
+
:name => 'jboss.system:service=MainDeployer',
|
78
|
+
:methodName => method,
|
79
|
+
:argType => 'java.net.URL',
|
80
|
+
:arg0 => url )
|
81
|
+
end
|
82
|
+
|
83
|
+
def success?(response)
|
84
|
+
response.include?( "Operation completed successfully" )
|
85
|
+
end
|
86
|
+
|
87
|
+
def jmx_console(params)
|
88
|
+
req = Net::HTTP::Post.new('/jmx-console/HtmlAdaptor')
|
89
|
+
req.set_form_data( params )
|
90
|
+
http( req )
|
91
|
+
end
|
92
|
+
|
93
|
+
def http req
|
94
|
+
res = Net::HTTP.start(TorqueSpec.host, TorqueSpec.port) do |http|
|
95
|
+
http.read_timeout = 120
|
96
|
+
http.request(req)
|
97
|
+
end
|
98
|
+
unless Net::HTTPSuccess === res
|
99
|
+
STDERR.puts res.body
|
100
|
+
res.error!
|
101
|
+
end
|
102
|
+
res.body
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module TorqueSpec
|
4
|
+
|
5
|
+
def deploy(*paths)
|
6
|
+
metaclass = class << self; self; end
|
7
|
+
metaclass.send(:define_method, :deploy_paths) do
|
8
|
+
paths.map {|p| Pathname.new(p).absolute? ? p : File.join(TorqueSpec.knob_root, p) }
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class << self
|
13
|
+
attr_accessor :host, :port, :knob_root, :jboss_home, :jboss_conf, :jvm_args, :max_heap, :lazy
|
14
|
+
def configure
|
15
|
+
yield self
|
16
|
+
end
|
17
|
+
def jvm_args
|
18
|
+
max_heap ? @jvm_args.sub(/-Xmx\w+/, "-Xmx#{max_heap}") : @jvm_args
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
# Default TorqueSpec options
|
25
|
+
TorqueSpec.configure do |config|
|
26
|
+
config.lazy = true
|
27
|
+
config.host = 'localhost'
|
28
|
+
config.port = 8080
|
29
|
+
config.jboss_home = ENV['JBOSS_HOME']
|
30
|
+
config.jboss_conf = 'default'
|
31
|
+
config.jvm_args = "-Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -Djruby_home.env.ignore=true -Dgem.path=default"
|
32
|
+
end
|
33
|
+
|
data/torquespec.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "torquespec/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "torquespec"
|
7
|
+
s.version = TorqueSpec::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Jim Crossley", "Bob McWhirter"]
|
10
|
+
s.email = "team@projectodd.org"
|
11
|
+
s.homepage = "http://github.com/torquebox/torquespec"
|
12
|
+
s.summary = %q{Deploy TorqueBox knobs to a running JBoss instance}
|
13
|
+
s.description = %q{Write integration tests around the deployment of your app to a real JBoss app server}
|
14
|
+
|
15
|
+
s.rubyforge_project = "torquespec"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
|
22
|
+
s.add_dependency "rspec"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: torquespec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jim Crossley
|
14
|
+
- Bob McWhirter
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-04-26 00:00:00 -04:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rspec
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
version: "0"
|
34
|
+
type: :runtime
|
35
|
+
version_requirements: *id001
|
36
|
+
description: Write integration tests around the deployment of your app to a real JBoss app server
|
37
|
+
email: team@projectodd.org
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- Gemfile
|
47
|
+
- Rakefile
|
48
|
+
- lib/torquespec.rb
|
49
|
+
- lib/torquespec/rspec.rb
|
50
|
+
- lib/torquespec/server.rb
|
51
|
+
- lib/torquespec/torquespec.rb
|
52
|
+
- lib/torquespec/version.rb
|
53
|
+
- torquespec.gemspec
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://github.com/torquebox/torquespec
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
hash: 3
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 3
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
version: "0"
|
81
|
+
requirements: []
|
82
|
+
|
83
|
+
rubyforge_project: torquespec
|
84
|
+
rubygems_version: 1.3.7
|
85
|
+
signing_key:
|
86
|
+
specification_version: 3
|
87
|
+
summary: Deploy TorqueBox knobs to a running JBoss instance
|
88
|
+
test_files: []
|
89
|
+
|