class FakeSQS::TestIntegration

Attributes

options[R]

Public Class Methods

new(options = {}) click to toggle source
# File lib/fake_sqs/test_integration.rb, line 8
def initialize(options = {})
  @options = options
end

Public Instance Methods

expire() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 45
def expire
  connection.put("/", "")
end
host() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 12
def host
  option :sqs_endpoint
end
port() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 16
def port
  option :sqs_port
end
reset() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 41
def reset
  connection.delete("/")
end
start() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 20
def start
  start! unless up?
  reset
end
start!() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 25
def start!
  args = [ binfile, "-p", port.to_s, verbose, logging, "--database", database, { :out => out, :err => out } ].flatten.compact
  @pid = Process.spawn(*args)
  wait_until_up(Time.now + start_timeout)
end
stop() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 31
def stop
  if @pid
    Process.kill("INT", @pid)
    Process.waitpid(@pid)
    @pid = nil
  else
    $stderr.puts "FakeSQS is not running"
  end
end
up?() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 57
def up?
  @pid && connection.get("/ping").code.to_s == "200"
rescue Errno::ECONNREFUSED
  false
end
uri() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 53
def uri
  URI(url)
end
url() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 49
def url
  "http://#{host}:#{port}"
end

Private Instance Methods

binfile() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 101
def binfile
  File.expand_path("../../../bin/fake_sqs", __FILE__)
end
connection() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 113
def connection
  @connection ||= Net::HTTP.new(host, port)
end
database() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 69
def database
  options.fetch(:database)
end
debug?() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 117
def debug?
  ENV["DEBUG"].to_s == "true" || options[:debug]
end
logging() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 85
def logging
  if (file = ENV["SQS_LOG"] || options[:log])
    [ "--log", file ]
  else
    []
  end
end
option(key) click to toggle source
# File lib/fake_sqs/test_integration.rb, line 65
def option(key)
  options.fetch(key)
end
out() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 105
def out
  if debug?
    :out
  else
    "/dev/null"
  end
end
start_timeout() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 73
def start_timeout
  options[:start_timeout] || 2
end
verbose() click to toggle source
# File lib/fake_sqs/test_integration.rb, line 77
def verbose
  if options[:verbose]
    "--verbose"
  else
    "--no-verbose"
  end
end
wait_until_up(deadline) click to toggle source
# File lib/fake_sqs/test_integration.rb, line 93
def wait_until_up(deadline)
  fail "FakeSQS didn't start in time" if Time.now > deadline
  unless up?
    sleep 0.1
    wait_until_up(deadline)
  end
end