iron_mq 1.5.0 → 1.7.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.
data/Rakefile CHANGED
@@ -10,8 +10,7 @@ begin
10
10
  gem.email = "travis@iron.io"
11
11
  gem.homepage = "http://www.iron.io"
12
12
  gem.authors = ["Travis Reeder"]
13
- gem.add_dependency 'rest-client'
14
- gem.add_dependency 'rest'
13
+ gem.add_dependency 'iron_core'
15
14
  #gem.add_dependency 'typhoeus'
16
15
  gem.required_ruby_version = '>= 1.9'
17
16
  end
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 1
3
- :minor: 5
3
+ :minor: 7
4
4
  :patch: 0
5
- :build: !!null
5
+ :build:
data/iron_mq.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "iron_mq"
8
- s.version = "1.5.0"
8
+ s.version = "1.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Travis Reeder"]
12
- s.date = "2012-03-02"
12
+ s.date = "2012-06-04"
13
13
  s.description = "Ruby client for IronMQ"
14
14
  s.email = "travis@iron.io"
15
15
  s.extra_rdoc_files = [
@@ -37,28 +37,22 @@ Gem::Specification.new do |s|
37
37
  s.homepage = "http://www.iron.io"
38
38
  s.require_paths = ["lib"]
39
39
  s.required_ruby_version = Gem::Requirement.new(">= 1.9")
40
- s.rubygems_version = "1.8.15"
40
+ s.rubygems_version = "1.8.24"
41
41
  s.summary = "Ruby client for IronMQ"
42
42
 
43
43
  if s.respond_to? :specification_version then
44
44
  s.specification_version = 3
45
45
 
46
46
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
48
- s.add_runtime_dependency(%q<rest>, [">= 0"])
49
- s.add_runtime_dependency(%q<rest-client>, [">= 0"])
50
- s.add_runtime_dependency(%q<rest>, [">= 0"])
47
+ s.add_runtime_dependency(%q<iron_core>, [">= 0"])
48
+ s.add_runtime_dependency(%q<iron_core>, [">= 0"])
51
49
  else
52
- s.add_dependency(%q<rest-client>, [">= 0"])
53
- s.add_dependency(%q<rest>, [">= 0"])
54
- s.add_dependency(%q<rest-client>, [">= 0"])
55
- s.add_dependency(%q<rest>, [">= 0"])
50
+ s.add_dependency(%q<iron_core>, [">= 0"])
51
+ s.add_dependency(%q<iron_core>, [">= 0"])
56
52
  end
57
53
  else
58
- s.add_dependency(%q<rest-client>, [">= 0"])
59
- s.add_dependency(%q<rest>, [">= 0"])
60
- s.add_dependency(%q<rest-client>, [">= 0"])
61
- s.add_dependency(%q<rest>, [">= 0"])
54
+ s.add_dependency(%q<iron_core>, [">= 0"])
55
+ s.add_dependency(%q<iron_core>, [">= 0"])
62
56
  end
63
57
  end
64
58
 
@@ -1,29 +1,34 @@
1
- require 'json'
2
- require 'logger'
3
- require 'rest'
1
+ require 'yaml'
2
+
3
+ require 'iron_core'
4
4
 
5
5
  module IronMQ
6
+ @@version = nil
6
7
 
7
- class Client
8
+ def self.version
9
+ if @@version.nil?
10
+ v = YAML.load(File.read(File.dirname(__FILE__) + '/../../VERSION.yml'))
11
+ $stderr.puts v.inspect
12
+ @@version = [v[:major].to_s, v[:minor].to_s, v[:patch].to_s].join('.')
13
+ end
8
14
 
9
- attr_accessor :token, :project_id, :queue_name, :logger,
10
- :scheme, :host, :port
15
+ @@version
16
+ end
11
17
 
12
- def initialize(options={})
13
- @logger = Logger.new(STDOUT)
14
- @logger.level=Logger::INFO
18
+ class Client < IronCore::Client
19
+ AWS_US_EAST_HOST = 'mq-aws-us-east-1.iron.io'
15
20
 
16
- @token = options[:token] || options['token']
17
- @project_id = options[:project_id] || options['project_id']
18
- @queue_name = options[:queue_name] || options['queue_name'] || "default"
19
- @scheme = options[:scheme] || options['scheme'] || "https"
20
- @host = options[:host] || options['host'] || "mq-aws-us-east-1.iron.io"
21
- @port = options[:port] || options['port'] || 443
21
+ attr_accessor :queue_name
22
22
 
23
- @base_url = "#{@scheme}://#{@host}:#{@port}/1"
23
+ def initialize(options={})
24
+ super('mq', options, [:queue_name])
24
25
 
25
- @rest = Rest::Client.new
26
+ load_from_hash(:scheme => 'https', :host => IronMQ::Client::AWS_US_EAST_HOST, :port => 443, :api_version => 1, :user_agent => 'iron_mq_ruby-' + IronMQ.version + ' (iron_core_ruby-' + IronCore.version + ')', :queue_name => 'default')
26
27
 
28
+ if (not @token) || (not @project_id)
29
+ IronCore::Logger.error 'IronMQ', 'Both token and project_id must be specified'
30
+ raise IronCore::IronError.new('Both token and project_id must be specified')
31
+ end
27
32
  end
28
33
 
29
34
  def messages
@@ -33,105 +38,5 @@ module IronMQ
33
38
  def queues
34
39
  return Queues.new(self)
35
40
  end
36
-
37
- def base_url
38
- #"#{scheme}://#{host}:#{port}/1"
39
- @base_url
40
- end
41
-
42
- def full_url(path)
43
- url = "#{base_url}#{path}"
44
- url
45
- end
46
-
47
- def common_req_hash
48
- {
49
- :headers=>{"Content-Type" => 'application/json',
50
- "Authorization"=>"OAuth #{@token}",
51
- "User-Agent"=>"IronMQ Ruby Client"}
52
- }
53
- end
54
-
55
-
56
- def get(path, params={})
57
- url = full_url(path)
58
- @logger.debug 'url=' + url
59
- req_hash = common_req_hash
60
- req_hash[:params] = params if params
61
- @logger.debug 'req_hash=' + req_hash.inspect
62
- response = @rest.get(url, req_hash)
63
- @logger.debug 'GET response=' + response.inspect
64
- res = check_response(response)
65
- return res, response.code
66
- end
67
-
68
- def post(path, params={})
69
- url = full_url(path)
70
- @logger.debug 'url=' + url
71
- #response = @http_sess.post(path + "?oauth=#{@token}", {'oauth' => @token}.merge(params).to_json, {"Content-Type" => 'application/json'})
72
- req_hash = common_req_hash
73
- req_hash[:body] = params.to_json
74
- response = @rest.post(url, req_hash)
75
- @logger.debug 'POST response=' + response.inspect
76
- res = check_response(response)
77
- #@logger.debug 'response: ' + res.inspect
78
- #body = response.body
79
- #res = JSON.parse(body)
80
- return res, response.code
81
- end
82
-
83
-
84
- def delete(path, params={})
85
- url = "#{base_url}#{path}"
86
- @logger.debug 'url=' + url
87
- req_hash = common_req_hash
88
- req_hash[:params] = params
89
- response = @rest.delete(url, req_hash)
90
- res = check_response(response)
91
- #body = response.body
92
- #res = JSON.parse(body)
93
- #@logger.debug 'response: ' + res.inspect
94
- return res, response.code
95
- end
96
-
97
- def check_response(response)
98
- # response.code # http status code
99
- #response.time # time in seconds the request took
100
- #response.headers # the http headers
101
- #response.headers_hash # http headers put into a hash
102
- #response.body # the response body
103
- status = response.code
104
- body = response.body
105
- # todo: check content-type == application/json before parsing
106
- @logger.debug "response code=" + status.to_s
107
- @logger.debug "response body=" + body.inspect
108
- begin
109
- res = JSON.parse(body)
110
- rescue => ex
111
- # an unexpected error response
112
- raise IronMQ::Error.new("Status #{status}: #{ex.class.name}: #{ex.message}", :status=>status)
113
- end
114
- if status < 400
115
-
116
- else
117
- raise IronMQ::Error.new("Status #{status}: #{res["msg"]}", :status=>status)
118
- end
119
- res
120
- end
121
-
122
41
  end
123
-
124
- class Error < StandardError
125
- def initialize(msg, options={})
126
- super(msg)
127
- @options = options
128
- end
129
-
130
- def status
131
- @options[:status]
132
- end
133
- end
134
-
135
-
136
42
  end
137
-
@@ -8,36 +8,27 @@ module IronMQ
8
8
  end
9
9
 
10
10
  def path(options={})
11
- path = "/projects/#{@client.project_id}/queues/#{options[:queue_name] || @client.queue_name}/messages"
11
+ path = "projects/#{@client.project_id}/queues/#{options[:queue_name] || options['queue_name'] || @client.queue_name}/messages"
12
12
  end
13
13
 
14
14
  # options:
15
15
  # :queue_name => can specify an alternative queue name
16
16
  # :timeout => amount of time before message goes back on the queue
17
17
  def get(options={})
18
- begin
19
- res, status = @client.get(path(options), options)
20
- @client.logger.debug "GET response: " + res.inspect
21
- ret = []
22
- res["messages"].each do |m|
23
- ret << Message.new(self, m)
24
- end
25
- if options[:n]
26
- return ret
18
+ res = @client.parse_response(@client.get(path(options), options))
19
+ ret = []
20
+ res["messages"].each do |m|
21
+ ret << Message.new(self, m)
22
+ end
23
+ if options[:n] || options['n']
24
+ return ret
25
+ else
26
+ if ret.size > 0
27
+ return ret[0]
27
28
  else
28
- if ret.size > 0
29
- return ret[0]
30
- else
31
- return nil
32
- end
33
- end
34
- rescue IronMQ::Error => ex
35
- if ex.status == 404
36
29
  return nil
37
30
  end
38
- raise ex
39
31
  end
40
-
41
32
  end
42
33
 
43
34
  # options:
@@ -57,8 +48,7 @@ module IronMQ
57
48
  end
58
49
  to_send = {}
59
50
  to_send[:messages] = msgs
60
- res, status = @client.post(path(options), to_send)
61
- #return Message.new(self, res)
51
+ res = @client.parse_response(@client.post(path(options), to_send))
62
52
  if batch
63
53
  return res
64
54
  else
@@ -68,7 +58,7 @@ module IronMQ
68
58
 
69
59
  def delete(message_id, options={})
70
60
  path2 = "#{self.path(options)}/#{message_id}"
71
- res, status = @client.delete(path2)
61
+ res = @client.parse_response(@client.delete(path2))
72
62
  return ResponseBase.new(res)
73
63
  end
74
64
 
@@ -8,12 +8,14 @@ module IronMQ
8
8
  end
9
9
 
10
10
  def path(options={})
11
- path = "/projects/#{@client.project_id}/queues"
11
+ path = "projects/#{@client.project_id}/queues"
12
12
  end
13
13
 
14
14
  def list(options={})
15
15
  ret = []
16
- res, status = @client.get("#{path(options)}", options)
16
+ r1 = @client.get("#{path(options)}", options)
17
+ #p r1
18
+ res = @client.parse_response(r1)
17
19
  res.each do |q|
18
20
  #p q
19
21
  q = Queue.new(self, q)
@@ -25,7 +27,7 @@ module IronMQ
25
27
  # options:
26
28
  # :name => can specify an alternative queue name
27
29
  def get(options={})
28
- res, status = @client.get("#{path(options)}/#{options[:name]}")
30
+ res = @client.parse_response(@client.get("#{path(options)}/#{options[:name]}"))
29
31
  return Queue.new(self, res)
30
32
  end
31
33
 
data/test/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'http://rubygems.org'
2
2
  gem 'beanstalk-client'
3
3
  gem 'test-unit'
4
4
  gem 'concur'
5
+ gem 'uber_config'
6
+ gem 'iron_core'
data/test/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.2.6)
4
+ addressable (2.2.8)
5
5
  beanstalk-client (1.1.1)
