torquespec 0.0.6 → 0.1.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.
Binary file
@@ -0,0 +1,55 @@
1
+ module TorqueSpec
2
+ module AS6
3
+
4
+ def port
5
+ 8080
6
+ end
7
+
8
+ def start_command
9
+ "#{ENV['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"
10
+ end
11
+
12
+ def shutdown
13
+ success?( jmx_console( :action => 'invokeOpByName',
14
+ :name => 'jboss.system:type=Server',
15
+ :methodName => 'shutdown' ) )
16
+ end
17
+
18
+ def ready?
19
+ response = jmx_console( :action => 'inspectMBean',
20
+ :name => 'jboss.system:type=Server' )
21
+ "True" == response.match(/>Started<.*?<pre>\s+^(\w+)/m)[1]
22
+ rescue
23
+ false
24
+ end
25
+
26
+ def _deploy(url)
27
+ success?( deployer( 'redeploy', url ) )
28
+ end
29
+
30
+ def _undeploy(url)
31
+ success?( deployer( 'undeploy', url ) )
32
+ end
33
+
34
+
35
+
36
+ private
37
+
38
+ def success?(response)
39
+ response.include?( "Operation completed successfully" )
40
+ end
41
+
42
+ def deployer(method, url)
43
+ jmx_console( :action => 'invokeOpByName',
44
+ :name => 'jboss.system:service=MainDeployer',
45
+ :methodName => method,
46
+ :argType => 'java.net.URL',
47
+ :arg0 => url )
48
+ end
49
+
50
+ def jmx_console(params)
51
+ post('/jmx-console/HtmlAdaptor', params)
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,55 @@
1
+ require 'rubygems'
2
+ require 'json'
3
+ require 'uri'
4
+
5
+ module TorqueSpec
6
+ module AS7
7
+
8
+ def port
9
+ 9990
10
+ end
11
+
12
+ def start_command
13
+ "#{ENV['JAVA_HOME']}/bin/java #{TorqueSpec.jvm_args} -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dorg.jboss.boot.log.file=#{TorqueSpec.jboss_home}/standalone/log/boot.log -Dlogging.configuration=file:#{TorqueSpec.jboss_home}/standalone/configuration/logging.properties -jar #{TorqueSpec.jboss_home}/jboss-modules.jar -mp #{TorqueSpec.jboss_home}/modules -logmodule org.jboss.logmanager -jaxpmodule javax.xml.jaxp-provider org.jboss.as.standalone -Djboss.home.dir=#{TorqueSpec.jboss_home}"
14
+ end
15
+
16
+ def shutdown
17
+ domain_api( :operation => "shutdown" )
18
+ rescue EOFError
19
+ # ignorable
20
+ end
21
+
22
+ def _deploy(path)
23
+ url = urlify(path)
24
+ domain_api( :operation => "add",
25
+ :address => [ "deployment", url ],
26
+ :url => url )
27
+ domain_api( :operation => "deploy",
28
+ :address => [ "deployment", url ] )
29
+ end
30
+
31
+ def _undeploy(path)
32
+ domain_api( :operation => "remove",
33
+ :address => [ "deployment", urlify(path) ] )
34
+ end
35
+
36
+ def ready?
37
+ response = JSON.parse( domain_api( :operation => "read-attribute",
38
+ :name => "server-state") )
39
+ response['outcome']=='success' && response['result']=='RUNNING'
40
+ rescue
41
+ false
42
+ end
43
+
44
+ private
45
+
46
+ def domain_api(params)
47
+ post('/domain-api', params.to_json)
48
+ end
49
+
50
+ def urlify(path)
51
+ URI.parse(path).scheme.nil? ? "file:#{path}" : path
52
+ end
53
+
54
+ end
55
+ end
@@ -1,8 +1,18 @@
1
1
  require 'net/http'
2
+ require 'torquespec/as6'
3
+ require 'torquespec/as7'
2
4
 
3
5
  module TorqueSpec
4
6
  class Server
5
-
7
+
8
+ def initialize
9
+ if File.exist?( File.join( TorqueSpec.jboss_home, "bin/run.sh" ) )
10
+ self.extend AS6
11
+ else
12
+ self.extend AS7
13
+ end
14
+ end
15
+
6
16
  def start(opts={})
7
17
  if ready?
8
18
  if TorqueSpec.lazy
@@ -13,12 +23,15 @@ module TorqueSpec
13
23
  puts "Waiting for running JBoss to shutdown"
14
24
  sleep(5)
15
25
  sleep(1) while ready?
26
+ self.stopped = false
16
27
  end
17
28
  end
18
29
  startup(opts)
19
30
  end
20
31
 
21
32
  def stop
33
+ return if stopped
34
+ self.stopped = true
22
35
  if TorqueSpec.lazy
23
36
  puts "JBoss won't be stopped (lazy=true)"
24
37
  else
@@ -30,26 +43,19 @@ module TorqueSpec
30
43
  def deploy(url)
31
44
  t0 = Time.now
32
45
  puts "#{url}"
33
- success?( deployer( 'redeploy', url ) )
46
+ _deploy(url)
34
47
  puts " deployed in #{(Time.now - t0).to_i}s"
35
48
  end
36
49
 
37
50
  def undeploy(url)
38
- success?( deployer( 'undeploy', url ) )
51
+ _undeploy(url)
39
52
  puts " undeployed #{url.split('/')[-1]}"
40
53
  end
41
54
 
42
- def ready?
43
- response = jmx_console( :action => 'inspectMBean', :name => 'jboss.system:type=Server' )
44
- "True" == response.match(/>Started<.*?<pre>\s+^(\w+)/m)[1]
45
- rescue
46
- false
47
- end
48
-
49
55
  def wait_for_ready(timeout)
50
56
  puts "Waiting up to #{timeout}s for JBoss to boot"
51
57
  t0 = Time.now
52
- while (Time.now - t0 < timeout) do
58
+ while (Time.now - t0 < timeout && !stopped) do
53
59
  if ready?
54
60
  puts "JBoss started in #{(Time.now - t0).to_i}s"
55
61
  return true
@@ -63,7 +69,7 @@ module TorqueSpec
63
69
 
64
70
  def startup(opts)
65
71
  wait = opts[:wait].to_i
66
- cmd = command
72
+ cmd = start_command
67
73
  process = IO.popen( cmd )
68
74
  Thread.new(process) { |console| while(console.gets); end }
69
75
  %w{ INT TERM KILL }.each { |signal| trap(signal) { stop } }
@@ -71,37 +77,18 @@ module TorqueSpec
71
77
  wait > 0 ? wait_for_ready(wait) : process.pid
72
78
  end
73
79
 
74
- def shutdown
75
- success?( jmx_console( :action => 'invokeOpByName',
76
- :name => 'jboss.system:type=Server',
77
- :methodName => 'shutdown' ) )
78
- end
79
-
80
- def command
81
- java_home = java.lang::System.getProperty( 'java.home' )
82
- "#{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}"
83
- end
84
-
85
- def deployer(method, url)
86
- jmx_console( :action => 'invokeOpByName',
87
- :name => 'jboss.system:service=MainDeployer',
88
- :methodName => method,
89
- :argType => 'java.net.URL',
90
- :arg0 => url )
91
- end
92
-
93
- def success?(response)
94
- response.include?( "Operation completed successfully" )
95
- end
96
-
97
- def jmx_console(params)
98
- req = Net::HTTP::Post.new('/jmx-console/HtmlAdaptor')
99
- req.set_form_data( params )
80
+ def post(path, params)
81
+ req = Net::HTTP::Post.new(path)
82
+ if (params.is_a? Hash)
83
+ req.set_form_data( params )
84
+ else
85
+ req.body = params
86
+ end
100
87
  http( req )
