Skip to content

Commit

Permalink
Refactor a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrossley3 committed Oct 23, 2012
1 parent dd915e4 commit 5da211d
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/torquespec/server.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,14 +10,18 @@ def initialize
self.extend( Domain ) if TorqueSpec.domain_mode self.extend( Domain ) if TorqueSpec.domain_mode
end end


def message(s)
RSpec.configuration.reporter.message(s) if TorqueSpec.verbose?
end

def start(opts={}) def start(opts={})
if ready? if ready?
if TorqueSpec.lazy if TorqueSpec.lazy
RSpec.configuration.reporter.message "Using running JBoss (try lazy=false if you get errors)" if TorqueSpec.verbose? message "Using running JBoss (try lazy=false if you get errors)"
return return
else else
stop stop
RSpec.configuration.reporter.message "Waiting for running JBoss to shutdown" if TorqueSpec.verbose? message "Waiting for running JBoss to shutdown"
sleep(5) sleep(5)
sleep(1) while ready? sleep(1) while ready?
self.stopped = false self.stopped = false
Expand All @@ -30,18 +34,18 @@ def stop
return if stopped return if stopped
self.stopped = true self.stopped = true
if TorqueSpec.lazy if TorqueSpec.lazy
RSpec.configuration.reporter.message "JBoss won't be stopped (lazy=true)" if TorqueSpec.verbose? message "JBoss won't be stopped (lazy=true)"
else else
shutdown shutdown
RSpec.configuration.reporter.message "Shutdown message sent to JBoss" if TorqueSpec.verbose? message "Shutdown message sent to JBoss"
end end
end end


def deploy(url) def deploy(url)
t0 = Time.now t0 = Time.now
RSpec.configuration.reporter.message "deploy #{url} " if TorqueSpec.verbose? message "deploy #{url}"
_deploy(url) _deploy(url)
RSpec.configuration.reporter.message "in #{(Time.now - t0).to_i}s" if TorqueSpec.verbose? message "deployed in #{(Time.now - t0).to_i}s"
end end


def undeploy(url) def undeploy(url)
Expand All @@ -54,11 +58,11 @@ def undeploy(url)
end end


def wait_for_ready(timeout) def wait_for_ready(timeout)
RSpec.configuration.reporter.message "Waiting up to #{timeout}s for JBoss to boot" if TorqueSpec.verbose? message "Waiting up to #{timeout}s for JBoss to boot"
t0 = Time.now t0 = Time.now
while (Time.now - t0 < timeout && !stopped) do while (Time.now - t0 < timeout && !stopped) do
if ready? if ready?
RSpec.configuration.reporter.message "JBoss started in #{(Time.now - t0).to_i}s" if TorqueSpec.verbose? message "JBoss started in #{(Time.now - t0).to_i}s"
return true return true
end end
sleep(1) sleep(1)
Expand All @@ -76,7 +80,7 @@ def startup(opts)
self.server_pid = process.pid self.server_pid = process.pid
Thread.new(process) { |console| while(console.gets); end } Thread.new(process) { |console| while(console.gets); end }
%w{ INT TERM KILL }.each { |signal| trap(signal) { stop } } %w{ INT TERM KILL }.each { |signal| trap(signal) { stop } }
RSpec.configuration.reporter.message "#{cmd}\npid=#{process.pid}" if TorqueSpec.verbose? message "#{cmd}\npid=#{process.pid}"
wait > 0 ? wait_for_ready(wait) : process.pid wait > 0 ? wait_for_ready(wait) : process.pid
end end


Expand Down

0 comments on commit 5da211d

Please sign in to comment.