6
6
  concur (0.1.2)
7
7
  em-http-request
@@ -11,23 +11,31 @@ GEM
11
11
  faraday
12
12
  faraday
13
13
  cookiejar (0.3.0)
14
- em-http-request (1.0.1)
14
+ em-http-request (1.0.2)
15
15
  addressable (>= 2.2.3)
16
16
  cookiejar
17
17
  em-socksify
18
18
  eventmachine (>= 1.0.0.beta.4)
19
19
  http_parser.rb (>= 0.5.3)
20
- em-socksify (0.1.0)
21
- eventmachine
20
+ em-socksify (0.2.0)
21
+ eventmachine (>= 1.0.0.beta.4)
22
22
  eventmachine (1.0.0.beta.4)
23
- faraday (0.7.5)
24
- addressable (~> 2.2.6)
25
- multipart-post (~> 1.1.3)
26
- rack (>= 1.1.0, < 2)
23
+ faraday (0.8.1)
24
+ multipart-post (~> 1.1)
27
25
  http_parser.rb (0.5.3)
28
- multipart-post (1.1.4)
29
- rack (1.4.0)
30
- test-unit (2.4.4)
26
+ iron_core (0.1.2)
27
+ bundler (> 1.0.0)
28
+ rest
29
+ rest-client
30
+ mime-types (1.18)
31
+ multipart-post (1.1.5)
32
+ rest (0.2.0)
33
+ rest-client
34
+ rest-client
35
+ rest-client (1.6.7)
36
+ mime-types (>= 1.16)
37
+ test-unit (2.4.9)
38
+ uber_config (0.0.1)
31
39
 
32
40
  PLATFORMS
33
41
  ruby
@@ -35,4 +43,6 @@ PLATFORMS
35
43
  DEPENDENCIES
36
44
  beanstalk-client
37
45
  concur
46
+ iron_core
38
47
  test-unit
48
+ uber_config
@@ -14,7 +14,7 @@ class LongRunWorker < IronWorker::Base
14
14
 
15
15
  start = Time.now
16
16
  puts "Queuing #{@num_to_add} items at #{start}..."
17
- executor = Concur::Executor.new_thread_pool_executor(20)
17
+ executor = Concur::Executor.new_thread_pool_executor(50)
18
18
  @num_to_add.times do |i|
19
19
  task = executor.execute do
20
20
  begin
@@ -31,7 +31,7 @@ class LongRunWorker < IronWorker::Base
31
31
  while executor.queue_size > 0 do
32
32
  i += 1
33
33
  puts "waiting #{i}, queue size=#{executor.queue_size}"
34
- sleep 0.5
34
+ sleep 2
35
35
  end
36
36
 
37
37
 
data/test/schedule_abt.rb CHANGED
@@ -1,4 +1,27 @@
1
- worker = Abt::TestWorker.new
1
+ require 'abt'
2
+ require 'time'
3
+ require_relative 'test_base'
4
+
5
+ # Config for abt tests to run on IronWorker
6
+ @abt_config = YAML::load_file(File.expand_path(File.join("~", "Dropbox", "configs", "abt", "test", "config.yml")))
7
+ IronWorker.configure do |c|
8
+ c.token = @abt_config['iron']['token']
9
+ c.project_id = @abt_config['iron']['project_id']
10
+ end
11
+
12
+ # IronWorker.logger.level = Logger::DEBUG
13
+ # Config to run iron_mq_ruby tests
14
+ @test_config = TestBase.load_config
15
+
16
+ worker = Abt::AbtWorker.new
2
17
  worker.git_url = "git://github.com/iron-io/iron_mq_ruby.git"
