torquespec 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,15 +4,27 @@ module TorqueSpec
4
4
  class Server
5
5
 
6
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
7
+ if ready?
8
+ if TorqueSpec.lazy
9
+ puts "Using running JBoss (try lazy=false if you get errors)"
10
+ return
11
+ else
12
+ stop
13
+ puts "Waiting for running JBoss to shutdown"
14
+ sleep(5)
15
+ sleep(1) while ready?
16
+ end
17
+ end
18
+ startup(opts)
19
+ end
20
+
21
+ def stop
22
+ if TorqueSpec.lazy
23
+ puts "JBoss won't be stopped (lazy=true)"
24
+ else
25
+ shutdown
26
+ puts "Shutdown message sent to JBoss"
27
+ end
16
28
  end
17
29
 
18
30
  def deploy(url)
@@ -27,25 +39,6 @@ module TorqueSpec
27
39
  puts " undeployed #{url.split('/')[-1]}"
28
40
  end
29
41
 
30
- def stop
31
- if TorqueSpec.lazy
32
- puts "JBoss still running, pid=#{@process.pid}"
33
- elsif @process
34
- unless clean_stop
35
- puts "Unable to shutdown JBoss cleanly, interrupting process"
36
- Process.kill("INT", @process.pid)
37
- end
38
- @process = nil
39
- puts "JBoss stopped"
40
- end
41
- end
42
-
43
- def clean_stop
44
- success?( jmx_console( :action => 'invokeOpByName',
45
- :name => 'jboss.system:type=Server',
46
- :methodName => 'shutdown' ) )
47
- end
48
-
49
42
  def ready?
50
43
  response = jmx_console( :action => 'inspectMBean', :name => 'jboss.system:type=Server' )
51
44
  "True" == response.match(/>Started<.*?<pre>\s+^(\w+)/m)[1]
@@ -56,7 +49,7 @@ module TorqueSpec
56
49
  def wait_for_ready(timeout)
57
50
  puts "Waiting up to #{timeout}s for JBoss to boot"
58
51
  t0 = Time.now
59
- while (Time.now - t0 < timeout && @process) do
52
+ while (Time.now - t0 < timeout) do
60
53
  if ready?
61
54
  puts "JBoss started in #{(Time.now - t0).to_i}s"
62
55
  return true
@@ -68,6 +61,22 @@ module TorqueSpec
68
61
 
69
62
  protected
70
63
 
64
+ def startup(opts)
65
+ wait = opts[:wait].to_i
66
+ cmd = command
67
+ process = IO.popen( cmd )
68
+ Thread.new(process) { |console| while(console.gets); end }
69
+ %w{ INT TERM KILL }.each { |signal| trap(signal) { stop } }
70
+ puts "#{cmd}\npid=#{process.pid}"
71
+ wait > 0 ? wait_for_ready(wait) : process.pid
72
+ end
73
+
74
+ def shutdown
75
+ success?( jmx_console( :action => 'invokeOpByName',
76
+ :name => 'jboss.system:type=Server',
77
+ :methodName => 'shutdown' ) )
78
+ end
79
+
71
80
  def command
72
81
  java_home = java.lang::System.getProperty( 'java.home' )
73
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}"
@@ -1,3 +1,3 @@
1
1
  module TorqueSpec
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  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: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
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-02 00:00:00 -04:00
19
+ date: 2011-05-09 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency