carrot 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  ---
2
- :major: 0
3
- :minor: 7
2
+ :build:
3
+ :minor: 8
4
4
  :patch: 0
5
+ :major: 0
data/carrot.gemspec CHANGED
@@ -1,15 +1,15 @@
1
1
  # Generated by jeweler
2
- # DO NOT EDIT THIS FILE
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{carrot}
8
- s.version = "0.7.0"
8
+ s.version = "0.8.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Amos Elliston"]
12
- s.date = %q{2009-10-19}
12
+ s.date = %q{2010-06-10}
13
13
  s.description = %q{A synchronous version of the ruby amqp client}
14
14
  s.email = %q{amos@geni.com}
15
15
  s.extra_rdoc_files = [
@@ -60,3 +60,4 @@ Gem::Specification.new do |s|
60
60
  else
61
61
  end
62
62
  end
63
+
data/lib/amqp/queue.rb CHANGED
@@ -1,10 +1,9 @@
1
1
  module Carrot::AMQP
2
2
  class Queue
3
- attr_reader :name, :server, :carrot
3
+ attr_reader :name, :carrot
4
4
  attr_accessor :delivery_tag
5
5
 
6
6
  def initialize(carrot, name, opts = {})
7
- @server = carrot.server
8
7
  @opts = opts
9
8
  @name = name
10
9
  @carrot = carrot
@@ -19,7 +18,7 @@ module Carrot::AMQP
19
18
  Protocol::Basic::Get.new({ :queue => name, :consumer_tag => name, :no_ack => !opts.delete(:ack), :nowait => true }.merge(opts))
20
19
  )
21
20
  method = server.next_method
22
- return unless method.is_a?(Protocol::Basic::GetOk)
21
+ return unless method.kind_of?(Protocol::Basic::GetOk)
23
22
 
24
23
  self.delivery_tag = method.delivery_tag
25
24
 
@@ -56,6 +55,8 @@ module Carrot::AMQP
56
55
  Protocol::Queue::Declare.new({ :queue => name, :passive => true }.merge(opts))
57
56
  )
58
57
  method = server.next_method
58
+ return [nil, nil] if method.kind_of?(Protocol::Connection::Close)
59
+
59
60
  [method.message_count, method.consumer_count]
60
61
  end
61
62
 
@@ -85,6 +86,16 @@ module Carrot::AMQP
85
86
  carrot.queues.delete(name)
86
87
  end
87
88
 
89
+ def purge(opts = {})
90
+ server.send_frame(
91
+ Protocol::Queue::Purge.new({ :queue => name, :nowait => true }.merge(opts))
92
+ )
93
+ end
94
+
95
+ def server
96
+ carrot.server
97
+ end
98
+
88
99
  private
89
100
  def exchange
90
101
  @exchange ||= Exchange.new(carrot, :direct, '', :key => name)
data/lib/amqp/server.rb CHANGED
@@ -66,6 +66,8 @@ module Carrot::AMQP
66
66
  )
67
67
  puts "Error closing connection" unless next_method.is_a?(Protocol::Connection::CloseOk)
68
68
 
69
+ rescue ServerDown => e
70
+ ensure
69
71
  close_socket
70
72
  end
71
73
 
@@ -86,7 +88,7 @@ module Carrot::AMQP
86
88
  def send_command(cmd, *args)
87
89
  begin
88
90
  socket.__send__(cmd, *args)
89
- rescue Errno::EPIPE, IOError => e
91
+ rescue Errno::EPIPE, IOError, Errno::ECONNRESET, Errno::EINVAL => e
90
92
  raise ServerDown, e.message
91
93
  end
92
94
  end
data/lib/carrot.rb CHANGED
@@ -27,19 +27,23 @@ class Carrot
27
27
  end
28
28
  class Error < StandardError; end
29
29
 
30
- attr_accessor :server
31
-
32
30
  def initialize(opts = {})
33
- @server = AMQP::Server.new(opts)
31
+ @opts = opts
34
32
  end
35
33
 
36
34
  def queue(name, opts = {})
37
35
  queues[name] ||= AMQP::Queue.new(self, name, opts)
38
36
  end
39
37
 
38
+ def server
39
+ @server ||= AMQP::Server.new(@opts)
40
+ end
41
+
40
42
  def stop
41
43
  server.close
44
+ @server = nil
42
45
  end
46
+ alias :reset :stop
43
47
 
44
48
  def queues
45
49
  @queues ||= {}
data/test/carrot_test.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
3
  class CarrotTest < Test::Unit::TestCase
4
+ TEST_QUEUE = '_carrot_test'
4
5
 
5
6
  test "simple server connection" do
6
7
  c = Carrot.new
@@ -8,8 +9,17 @@ class CarrotTest < Test::Unit::TestCase
8
9
 
9
10
  test "large messages" do
10
11
  msg = 'a' * 1024 * 1024
11
- q = Carrot.queue('_carrot_test')
12
+ q = Carrot.queue(TEST_QUEUE)
12
13
  q.publish(msg)
13
14
  assert_equal msg, q.pop
14
15
  end
16
+
17
+ test "reset" do
18
+ c = Carrot.new
19
+ q = c.queue(TEST_QUEUE)
20
+ count = q.message_count
21
+ q.publish('test')
22
+ c.reset
23
+ assert_equal count + 1, q.message_count
24
+ end
15
25
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrot
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amos Elliston
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-19 00:00:00 -07:00
12
+ date: 2010-06-10 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15