3
18
  worker.test_config = @test_config
4
- worker.run_local
19
+ worker.add_notifier(:hip_chat_notifier, :config=>@abt_config["hipchat"])
20
+ worker.upload # Must upload after adding notifier to ensure it's merged
21
+ #worker.run_local
22
+ #worker.queue
23
+ #status = worker.wait_until_complete
24
+ #p status
25
+ #puts "LOG:"
26
+ #puts worker.get_log
27
+ #worker.schedule(:start_at=>Time.now.iso8601, :run_every=>3600)
data/test/test_base.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  gem 'test-unit'
2
2
  require 'test/unit'
3
3
  require 'yaml'
4
+ require 'uber_config'
4
5
  begin
5
6
  require File.join(File.dirname(__FILE__), '../lib/iron_mq')
6
7
  rescue Exception => ex
@@ -13,29 +14,14 @@ class TestBase < Test::Unit::TestCase
13
14
  def setup
14
15
  puts 'setup'
15
16
  # check multiple config locations
16
- @config = load_config
17
+ @config = UberConfig.load
17
18
  puts "config=" + @config.inspect
18
- @client = IronMQ::Client.new(@config['iron_mq'])
19
- @client.logger.level = Logger::DEBUG
19
+ @client = IronMQ::Client.new(@config['iron'])
20
+ IronCore::Logger.logger.level = Logger::DEBUG
20
21
  @client.queue_name = 'ironmq-ruby-tests'