101
88
  end
102
89
 
103
90
  def http req
104
- res = Net::HTTP.start(TorqueSpec.host, TorqueSpec.port) do |http|
91
+ res = Net::HTTP.start('localhost', port) do |http|
105
92
  http.read_timeout = 180
106
93
  http.request(req)
107
94
  end
@@ -112,6 +99,7 @@ module TorqueSpec
112
99
  res.body
113
100
  end
114
101
 
102
+ attr_accessor :stopped
115
103
  end
116
104
 
117
105
  end
@@ -28,11 +28,9 @@ end
28
28
  # Default TorqueSpec options
29
29
  TorqueSpec.configure do |config|
30
30
  config.knob_root = ".torquespec"
31
- config.lazy = true
32
- config.host = 'localhost'
33
- config.port = 8080
31
+ config.lazy = false
34
32
  config.jboss_home = ENV['JBOSS_HOME']
35
33
  config.jboss_conf = 'default'
36
- config.jvm_args = "-Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -Djruby_home.env.ignore=true -Dgem.path=default"
34
+ config.jvm_args = "-Xms64m -Xmx1024m -XX:MaxPermSize=512m -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+CMSClassUnloadingEnabled -Djruby_home.env.ignore=true -Dgem.path=default"
37
35
  end
38
36
 
@@ -1,3 +1,3 @@
1
1
  module TorqueSpec
2
- VERSION = "0.0.6"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -0,0 +1,14 @@
1
+ require 'torquespec'
2
+ require 'open-uri'
3
+
4
+ TorqueSpec.lazy = false
5
+
6
+ describe "simple deployment" do
7
+
8
+ deploy File.join( File.dirname(__FILE__), "../apps/simple.knob" )
9
+
10
+ it "should greet the world" do
11
+ response = open("http://localhost:8080") {|f| f.read}
12
+ response.strip.should == "Hello World!"
13
+ end
14
+ end
@@ -20,4 +20,5 @@ Gem::Specification.new do |s|
20
20
  s.require_paths = ["lib"]
21
21
 
22
22
  s.add_dependency "rspec"
23
+ s.add_dependency "json"
23
24
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torquespec
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 6
10
- version: 0.0.6
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jim Crossley
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-05-09 00:00:00 -04:00
19
+ date: 2011-05-15 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -33,6 +33,20 @@ dependencies:
33
33
  version: "0"
34
34
  type: :runtime
35
35
  version_requirements: *id001
36
+ - !ruby/object:Gem::Dependency
37
+ name: json
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ hash: 3
45
+ segments:
46
+ - 0
47
+ version: "0"
48
+ type: :runtime
49
+ version_requirements: *id002
36
50
  description: Write integration tests around the deployment of your app to a real JBoss app server
37
51
  email: team@projectodd.org
38
52
  executables: []
@@ -46,12 +60,16 @@ files:
46
60
  - Gemfile
47
61
  - README.md
48
62
  - Rakefile
63
+ - apps/simple.knob
49
64
  - lib/torquespec.rb
65
+ - lib/torquespec/as6.rb
66
+ - lib/torquespec/as7.rb
50
67
  - lib/torquespec/deployment_descriptor.rb
51
68
  - lib/torquespec/rspec.rb
52
69
  - lib/torquespec/server.rb
53
70
  - lib/torquespec/torquespec.rb
54
71
  - lib/torquespec/version.rb
72
+ - spec/hello_world_spec.rb
55
73
  - torquespec.gemspec
56
74
  has_rdoc: true
57
75
  homepage: http://github.com/torquebox/torquespec
@@ -87,5 +105,5 @@ rubygems_version: 1.3.7
87
105
  signing_key:
88
106
  specification_version: 3
89
107
  summary: Deploy TorqueBox knobs to a running JBoss instance
90
- test_files: []
91
-
108
+ test_files:
109
+ - spec/hello_world_spec.rb