21
22
 
22
23
  end
23
24
 
24
- def load_config
25
- # check for config
26
- # First check if running in abt worker
27
- if defined? $abt_config
28
- @config = $abt_config
29
- return @config
30
- end
31
- cf = File.expand_path(File.join("~", "Dropbox", "configs", "iron_mq_ruby", "test", "config.yml"))
32
- if File.exist?(cf)
33
- @config = YAML::load_file(cf)
34
- return @config
35
- end
36
-
37
- end
38
-
39
25
 
40
26
  def clear_queue(queue_name=nil)
41
27
  queue_name ||= @client.queue_name
@@ -8,46 +8,219 @@ require 'beanstalk-client'
8
8
  require 'yaml'
9
9
  require_relative 'test_base'
10
10
 
11
- class IronMQTests < TestBase
11
+ class BeanstalkTests < TestBase
12
12
  def setup
13
13
  super
14
14
 
15
+ config = @config['iron']
16
+ @host = "#{config['host'] || "mq-aws-us-east-1.iron.io"}:#{config['beanstalkd_port'] || 11300}"
17
+ puts "beanstalkd url: #{@host}"
18
+ @skip = @host.include? 'rackspace'
19
+ return if @skip # bypass these tests if rackspace
20
+ @beanstalk = Beanstalk::Connection.new(@host)
21
+ @beanstalk.put("oauth #{config['token']} #{config['project_id']}")
22
+
23
+ clear_tube('default')
15
24
  end
16
25
 
17
- def test_beanstalk
18
- puts 'test_beanstalk'
19
- config = @config['iron_mq']
20
- h = "#{config['host']||"mq-aws-us-east-1.iron.io"}:#{config['beanstalkd_port']||11300}"
21
- puts "beanstalkd url: #{h}"
22
- beanstalk = Beanstalk::Connection.new(h)
23
- beanstalk.put("oauth #{config['token']} #{config['project_id']}")
26
+ def test_basics
27
+ omit_if @skip # bypass this test if rackspace
28
+ puts 'test_basics'
29
+
24
30
  queue_name = "beanstalk_test"
25
31
  clear_queue(queue_name)
26
- beanstalk.use(queue_name)
27
- beanstalk.watch(queue_name)
32
+ @beanstalk.use(queue_name)
33
+ @beanstalk.watch(queue_name)
34
+
35
+ #puts 'reserving...'
36
+ #job = beanstalk.reserve(1)
37
+ #p job
38
+ #exit
28
39
 
29
40
  msg = "hello #{Time.now}"
30
- beanstalk.put(msg)
31
- job = beanstalk.reserve
32
- assert_equal msg, job.body, "body not the same as message."
41
+ puts "msg=" + msg
42
+ @beanstalk.put(msg)
43
+ job = @beanstalk.reserve
44
+ p job
45
+ p job.body
46
+ assert_equal msg, job.body, "job.body #{job.body} not the same as the one we put on #{msg}."
33
47
  job.delete
34
48
  job = assert_raise(Beanstalk::TimedOut) {
35
- beanstalk.reserve(1)
49
+ @beanstalk.reserve(1)
36
50
  }
37
51
 
38
52
  hasher = {:x => 1, :y => "hello", "yo" => "scooby doo"}
39
- beanstalk.put(hasher.to_json)
40
- job = beanstalk.reserve(1)
53
+ @beanstalk.put(hasher.to_json)
54
+ job = @beanstalk.reserve(1)
55
+ got = JSON.parse(job.body)
56
+ assert got.is_a?(Hash)
57
+ assert_equal hasher[:x], got['x']
58
+ job.delete
59
+
60
+ msg = "hello there\nthis is a new line"
61
+ @beanstalk.put(msg)
62
+ job = @beanstalk.reserve(1)
63
+ assert_equal msg, job.body, "#{job.body} does not equal #{msg}"
64
+ job.delete
65
+ end
66
+
67
+ def clear_tube(tube)
68
+ omit_if @skip # bypass this test if rackspace
69
+ watched = @beanstalk.list_tubes_watched(true)
70
+ puts 'watched: ' + watched.inspect
71
+ @beanstalk.watch(tube)
72
+ puts "clear #{tube}"
73
+ # clean up anything in queue
74
+ while x = reserve(0) do
75
+ puts 'deleting ' + x.inspect
76
+ x.delete
77
+ end
78
+ puts 'done clearing'
79
+ @beanstalk.ignore(tube) if not watched.include?(tube)
80
+ end
81
+
82
+ def test_basics2
83
+ omit_if @skip # bypass this test if rackspace
84
+ puts 'test_basics'
85
+ msg = "hello #{Time.now}"
86
+ @beanstalk.put(msg)
87
+ job = reserve
88
+ puts 'first job: ' + job.inspect
89
+ puts "body=" + job.body # prints "hello"
90
+ assert_equal msg, job.body, "body not the same as message."
91
+ job.delete
92
+ puts 'deleted'
93
+ job = reserve(1)
94
+ puts 'second job = ' + job.inspect
95
+ assert job.nil?, "second job was not nil " + job.inspect
96
+
97
+ hasher = {:x => 1, :y => "hello", "yo" => "scooby doo"}
98
+ @beanstalk.put(hasher.to_json)
99
+ job = reserve(1)
41
100
  got = JSON.parse(job.body)
101
+ puts 'got=' + got.inspect
42
102
  assert got.is_a?(Hash)
43
103
  assert_equal hasher[:x], got['x']
44
104
  job.delete
45
105
 
46
106
  msg = "hello there\nthis is a new line"
47
- beanstalk.put(msg)
48
- job = beanstalk.reserve(1)
107
+ @beanstalk.put(msg)
108
+ job = reserve(1)
49
109
  assert_equal msg, job.body, "#{job.body} does not equal #{msg}"
50
110
  job.delete
51
111
  end
52
112
 
113
+ def test_timeout
114
+ omit_if @skip # bypass this test if rackspace
115
+ puts 'test_timeout'
116
+ msg = "timeout message #{Time.now}"
117
+ # timeout of 10 seconds
118
+ res = @beanstalk.put(msg, 65536, 0, 10)
119
+ puts 'result: ' + res.inspect
120
+ job = reserve(0)
121
+ puts 'first timeout job: ' + job.inspect
122
+ assert_equal msg, job.body, "body not the same as message."
123
+
124
+ niljob = reserve(0)
125
+ assert niljob.nil?, "job is not nil! #{niljob.inspect}"
126
+
127
+ # let it time out
128
+ sleep 10
129
+ job = reserve(0)
130
+ puts 'second delayed job: ' + job.inspect
131
+ assert_not_nil job, "job is nil"
132
+ assert_equal msg, job.body, "body not the same as message."
133
+ job.delete
134
+ end
135
+
136
+ def test_delay
137
+ omit_if @skip # bypass this test if rackspace
138
+ puts 'test_delay'
139
+ msg = "delayed message #{Time.now}"
140
+ # delay of 2 seconds
141
+ @beanstalk.put(msg, 65536, 2)
142
+
143
+ # delay should still be in effect, so job is nil
144
+ job = reserve(0)
145
+ assert job.nil?, "job is not nil"
146
+
147
+ # wait for delay to expire
148
+ sleep 2
149
+ job = reserve(0)
150
+ assert_not_nil job, "job is nil"
151
+ assert_equal msg, job.body, "body not the same as message."
152
+ job.delete
153
+ end
154
+
155
+ def tube_message(tube)
156
+ omit_if @skip # bypass this test if rackspace
157
+ "hello #{tube}! #{Time.now}"
158
+ end
159
+
160
+ def reserve(timeout=nil)
161
+ omit_if @skip # bypass this test if rackspace
162
+ begin
163
+ job = @beanstalk.reserve(timeout)
164
+ puts 'got job: ' + job.inspect
165
+ return job
166
+ rescue Beanstalk::TimedOut => ex
167
+ puts "Timed out: #{ex.message}"
168
+ return nil
169
+ end
170
+ end
171
+
172
+ def test_tubes
173
+ omit_if @skip # bypass this test if rackspace
174
+ clear_tube('youtube')
175
+ tube1 = 'default'
176
+ msg1 = tube_message(tube1)
177
+ @beanstalk.put(msg1)
178
+ tube2 = 'youtube'
179
+ @beanstalk.use(tube2) # switch tubes to put messages on
180
+ msg2 = tube_message(tube2)
181
+ @beanstalk.put(msg2)
182
+ # now we have a single message in two different tubes.
183
+ # let's first try to ensure we only get the one off the default tube.
184
+ job = reserve(1)
185
+ assert_equal msg1, job.body, "body #{job.body.to_s} does not equal #{msg1}"
186
+ job.delete
187
+ # second message should not come off since we're not watching that tube.
188
+ job = reserve(1)
189
+ assert job.nil?, "second job was not nil " + job.inspect
190
+
191
+ @beanstalk.watch(tube2)
192
+ job = reserve(1)
193
+ assert_equal msg2, job.body, "body #{job.body.to_s} does not equal #{msg2}"
194
+ job.delete
195
+
196
+ # Now that we're watching both tubes we should get messages put into either.
197
+ @beanstalk.use(tube1)
198
+ msg3 = tube_message(tube1)
199
+ @beanstalk.put(msg3)
200
+ job = reserve(1)
201
+ assert_equal msg3, job.body
202
+ job.delete
203
+
204
+ # now put one in default and one in tube2, then we'll ignore default
205
+ msg1 = tube_message(tube1)
206
+ @beanstalk.put(msg1)
207
+ @beanstalk.use(tube2) # switch tubes to put messages on
208
+ msg2 = tube_message(tube2)
209
+ @beanstalk.put(msg2)
210
+
211
+ @beanstalk.ignore(tube1)
212
+ job = reserve(1)
213
+ assert_equal msg2, job.body, "body #{job.body.to_s} does not equal #{msg2}"
214
+ job.delete
215
+ job = reserve(1)
216
+ assert job.nil?
217
+
218
+ # clean up the last message from default
219
+ @beanstalk.watch(tube1)
220
+ job = reserve(1)
221
+ assert_equal msg1, job.body, "body #{job.body.to_s} does not equal #{msg1}"
222
+ job.delete
223
+ end
224
+
225
+
53
226
  end
data/test/test_iron_mq.rb CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  gem 'test-unit'
6
6
  require 'test/unit'
7
- require 'beanstalk-client'
8
7
  require 'yaml'
9
8
  require_relative 'test_base'
10
9
 
@@ -23,18 +22,14 @@ class IronMQTests < TestBase
23
22
  @client.queue_name = 'test_basics'
24
23
  clear_queue
25
24
 
26
- queue = @client.queues.get(:name=>@client.queue_name)
27
- total_messages = queue.total_messages
28
-
29
25
  res = @client.messages.post("hello world!")
30
26
  p res
31
27
  assert res["id"]
32
28
  assert res.id
33
29
  assert res.msg
34
30
 
35
- queue = @client.queues.get(:name=>@client.queue_name)
31
+ queue = @client.queues.get(:name => @client.queue_name)
36
32
  assert queue.size == 1
37
- assert queue.total_messages == (total_messages+1)
38
33
  res = @client.messages.get()
39
34
  p res
40
35
  assert res["id"]
@@ -47,7 +42,7 @@ class IronMQTests < TestBase
47
42
  p res
48
43
  assert res.nil?
49
44
 
50
- queue = @client.queues.get(:name=>@client.queue_name)
45
+ queue = @client.queues.get(:name => @client.queue_name)
51
46
  assert queue.size == 0
52
47
 
53
48
  res = @client.messages.post("hello world 2!")
@@ -93,12 +88,13 @@ class IronMQTests < TestBase
93
88
  sleep 45
94
89
 
95
90
  msg2 = @client.messages.get()
91
+ assert msg2
96
92
  assert msg.id == msg2.id
97
93
 
98
94
  msg2.delete
99
95
 
100
96
  # now try explicit timeout
101
- res = @client.messages.post("hello world timeout2!", :timeout=>10)
97
+ res = @client.messages.post("hello world timeout2!", :timeout => 10)
102
98
  p res
103
99
  msg = @client.messages.get()
104
100
  p msg
@@ -107,6 +103,7 @@ class IronMQTests < TestBase
107
103
  p msg4
108
104
  assert msg4.nil?
109
105
  puts 'sleeping 15 seconds...'
106
+ sleep 15
110
107
  msg2 = @client.messages.get()
111
108
  assert msg2
112
109
  assert msg.id == msg2.id
@@ -114,6 +111,13 @@ class IronMQTests < TestBase
114
111
  end
115
112
 
116
113
  def test_queues
114
+ puts 'test_queues'
115
+
116
+ assert_raise IronCore::IronResponseError do
117
+ # should raise a 404
118
+ q = @client.queues.get(:name => "some_queue_that_does_not_exist")
119
+ end
120
+
117
121
  res = @client.queues.list()
118
122
  puts "res.size: " + res.size.to_s
119
123
  res.each do |q|
@@ -123,7 +127,7 @@ class IronMQTests < TestBase
123
127
  end
124
128
  assert res.size > 0
125
129
 
126
- res = @client.queues.list(:page=>5)
130
+ res = @client.queues.list(:page => 5)
127
131
  puts "res.size 2: " + res.size.to_s
128
132
  res.each do |q|
129
133
  p q.name
@@ -156,7 +160,7 @@ class IronMQTests < TestBase
156
160
 
157
161
  x = []
158
162
  10.times do |i|
159
- x << {:body=>"body #{i}"}
163
+ x << {:body => "body #{i}"}
160
164
  end
161
165
  resp = @client.messages.post(x)
162
166
  assert resp["ids"]
@@ -168,7 +172,7 @@ class IronMQTests < TestBase
168
172
  assert msg['id']
169
173
  msg.delete
170
174
 
171
- msgs = @client.messages.get(:n=>10)
175
+ msgs = @client.messages.get(:n => 10)
172
176
  assert msgs.is_a?(Array)
173
177
  assert msgs.size == 9, "size should be 9, but it's #{msgs.size}"
174
178
  assert msgs[0]["id"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_mq
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-02 00:00:00.000000000Z
12
+ date: 2012-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: rest-client
16
- requirement: &14061040 !ruby/object:Gem::Requirement
15
+ name: iron_core
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,21 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *14061040
25
- - !ruby/object:Gem::Dependency
26
- name: rest
27
- requirement: &14060480 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
28
25
  none: false
29
26
  requirements:
30
27
  - - ! '>='
31
28
  - !ruby/object:Gem::Version
32
29
  version: '0'
33
- type: :runtime
34
- prerelease: false
35
- version_requirements: *14060480
36
30
  - !ruby/object:Gem::Dependency
37
- name: rest-client
38
- requirement: &14059900 !ruby/object:Gem::Requirement
31
+ name: iron_core
32
+ requirement: !ruby/object:Gem::Requirement
39
33
  none: false
40
34
  requirements:
41
35
  - - ! '>='
@@ -43,18 +37,12 @@ dependencies:
43
37
  version: '0'
44
38
  type: :runtime
45
39
  prerelease: false
46
- version_requirements: *14059900
47
- - !ruby/object:Gem::Dependency
48
- name: rest
49
- requirement: &14059100 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
50
41
  none: false
51
42
  requirements:
52
43
  - - ! '>='
53
44
  - !ruby/object:Gem::Version
54
45
  version: '0'
55
- type: :runtime
56
- prerelease: false
57
- version_requirements: *14059100
58
46
  description: Ruby client for IronMQ
59
47
  email: travis@iron.io
60
48
  executables: []
@@ -99,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
87
  version: '0'
100
88
  requirements: []
101
89
  rubyforge_project:
102
- rubygems_version: 1.8.15
90
+ rubygems_version: 1.8.24
103
91
  signing_key:
104
92
  specification_version: 3
105
93
  summary: Ruby client for IronMQ